Commit 3da57c80 authored by Grzegorz Bizon's avatar Grzegorz Bizon

Require reference to CI config for some entries

parent f067202e
...@@ -10,6 +10,13 @@ module Gitlab ...@@ -10,6 +10,13 @@ module Gitlab
validations do validations do
validates :config, key: true validates :config, key: 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
......
require 'spec_helper' require 'spec_helper'
describe Gitlab::Ci::Config::Node::Stage do 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 describe 'validations' do
context 'when entry config value is correct' do context 'when entry config value is correct' do
let(:config) { :stage1 } let(:config) { :build }
describe '#value' do describe '#value' do
it 'returns a stage key' do it 'returns a stage key' do
...@@ -18,20 +19,32 @@ describe Gitlab::Ci::Config::Node::Stage do ...@@ -18,20 +19,32 @@ describe Gitlab::Ci::Config::Node::Stage do
expect(entry).to be_valid expect(entry).to be_valid
end end
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 context 'when value has a wrong type' do
let(:config) { { test: true } } let(:config) { { test: true } }
describe '#errors' do it 'reports errors about wrong type' do
it 'reports errors' do
expect(entry.errors) expect(entry.errors)
.to include 'stage config should be a string or symbol' .to include 'stage config should be a string or symbol'
end end
end end
describe '#valid?' do context 'when stage is not present in global configuration' do
it 'is not valid' do pending 'reports error about missing stage' do
expect(entry).not_to be_valid expect(entry.errors)
.to include 'stage config should be one of test, stage'
end end
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