2019-03-28 21:07:03 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2022-08-18 05:11:27 -04:00
|
|
|
require 'fast_spec_helper'
|
2019-03-28 21:07:03 -04:00
|
|
|
|
2020-06-24 14:09:03 -04:00
|
|
|
RSpec.describe Gitlab::PushOptions do
|
2019-03-28 21:07:03 -04:00
|
|
|
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
|
|
|
|
|
2019-04-05 00:19:30 -04:00
|
|
|
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
|
|
|
|
|
2019-03-28 21:07:03 -04:00
|
|
|
it 'can parse multiple push options' do
|
2022-09-29 11:09:34 -04:00
|
|
|
options = described_class.new(
|
|
|
|
[
|
|
|
|
'merge_request.create',
|
|
|
|
'merge_request.target=value'
|
|
|
|
])
|
2019-03-28 21:07:03 -04:00
|
|
|
|
|
|
|
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
|
2022-09-29 11:09:34 -04:00
|
|
|
options = described_class.new(
|
|
|
|
[
|
|
|
|
'merge_request.create'
|
|
|
|
])
|
2019-03-28 21:07:03 -04:00
|
|
|
|
|
|
|
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
|
2022-09-29 11:09:34 -04:00
|
|
|
options = described_class.new(
|
|
|
|
[
|
|
|
|
'merge_request.target=value1',
|
|
|
|
'merge_request.target=value2'
|
|
|
|
])
|
2019-03-28 21:07:03 -04:00
|
|
|
|
|
|
|
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
|