Skip to content
Snippets Groups Projects
Commit 8baee987 authored by Grzegorz Bizon's avatar Grzegorz Bizon
Browse files

Extract internal attributes validator for CI entry

parent 3da57c80
No related branches found
No related tags found
1 merge request!5087Move CI job config entries from legacy to new config
Pipeline #
Loading
Loading
@@ -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
Loading
Loading
Loading
Loading
@@ -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
 
Loading
Loading
Loading
Loading
@@ -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
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment