Commit 8baee987 authored by Grzegorz Bizon's avatar Grzegorz Bizon

Extract internal attributes validator for CI entry

parent 3da57c80
......@@ -10,13 +10,7 @@ module Gitlab
validations do
validates :config, key: true
validate do |entry|
unless entry.global
raise Entry::InvalidError,
'This entry needs reference to global configuration'
end
end
validates :global, required_attribute: true
end
def self.default
......
......@@ -33,6 +33,15 @@ module Gitlab
end
end
class RequiredAttributeValidator < ActiveModel::EachValidator
def validate_each(record, attribute, value)
if value.nil?
raise Entry::InvalidError,
"Entry needs #{attribute} attribute set internally."
end
end
end
class KeyValidator < ActiveModel::EachValidator
include LegacyValidationHelpers
......
......@@ -27,8 +27,10 @@ describe Gitlab::Ci::Config::Node::Stage do
let(:entry) { described_class.new(config) }
it 'raises error' do
expect { entry }
.to raise_error Gitlab::Ci::Config::Node::Entry::InvalidError
expect { entry }.to raise_error(
Gitlab::Ci::Config::Node::Entry::InvalidError,
/Entry needs global attribute set internally./
)
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