summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGrzegorz Bizon <grzesiek.bizon@gmail.com>2018-03-13 14:29:54 +0100
committerGrzegorz Bizon <grzesiek.bizon@gmail.com>2018-03-13 14:29:54 +0100
commitd4319e1700b2eb4070a9cdac71b6f5b78ede08ff (patch)
treeaa61def977c868c90957c80e98953a6fc6eec094
parente16fba6726adcf7e82862336fab22c6c6baf2010 (diff)
downloadgitlab-ce-d4319e1700b2eb4070a9cdac71b6f5b78ede08ff.tar.gz
Add more unit tests for variables collection class
-rw-r--r--lib/gitlab/ci/variables/collection.rb1
-rw-r--r--spec/lib/gitlab/ci/variables/collection/item_spec.rb8
-rw-r--r--spec/lib/gitlab/ci/variables/collection_spec.rb25
3 files changed, 33 insertions, 1 deletions
diff --git a/lib/gitlab/ci/variables/collection.rb b/lib/gitlab/ci/variables/collection.rb
index 97ca6dc3d3d..ae7415fcdb1 100644
--- a/lib/gitlab/ci/variables/collection.rb
+++ b/lib/gitlab/ci/variables/collection.rb
@@ -14,7 +14,6 @@ module Gitlab
@variables.append(Collection::Item.fabricate(resource))
end
- # TODO, specs
def concat(resources)
resources.each { |variable| self.append(variable) }
end
diff --git a/spec/lib/gitlab/ci/variables/collection/item_spec.rb b/spec/lib/gitlab/ci/variables/collection/item_spec.rb
index 6f86d658f52..37394c3e80f 100644
--- a/spec/lib/gitlab/ci/variables/collection/item_spec.rb
+++ b/spec/lib/gitlab/ci/variables/collection/item_spec.rb
@@ -39,6 +39,14 @@ describe Gitlab::Ci::Variables::Collection::Item do
end
end
+ describe '#[]' do
+ it 'behaves like a hash accessor' do
+ item = described_class.new(**variable)
+
+ expect(item[:key]).to eq 'VAR'
+ end
+ end
+
describe '#to_hash' do
it 'returns a hash representation of a collection item' do
expect(described_class.new(**variable).to_hash).to eq variable
diff --git a/spec/lib/gitlab/ci/variables/collection_spec.rb b/spec/lib/gitlab/ci/variables/collection_spec.rb
index 9ee39d40625..005e2bb17b4 100644
--- a/spec/lib/gitlab/ci/variables/collection_spec.rb
+++ b/spec/lib/gitlab/ci/variables/collection_spec.rb
@@ -37,6 +37,31 @@ describe Gitlab::Ci::Variables::Collection do
end
end
+ describe '#concat' do
+ it 'appends all elements from an array' do
+ collection = described_class.new([{ key: 'VAR_1', value: '1' }])
+ variables = [{ key: 'VAR_2', value: '2' }, { key: 'VAR_3', value: '3' }]
+
+ collection.concat(variables)
+
+ expect(collection).to include(key: 'VAR_1', value: '1', public: true)
+ expect(collection).to include(key: 'VAR_2', value: '2', public: true)
+ expect(collection).to include(key: 'VAR_3', value: '3', public: true)
+ end
+
+ it 'appends all elements from other collection' do
+ collection = described_class.new([{ key: 'VAR_1', value: '1' }])
+ additional = described_class.new([{ key: 'VAR_2', value: '2' },
+ { key: 'VAR_3', value: '3' }])
+
+ collection.concat(additional)
+
+ expect(collection).to include(key: 'VAR_1', value: '1', public: true)
+ expect(collection).to include(key: 'VAR_2', value: '2', public: true)
+ expect(collection).to include(key: 'VAR_3', value: '3', public: true)
+ end
+ end
+
describe '#+' do
it 'makes it possible to combine with an array' do
collection = described_class.new([{ key: 'TEST', value: 1 }])