BigW Consortium Gitlab

Commit d9d5042f by Grzegorz Bizon

Extract method that composes new Ci config entry

parent 33cd090b
...@@ -20,14 +20,18 @@ module Gitlab ...@@ -20,14 +20,18 @@ module Gitlab
def process! def process!
return if leaf? || invalid? return if leaf? || invalid?
keys.each do |key, entry| compose!
add_node(key, entry)
end
nodes.each(&:process!) nodes.each(&:process!)
nodes.each(&:validate!) nodes.each(&:validate!)
end end
def compose!
keys.each do |key, entry|
add_node(key, entry)
end
end
def nodes def nodes
@nodes.values @nodes.values
end end
......
...@@ -3,8 +3,6 @@ require 'spec_helper' ...@@ -3,8 +3,6 @@ require 'spec_helper'
describe Gitlab::Ci::Config::Node::Global do describe Gitlab::Ci::Config::Node::Global do
let(:global) { described_class.new(hash) } let(:global) { described_class.new(hash) }
before { global.process! }
describe '#keys' do describe '#keys' do
it 'can contain global config keys' do it 'can contain global config keys' do
expect(global.keys).to include :before_script expect(global.keys).to include :before_script
...@@ -20,7 +18,18 @@ describe Gitlab::Ci::Config::Node::Global do ...@@ -20,7 +18,18 @@ describe Gitlab::Ci::Config::Node::Global do
{ before_script: ['ls', 'pwd'] } { before_script: ['ls', 'pwd'] }
end end
describe '#compose!' do
before { global.compose! }
it 'instantiates entry nodes' do
expect(global.nodes.first)
.to be_an_instance_of Gitlab::Ci::Config::Node::Script
end
end
describe '#process!' do describe '#process!' do
before { global.process! }
it 'creates nodes hash' do it 'creates nodes hash' do
expect(global.nodes).to be_an Array expect(global.nodes).to be_an Array
end end
...@@ -48,13 +57,25 @@ describe Gitlab::Ci::Config::Node::Global do ...@@ -48,13 +57,25 @@ describe Gitlab::Ci::Config::Node::Global do
end end
describe '#before_script' do describe '#before_script' do
it 'returns correct script' do context 'when processed' do
expect(global.before_script).to eq "ls\npwd" before { global.process! }
it 'returns correct script' do
expect(global.before_script).to eq "ls\npwd"
end
end
context 'when not processed' do
it 'returns nil' do
expect(global.before_script).to be nil
end
end end
end end
end end
context 'when hash is not valid' do context 'when hash is not valid' do
before { global.process! }
let(:hash) do let(:hash) do
{ before_script: 'ls' } { before_script: 'ls' }
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