diff options
author | Kamil Trzciński <ayufan@ayufan.eu> | 2018-03-15 12:52:55 +0000 |
---|---|---|
committer | Kamil Trzciński <ayufan@ayufan.eu> | 2018-03-15 12:52:55 +0000 |
commit | 2a2b65c4b97a039c553d829d56a58875cde91754 (patch) | |
tree | 022455dec95c3220950d3ae2ce5a5faf530a1fd8 /spec/lib/gitlab/ci/variables/collection/item_spec.rb | |
parent | 0e1c67d15cc2042907cd7e2ed2fb40f2b476a33c (diff) | |
parent | a830c49a3fcf684f89ea5068bbca8ccc1b83fc4c (diff) | |
download | gitlab-ce-2a2b65c4b97a039c553d829d56a58875cde91754.tar.gz |
Merge branch 'backstage/gb/refactor-ci-cd-variables-collections' into 'master'42762-project-settings-sections-cannot-be-expanded-after-submission-error
Introduce CI/CD variables collection
Closes #33042
See merge request gitlab-org/gitlab-ce!14439
Diffstat (limited to 'spec/lib/gitlab/ci/variables/collection/item_spec.rb')
-rw-r--r-- | spec/lib/gitlab/ci/variables/collection/item_spec.rb | 54 |
1 files changed, 54 insertions, 0 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..cc1257484d2 --- /dev/null +++ b/spec/lib/gitlab/ci/variables/collection/item_spec.rb @@ -0,0 +1,54 @@ +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 + variable = create(:ci_variable, key: 'CI_VAR', value: '123') + resource = described_class.fabricate(variable) + + expect(resource).to be_a(described_class) + expect(resource).to eq(key: 'CI_VAR', value: '123', 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 '#[]' 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 + end + end +end |