diff options
author | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2016-06-27 14:12:47 +0200 |
---|---|---|
committer | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2016-06-27 14:16:57 +0200 |
commit | c019585cb83b1852451184663085e6f0e0d12024 (patch) | |
tree | 969d3dff5f728f78b4827b2c037435ed12b16f2e | |
parent | 56e88b8c28282976be258ba53a9f82662cc74703 (diff) | |
download | gitlab-ce-c019585cb83b1852451184663085e6f0e0d12024.tar.gz |
Validate interface only with CI node validator
-rw-r--r-- | lib/gitlab/ci/config/node/cache.rb | 29 | ||||
-rw-r--r-- | lib/gitlab/ci/config/node/validator.rb | 3 | ||||
-rw-r--r-- | spec/lib/gitlab/ci/config/node/validator_spec.rb | 32 |
3 files changed, 24 insertions, 40 deletions
diff --git a/lib/gitlab/ci/config/node/cache.rb b/lib/gitlab/ci/config/node/cache.rb index c6508e59c4b..251d7aa9097 100644 --- a/lib/gitlab/ci/config/node/cache.rb +++ b/lib/gitlab/ci/config/node/cache.rb @@ -8,30 +8,33 @@ module Gitlab class Cache < Entry include Configurable + node :key, Key, + description: 'Cache key used to define a cache affinity.' + + node :untracked, Boolean, + description: 'Cache all untracked files.' + + node :paths, Paths, + description: 'Specify which paths should be cached across builds.' + validations do - validate :allowed_keys + validate :keys def unknown_keys - return [] unless @node.config.is_a?(Hash) - - @node.config.keys - @node.class.nodes.keys + return [] unless config.is_a?(Hash) + config.keys - allowed_keys end - def allowed_keys + def keys if unknown_keys.any? errors.add(:config, "contains unknown keys #{unknown_keys}") end end end - node :key, Node::Key, - description: 'Cache key used to define a cache affinity.' - - node :untracked, Boolean, - description: 'Cache all untracked files.' - - node :paths, Paths, - description: 'Specify which paths should be cached across builds.' + def allowed_keys + self.class.nodes.keys + end end end end diff --git a/lib/gitlab/ci/config/node/validator.rb b/lib/gitlab/ci/config/node/validator.rb index 5f62d68710d..18e795d2c42 100644 --- a/lib/gitlab/ci/config/node/validator.rb +++ b/lib/gitlab/ci/config/node/validator.rb @@ -8,12 +8,11 @@ module Gitlab def initialize(node) super(node) - @node = node end def messages errors.full_messages.map do |error| - "#{@node.key} #{error}".humanize + "#{key} #{error}".humanize end end diff --git a/spec/lib/gitlab/ci/config/node/validator_spec.rb b/spec/lib/gitlab/ci/config/node/validator_spec.rb index aa55ce90b37..c293faa33ae 100644 --- a/spec/lib/gitlab/ci/config/node/validator_spec.rb +++ b/spec/lib/gitlab/ci/config/node/validator_spec.rb @@ -5,7 +5,13 @@ describe Gitlab::Ci::Config::Node::Validator do let(:validator_instance) { validator.new(node) } let(:node) { spy('node') } - shared_examples 'delegated validator' do + describe 'delegated validator' do + before do + validator.class_eval do + validates :test_attribute, presence: true + end + end + context 'when node is valid' do before do allow(node).to receive(:test_attribute).and_return('valid value') @@ -40,28 +46,4 @@ describe Gitlab::Ci::Config::Node::Validator do end end end - - describe 'attributes validations' do - before do - validator.class_eval do - validates :test_attribute, presence: true - end - end - - it_behaves_like 'delegated validator' - end - - describe 'interface validations' do - before do - validator.class_eval do - validate do - unless @node.test_attribute == 'valid value' - errors.add(:test_attribute, 'invalid value') - end - end - end - end - - it_behaves_like 'delegated validator' - end end |