diff options
author | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2017-09-22 13:17:01 +0300 |
---|---|---|
committer | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2017-09-22 13:29:06 +0300 |
commit | 87637693acbd443c674bcbf26d87281156a70761 (patch) | |
tree | 5e9acb924d93b27c1485bb1e5fdcdc1fcda180d1 /spec/lib/gitlab | |
parent | 26607a1690631916baf5a39d198ff7096cb5bde6 (diff) |
Introduce CI/CD variables collection class
Diffstat (limited to 'spec/lib/gitlab')
-rw-r--r-- | spec/lib/gitlab/ci/variables/collection_spec.rb | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/spec/lib/gitlab/ci/variables/collection_spec.rb b/spec/lib/gitlab/ci/variables/collection_spec.rb new file mode 100644 index 00000000000..0ded8581a86 --- /dev/null +++ b/spec/lib/gitlab/ci/variables/collection_spec.rb @@ -0,0 +1,63 @@ +require 'spec_helper' + +describe Gitlab::Ci::Variables::Collection do + describe '.new' do + it 'can be initialized with an array' do + variable = { key: 'SOME_VAR', value: 'Some Value'} + collection = described_class.new([variable]) + + expect(collection.first.to_h).to include variable + end + + it 'can be initialized without an argument' do + expect(subject).to be_none + end + end + + describe '#append' do + it 'appends a hash' do + subject.append(key: 'VARIABLE', value: 'something') + + expect(subject).to be_one + end + + it 'appends a Ci::Variable' do + subject.append(build(:ci_variable)) + + expect(subject).to be_one + end + + it 'appends an internal resource' do + collection = described_class.new([{ key: 'TEST', value: 1 }]) + + subject.append(collection.first) + + expect(subject).to be_one + end + end + + describe '#+' do + it 'makes it possible to combine with an array' do + collection = described_class.new([{ key: 'TEST', value: 1 }]) + variables = [{ key: 'TEST', value: 'something'}] + + expect((collection + variables).count).to eq 2 + end + + it 'makes it possible to combine with another collection' do + collection = described_class.new([{ key: 'TEST', value: 1 }]) + other = described_class.new([{ key: 'TEST', value: 2 }]) + + expect((collection + other).count).to eq 2 + end + end + + describe '#to_hash' do + it 'creates a hash / value mapping' do + collection = described_class.new([{ key: 'TEST', value: 1 }]) + + expect(collection.to_hash) + .to eq [{ key: 'TEST', value: 1, public: false }] + end + end +end |