From 3da57c800bf0c4fe3c45dbea3cff4179f6aa124f Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon <grzesiek.bizon@gmail.com> Date: Thu, 7 Jul 2016 15:15:44 +0200 Subject: [PATCH] Require reference to CI config for some entries --- lib/gitlab/ci/config/node/stage.rb | 7 +++++ spec/lib/gitlab/ci/config/node/stage_spec.rb | 31 ++++++++++++++------ 2 files changed, 29 insertions(+), 9 deletions(-) diff --git a/lib/gitlab/ci/config/node/stage.rb b/lib/gitlab/ci/config/node/stage.rb index 53ceafaa3f4..c7e12f291d7 100644 --- a/lib/gitlab/ci/config/node/stage.rb +++ b/lib/gitlab/ci/config/node/stage.rb @@ -10,6 +10,13 @@ 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 end def self.default diff --git a/spec/lib/gitlab/ci/config/node/stage_spec.rb b/spec/lib/gitlab/ci/config/node/stage_spec.rb index 653d613ba6e..92150ea5337 100644 --- a/spec/lib/gitlab/ci/config/node/stage_spec.rb +++ b/spec/lib/gitlab/ci/config/node/stage_spec.rb @@ -1,11 +1,12 @@ require 'spec_helper' describe Gitlab::Ci::Config::Node::Stage do - let(:entry) { described_class.new(config) } + let(:entry) { described_class.new(config, global: global) } + let(:global) { spy('Global') } describe 'validations' do context 'when entry config value is correct' do - let(:config) { :stage1 } + let(:config) { :build } describe '#value' do it 'returns a stage key' do @@ -18,20 +19,32 @@ describe Gitlab::Ci::Config::Node::Stage do expect(entry).to be_valid end end + end + + context 'when entry config is incorrect' do + describe '#errors' do + context 'when reference to global node is not set' do + let(:entry) { described_class.new(config) } + + it 'raises error' do + expect { entry } + .to raise_error Gitlab::Ci::Config::Node::Entry::InvalidError + end + end - context 'when entry config is incorrect' do - let(:config) { { test: true } } + context 'when value has a wrong type' do + let(:config) { { test: true } } - describe '#errors' do - it 'reports errors' do + it 'reports errors about wrong type' do expect(entry.errors) .to include 'stage config should be a string or symbol' end end - describe '#valid?' do - it 'is not valid' do - expect(entry).not_to be_valid + context 'when stage is not present in global configuration' do + pending 'reports error about missing stage' do + expect(entry.errors) + .to include 'stage config should be one of test, stage' end end end -- GitLab