Commit 0ea8c236 authored by Grzegorz Bizon's avatar Grzegorz Bizon

Add more specs for only/except policy config entry

parent 67e90a12
...@@ -65,7 +65,7 @@ module Gitlab ...@@ -65,7 +65,7 @@ module Gitlab
end end
def value def value
self.class.default(key: @key).yield_self do |default| self.class.default(key: @subject.key).yield_self do |default|
default.to_h.deep_merge(@subject.value.to_h) default.to_h.deep_merge(@subject.value.to_h)
end end
end end
......
...@@ -168,9 +168,57 @@ describe Gitlab::Ci::Config::Entry::Policy do ...@@ -168,9 +168,57 @@ describe Gitlab::Ci::Config::Entry::Policy do
end end
end end
describe '#value' do
context 'when it is `only` policy' do
before do
entry.key = :only
end
context 'when user overrides default values' do
let(:config) { { refs: %w[feature], variables: %w[$VARIABLE] } }
it 'does not include default values' do
expect(entry.value).to eq config
end
end
context 'when user does not override default values' do
let(:config) { { variables: %w[$VARIABLE] } }
it 'includes default values' do
expect(entry.value).to eq(refs: %w[branches tags],
variables: %w[$VARIABLE])
end
end
end
context 'when it is `except` policy' do
before do
entry.key = :except
end
context 'when user does not override default values' do
let(:config) { { variables: %w[$VARIABLE] } }
it 'does not include default values' do
expect(entry.value).to eq config
end
end
end
end
describe '.default' do describe '.default' do
it 'does not have a default value' do context 'when `only` policy is about to be fabricated' do
expect(described_class.default).to be_nil it 'has a default value' do
expect(described_class.default(key: :only))
.to eq(refs: %w[branches tags])
end
end
context 'when `except` policy is about to be fabricated' do
it 'does not have a default value' do
expect(described_class.default(key: :except)).to be_nil
end
end end
end end
end end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment