Commit 11c0d022 authored by Grzegorz Bizon's avatar Grzegorz Bizon

Simplify ci config node factory

parent 7c8f3b0c
......@@ -31,8 +31,8 @@ module Gitlab
private
def create_node(key, factory)
factory.with_value(@value[key])
factory.null_node unless @value.has_key?(key)
factory.with(value: @value[key])
factory.nullify! unless @value.has_key?(key)
factory.create!
end
......@@ -45,7 +45,7 @@ module Gitlab
def allow_node(symbol, entry_class, metadata)
factory = Node::Factory.new(entry_class)
.with_description(metadata[:description])
.with(description: metadata[:description])
define_method(symbol) do
raise Entry::InvalidError unless valid?
......
......@@ -15,17 +15,12 @@ module Gitlab
@attributes = {}
end
def with_value(value)
@attributes[:value] = value
def with(attributes)
@attributes.merge!(attributes)
self
end
def with_description(description)
@attributes[:description] = description
self
end
def null_node
def nullify!
@entry_class = Node::Null
self
end
......
......@@ -8,7 +8,7 @@ describe Gitlab::Ci::Config::Node::Factory do
context 'when value setting value' do
it 'creates entry with valid value' do
entry = factory
.with_value(['ls', 'pwd'])
.with(value: ['ls', 'pwd'])
.create!
expect(entry.value).to eq "ls\npwd"
......@@ -17,8 +17,8 @@ describe Gitlab::Ci::Config::Node::Factory do
context 'when setting description' do
it 'creates entry with description' do
entry = factory
.with_value(['ls', 'pwd'])
.with_description('test description')
.with(value: ['ls', 'pwd'])
.with(description: 'test description')
.create!
expect(entry.value).to eq "ls\npwd"
......@@ -38,8 +38,8 @@ describe Gitlab::Ci::Config::Node::Factory do
context 'when creating a null entry' do
it 'creates a null entry' do
entry = factory
.with_value(nil)
.null_node
.with(value: nil)
.nullify!
.create!
expect(entry).to be_an_instance_of Gitlab::Ci::Config::Node::Null
......
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