From 7c511c2f55f3e181983253d8b3ae74cd84e6844c Mon Sep 17 00:00:00 2001
From: Grzegorz Bizon <grzesiek.bizon@gmail.com>
Date: Wed, 29 Jun 2016 09:05:14 +0200
Subject: [PATCH] Make it possible to set parent in CI config node

---
 lib/gitlab/ci/config/node/entry.rb             |  4 ++--
 lib/gitlab/ci/config/node/factory.rb           |  3 ++-
 spec/lib/gitlab/ci/config/node/factory_spec.rb | 16 ++++++++++++++--
 3 files changed, 18 insertions(+), 5 deletions(-)

diff --git a/lib/gitlab/ci/config/node/entry.rb b/lib/gitlab/ci/config/node/entry.rb
index 08d8020f8e7..f22dac44836 100644
--- a/lib/gitlab/ci/config/node/entry.rb
+++ b/lib/gitlab/ci/config/node/entry.rb
@@ -8,9 +8,9 @@ module Gitlab
         class Entry
           class InvalidError < StandardError; end
 
-          attr_reader :config
-          attr_accessor :description
           attr_writer :key
+          attr_reader :config
+          attr_accessor :parent, :description
 
           def initialize(config)
             @config = config
diff --git a/lib/gitlab/ci/config/node/factory.rb b/lib/gitlab/ci/config/node/factory.rb
index 39b5784af25..85e28f345fe 100644
--- a/lib/gitlab/ci/config/node/factory.rb
+++ b/lib/gitlab/ci/config/node/factory.rb
@@ -32,8 +32,9 @@ module Gitlab
             end
 
             node.new(value).tap do |entry|
-              entry.description = @attributes[:description]
               entry.key = @attributes[:key]
+              entry.parent = @attributes[:parent]
+              entry.description = @attributes[:description]
             end
           end
         end
diff --git a/spec/lib/gitlab/ci/config/node/factory_spec.rb b/spec/lib/gitlab/ci/config/node/factory_spec.rb
index dd5f6e62b3e..91ddef7bfbf 100644
--- a/spec/lib/gitlab/ci/config/node/factory_spec.rb
+++ b/spec/lib/gitlab/ci/config/node/factory_spec.rb
@@ -5,7 +5,7 @@ describe Gitlab::Ci::Config::Node::Factory do
     let(:factory) { described_class.new(entry_class) }
     let(:entry_class) { Gitlab::Ci::Config::Node::Script }
 
-    context 'when value setting value' do
+    context 'when setting up a value' do
       it 'creates entry with valid value' do
         entry = factory
           .with(value: ['ls', 'pwd'])
@@ -35,9 +35,21 @@ describe Gitlab::Ci::Config::Node::Factory do
           expect(entry.key).to eq 'test key'
         end
       end
+
+      context 'when setting a parent' do
+        let(:parent) { Object.new }
+
+        it 'creates entry with valid parent' do
+          entry = factory
+            .with(value: 'ls', parent: parent)
+            .create!
+
+          expect(entry.parent).to eq parent
+        end
+      end
     end
 
-    context 'when not setting value' do
+    context 'when not setting up a value' do
       it 'raises error' do
         expect { factory.create! }.to raise_error(
           Gitlab::Ci::Config::Node::Factory::InvalidFactory
-- 
GitLab