Commit c91298d5 authored by Grzegorz Bizon's avatar Grzegorz Bizon

Use generic type validator in new ci configuration

parent 9510d31b
...@@ -19,7 +19,7 @@ module Gitlab ...@@ -19,7 +19,7 @@ module Gitlab
included do included do
validations do validations do
validates :config, hash: true validates :config, type: Hash
end end
end end
......
...@@ -13,10 +13,13 @@ module Gitlab ...@@ -13,10 +13,13 @@ module Gitlab
end end
end end
class HashValidator < ActiveModel::EachValidator class TypeValidator < ActiveModel::EachValidator
def validate_each(record, attribute, value) def validate_each(record, attribute, value)
unless value.is_a?(Hash) type = options[:with]
record.errors.add(attribute, 'should be a configuration entry hash') raise unless type.is_a?(Class)
unless value.is_a?(type)
record.errors.add(attribute, "should be a #{type.name}")
end end
end end
end end
......
...@@ -106,5 +106,11 @@ describe Gitlab::Ci::Config::Node::Global do ...@@ -106,5 +106,11 @@ describe Gitlab::Ci::Config::Node::Global do
expect(global).not_to be_valid expect(global).not_to be_valid
end end
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
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