Commit 7c8f3b0c authored by Grzegorz Bizon's avatar Grzegorz Bizon

Duplicate CI config node factory on class level

parent cc373a35
......@@ -37,7 +37,9 @@ module Gitlab
end
class_methods do
attr_reader :allowed_nodes
def allowed_nodes
Hash[@allowed_nodes.map { |key, factory| [key, factory.dup] } ]
end
private
......
......@@ -27,8 +27,8 @@ module Gitlab
end
def compose!
allowed_nodes.each do |key, factory|
@nodes[key] = create_node(key, factory.dup)
allowed_nodes.each do |key, essence|
@nodes[key] = create_node(key, essence)
end
end
......@@ -62,7 +62,7 @@ module Gitlab
private
def create_node(key, factory)
def create_node(key, essence)
raise NotImplementedError
end
end
......
require 'spec_helper'
describe Gitlab::Ci::Config::Node::Configurable do
let(:node) { Class.new }
before do
node.include(described_class)
end
describe 'allowed nodes' do
before do
node.class_eval do
allow_node :object, Object, description: 'test object'
end
end
describe '#allowed_nodes' do
it 'has valid allowed nodes' do
expect(node.allowed_nodes).to include :object
end
it 'creates a node factory' do
expect(node.allowed_nodes[:object])
.to be_an_instance_of Gitlab::Ci::Config::Node::Factory
end
it 'returns a duplicated factory object' do
first_factory = node.allowed_nodes[:object]
second_factory = node.allowed_nodes[:object]
expect(first_factory).not_to be_equal(second_factory)
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