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