2019-07-07 11:18:12 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2022-10-11 01:57:18 +05:30
|
|
|
require 'fast_spec_helper'
|
2019-07-07 11:18:12 +05:30
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
RSpec.describe Gitlab::PushOptions do
|
2019-07-07 11:18:12 +05:30
|
|
|
describe 'namespace and key validation' do
|
|
|
|
it 'ignores unrecognised namespaces' do
|
|
|
|
options = described_class.new(['invalid.key=value'])
|
|
|
|
|
|
|
|
expect(options.get(:invalid)).to eq(nil)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'ignores unrecognised keys' do
|
|
|
|
options = described_class.new(['merge_request.key=value'])
|
|
|
|
|
|
|
|
expect(options.get(:merge_request)).to eq(nil)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'ignores blank keys' do
|
|
|
|
options = described_class.new(['merge_request'])
|
|
|
|
|
|
|
|
expect(options.get(:merge_request)).to eq(nil)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'parses recognised namespace and key pairs' do
|
|
|
|
options = described_class.new(['merge_request.target=value'])
|
|
|
|
|
|
|
|
expect(options.get(:merge_request)).to include({
|
|
|
|
target: 'value'
|
|
|
|
})
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#get' do
|
|
|
|
it 'can emulate Hash#dig' do
|
|
|
|
options = described_class.new(['merge_request.target=value'])
|
|
|
|
|
|
|
|
expect(options.get(:merge_request, :target)).to eq('value')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#as_json' do
|
|
|
|
it 'returns all options' do
|
|
|
|
options = described_class.new(['merge_request.target=value'])
|
|
|
|
|
|
|
|
expect(options.as_json).to include(
|
|
|
|
merge_request: {
|
|
|
|
target: 'value'
|
|
|
|
}
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'can parse multiple push options' do
|
|
|
|
options = described_class.new([
|
|
|
|
'merge_request.create',
|
|
|
|
'merge_request.target=value'
|
|
|
|
])
|
|
|
|
|
|
|
|
expect(options.get(:merge_request)).to include({
|
|
|
|
create: true,
|
|
|
|
target: 'value'
|
|
|
|
})
|
|
|
|
expect(options.get(:merge_request, :create)).to eq(true)
|
|
|
|
expect(options.get(:merge_request, :target)).to eq('value')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'stores options internally as a HashWithIndifferentAccess' do
|
|
|
|
options = described_class.new([
|
|
|
|
'merge_request.create'
|
|
|
|
])
|
|
|
|
|
|
|
|
expect(options.get('merge_request', 'create')).to eq(true)
|
|
|
|
expect(options.get(:merge_request, :create)).to eq(true)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'selects the last option when options contain duplicate namespace and key pairs' do
|
|
|
|
options = described_class.new([
|
|
|
|
'merge_request.target=value1',
|
|
|
|
'merge_request.target=value2'
|
|
|
|
])
|
|
|
|
|
|
|
|
expect(options.get(:merge_request, :target)).to eq('value2')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'defaults values to true' do
|
|
|
|
options = described_class.new(['merge_request.create'])
|
|
|
|
|
|
|
|
expect(options.get(:merge_request, :create)).to eq(true)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'expands aliases' do
|
|
|
|
options = described_class.new(['mr.target=value'])
|
|
|
|
|
|
|
|
expect(options.get(:merge_request, :target)).to eq('value')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'forgives broken push options' do
|
|
|
|
options = described_class.new(['merge_request . target = value'])
|
|
|
|
|
|
|
|
expect(options.get(:merge_request, :target)).to eq('value')
|
|
|
|
end
|
|
|
|
end
|