From a60ccef9fec1d798dd0178d10b6a6a109612c17d Mon Sep 17 00:00:00 2001
From: Grzegorz Bizon <grzesiek.bizon@gmail.com>
Date: Tue, 27 Mar 2018 13:46:22 +0200
Subject: [PATCH] Add specs for method that exposes build variables hash

---
 app/models/ci/build.rb       |  3 ---
 spec/models/ci/build_spec.rb | 12 ++++++++++++
 2 files changed, 12 insertions(+), 3 deletions(-)

diff --git a/app/models/ci/build.rb b/app/models/ci/build.rb
index 5f149ad305..68aafdd730 100644
--- a/app/models/ci/build.rb
+++ b/app/models/ci/build.rb
@@ -288,9 +288,6 @@ module Ci
         .to_runner_variables
     end
 
-    ##
-    # TODO, add specs
-    #
     def variables_hash
       scoped_variables.to_hash
     end
diff --git a/spec/models/ci/build_spec.rb b/spec/models/ci/build_spec.rb
index f4d3e57b22..0f62ff4cca 100644
--- a/spec/models/ci/build_spec.rb
+++ b/spec/models/ci/build_spec.rb
@@ -2053,6 +2053,18 @@ describe Ci::Build do
     end
   end
 
+  describe '#variables_hash' do
+    before do
+      project.variables.create!(key: 'MY_VAR', value: 'my value 1')
+      pipeline.variables.create!(key: 'MY_VAR', value: 'my value 2')
+    end
+
+    it 'returns a regular hash created in valid order' do
+      expect(build.variables_hash).to include('MY_VAR': 'my value 2')
+      expect(build.variables_hash).not_to include('MY_VAR': 'my value 1')
+    end
+  end
+
   describe 'state transition: any => [:pending]' do
     let(:build) { create(:ci_build, :created) }
 
-- 
2.30.9