diff options
-rw-r--r-- | lib/gitlab/ci/config/node/configurable.rb | 2 | ||||
-rw-r--r-- | lib/gitlab/ci/config/node/validators.rb | 9 | ||||
-rw-r--r-- | spec/lib/gitlab/ci/config/node/global_spec.rb | 6 |
3 files changed, 13 insertions, 4 deletions
diff --git a/lib/gitlab/ci/config/node/configurable.rb b/lib/gitlab/ci/config/node/configurable.rb index 374ff71d0f5..e691ab0c5cf 100644 --- a/lib/gitlab/ci/config/node/configurable.rb +++ b/lib/gitlab/ci/config/node/configurable.rb @@ -19,7 +19,7 @@ module Gitlab included do validations do - validates :config, hash: true + validates :config, type: Hash end end diff --git a/lib/gitlab/ci/config/node/validators.rb b/lib/gitlab/ci/config/node/validators.rb index dc9cdb9a220..a76f041c953 100644 --- a/lib/gitlab/ci/config/node/validators.rb +++ b/lib/gitlab/ci/config/node/validators.rb @@ -13,10 +13,13 @@ module Gitlab end end - class HashValidator < ActiveModel::EachValidator + class TypeValidator < ActiveModel::EachValidator def validate_each(record, attribute, value) - unless value.is_a?(Hash) - record.errors.add(attribute, 'should be a configuration entry hash') + type = options[:with] + raise unless type.is_a?(Class) + + unless value.is_a?(type) + record.errors.add(attribute, "should be a #{type.name}") end end end diff --git a/spec/lib/gitlab/ci/config/node/global_spec.rb b/spec/lib/gitlab/ci/config/node/global_spec.rb index fddd53a2b57..fc9257d89dd 100644 --- a/spec/lib/gitlab/ci/config/node/global_spec.rb +++ b/spec/lib/gitlab/ci/config/node/global_spec.rb @@ -106,5 +106,11 @@ describe Gitlab::Ci::Config::Node::Global do expect(global).not_to be_valid end end + + describe '#errors' do + it 'returns error about invalid type' do + expect(global.errors.first).to match /should be a hash/ + end + end end end |