Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'spec/lib/gitlab/config/entry/validators_spec.rb')
-rw-r--r--spec/lib/gitlab/config/entry/validators_spec.rb33
1 files changed, 33 insertions, 0 deletions
diff --git a/spec/lib/gitlab/config/entry/validators_spec.rb b/spec/lib/gitlab/config/entry/validators_spec.rb
index abf3dbacb3d..6fa9f9d0767 100644
--- a/spec/lib/gitlab/config/entry/validators_spec.rb
+++ b/spec/lib/gitlab/config/entry/validators_spec.rb
@@ -102,4 +102,37 @@ RSpec.describe Gitlab::Config::Entry::Validators, feature_category: :pipeline_co
end
end
end
+
+ describe described_class::OnlyOneOfKeysValidator do
+ using RSpec::Parameterized::TableSyntax
+
+ where(:config, :valid_result) do
+ { foo: '1' } | true
+ { foo: '1', bar: '2', baz: '3' } | false
+ { bar: '2' } | true
+ { foo: '1' } | true
+ {} | false
+ { baz: '3' } | false
+ end
+
+ with_them do
+ before do
+ klass.instance_eval do
+ validates :config, only_one_of_keys: %i[foo bar]
+ end
+
+ allow(instance).to receive(:config).and_return(config)
+ end
+
+ it 'validates the instance' do
+ expect(instance.valid?).to be(valid_result)
+
+ unless valid_result
+ expect(instance.errors.messages_for(:config)).to(
+ include "must use exactly one of these keys: foo, bar"
+ )
+ end
+ end
+ end
+ end
end