From cf53d798736f7c86459c3e6635a83875e6101373 Mon Sep 17 00:00:00 2001
From: Grzegorz Bizon <grzesiek.bizon@gmail.com>
Date: Tue, 5 Jul 2016 13:07:03 +0200
Subject: [PATCH] Extract jobs config to separate key in config hash

---
 lib/gitlab/ci/config/node/global.rb           | 16 ++++++++++++++++
 spec/lib/gitlab/ci/config/node/global_spec.rb | 12 +++++++++++-
 2 files changed, 27 insertions(+), 1 deletion(-)

diff --git a/lib/gitlab/ci/config/node/global.rb b/lib/gitlab/ci/config/node/global.rb
index f92e1eccbcf..0a4315db047 100644
--- a/lib/gitlab/ci/config/node/global.rb
+++ b/lib/gitlab/ci/config/node/global.rb
@@ -36,6 +36,22 @@ module Gitlab
           helpers :before_script, :image, :services, :after_script,
                   :variables, :stages, :types, :cache
 
+          def initialize(config)
+            return super(config) unless config.is_a?(Hash)
+
+            jobs = config.except(*self.class.nodes.keys)
+            global = config.slice(*self.class.nodes.keys)
+
+            super(global.merge(jobs: jobs))
+          end
+
+          ##
+          # Temporary refactoring stub
+          #
+          def jobs
+            @config[:jobs]
+          end
+
           def stages
             stages_defined? ? stages_value : types_value
           end
diff --git a/spec/lib/gitlab/ci/config/node/global_spec.rb b/spec/lib/gitlab/ci/config/node/global_spec.rb
index c87c9e97bc8..88194bf9453 100644
--- a/spec/lib/gitlab/ci/config/node/global_spec.rb
+++ b/spec/lib/gitlab/ci/config/node/global_spec.rb
@@ -22,7 +22,9 @@ describe Gitlab::Ci::Config::Node::Global do
           variables: { VAR: 'value' },
           after_script: ['make clean'],
           stages: ['build', 'pages'],
-          cache: { key: 'k', untracked: true, paths: ['public/'] } }
+          cache: { key: 'k', untracked: true, paths: ['public/'] },
+          rspec: { script: 'rspec' },
+          spinach: { script: 'spinach' } }
       end
 
       describe '#process!' do
@@ -120,6 +122,14 @@ describe Gitlab::Ci::Config::Node::Global do
               .to eq(key: 'k', untracked: true, paths: ['public/'])
           end
         end
+
+        describe '#jobs' do
+          it 'returns jobs configuration' do
+            expect(global.jobs)
+              .to eq(rspec: { script: 'rspec' },
+                     spinach: { script: 'spinach' })
+          end
+        end
       end
     end
 
-- 
GitLab