Commit 5a4c667a authored by Michael Kozono's avatar Michael Kozono

Merge branch 'philipcunningham-add-compact-to-collection-326953' into 'master'

Add Gitlab::Ci::Variables::Collection#compact

See merge request gitlab-org/gitlab!62647
parents abce395a daadeafa
...@@ -24,6 +24,10 @@ module Gitlab ...@@ -24,6 +24,10 @@ module Gitlab
self self
end end
def compact
Collection.new(select { |variable| !variable.value.nil? })
end
def concat(resources) def concat(resources)
return self if resources.nil? return self if resources.nil?
......
...@@ -44,6 +44,30 @@ RSpec.describe Gitlab::Ci::Variables::Collection do ...@@ -44,6 +44,30 @@ RSpec.describe Gitlab::Ci::Variables::Collection do
end end
end end
describe '#compact' do
subject do
described_class.new
.append(key: 'STRING', value: 'string')
.append(key: 'NIL', value: nil)
.append(key: nil, value: 'string')
end
it 'returns a new Collection instance', :aggregate_failures do
collection = subject.compact
expect(collection).to be_an_instance_of(described_class)
expect(collection).not_to eql(subject)
end
it 'rejects pair that has nil value', :aggregate_failures do
collection = subject.compact
expect(collection).not_to include(key: 'NIL', value: nil, public: true)
expect(collection).to include(key: 'STRING', value: 'string', public: true)
expect(collection).to include(key: nil, value: 'string', public: true)
end
end
describe '#concat' do describe '#concat' do
it 'appends all elements from an array' do it 'appends all elements from an array' do
collection = described_class.new([{ key: 'VAR_1', value: '1' }]) collection = described_class.new([{ key: 'VAR_1', value: '1' }])
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment