Extract internal attributes validator for CI entry
This commit is contained in:
parent
3da57c800b
commit
8baee987be
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in New Issue