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
included do
validations do
validates :config, hash: true
validates :config, type: Hash
end
end
......
......@@ -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
......
......@@ -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
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