diff options
author | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2018-03-12 15:58:54 +0300 |
---|---|---|
committer | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2018-03-12 15:58:54 +0300 |
commit | 5ed8286e742597720d48e3bf6fc56938ba717f5e (patch) | |
tree | ef52db059c2d04ce620c0871fa41809b0b074b23 /spec/lib/gitlab | |
parent | 9d4c9272e016442cd84fbada82493b03b350bb8e (diff) |
Extract variables collection item to a separate class
Diffstat (limited to 'spec/lib/gitlab')
-rw-r--r-- | spec/lib/gitlab/ci/variables/collection/item_spec.rb | 47 | ||||
-rw-r--r-- | spec/lib/gitlab/ci/variables/collection_spec.rb | 5 |
2 files changed, 50 insertions, 2 deletions
diff --git a/spec/lib/gitlab/ci/variables/collection/item_spec.rb b/spec/lib/gitlab/ci/variables/collection/item_spec.rb new file mode 100644 index 00000000000..6f86d658f52 --- /dev/null +++ b/spec/lib/gitlab/ci/variables/collection/item_spec.rb @@ -0,0 +1,47 @@ +require 'spec_helper' + +describe Gitlab::Ci::Variables::Collection::Item do + let(:variable) do + { key: 'VAR', value: 'something', public: true } + end + + describe '.fabricate' do + it 'supports using a hash' do + resource = described_class.fabricate(variable) + + expect(resource).to be_a(described_class) + expect(resource).to eq variable + end + + it 'supports using an active record resource' do + resource = described_class.fabricate(create(:ci_variable)) + + expect(resource).to be_a(described_class) + expect(resource).to eq(key: 'VARIABLE_1', + value: 'VARIABLE_VALUE', + public: false) + end + + it 'supports using another collection item' do + item = described_class.new(**variable) + + resource = described_class.fabricate(item) + + expect(resource).to be_a(described_class) + expect(resource).to eq variable + expect(resource.object_id).not_to eq item.object_id + end + end + + describe '#==' do + it 'compares a hash representation of a variable' do + expect(described_class.new(**variable) == variable).to be true + 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 + end + end +end diff --git a/spec/lib/gitlab/ci/variables/collection_spec.rb b/spec/lib/gitlab/ci/variables/collection_spec.rb index 16c23ae450a..c4b2df7dede 100644 --- a/spec/lib/gitlab/ci/variables/collection_spec.rb +++ b/spec/lib/gitlab/ci/variables/collection_spec.rb @@ -3,10 +3,11 @@ 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' } + variable = { key: 'VAR', value: 'value', public: true } + collection = described_class.new([variable]) - expect(collection.first.to_h).to include variable + expect(collection.first.to_hash).to eq variable end it 'can be initialized without an argument' do |