Commit daadeafa authored by Philip Cunningham's avatar Philip Cunningham

Add #compact method to Ci::Variables::Collection

- Add new #compact method
- Add new specs for #compact
parent 235a261d
......@@ -24,6 +24,10 @@ module Gitlab
self
end
def compact
Collection.new(select { |variable| !variable.value.nil? })
end
def concat(resources)
return self if resources.nil?
......
......@@ -44,6 +44,30 @@ RSpec.describe Gitlab::Ci::Variables::Collection do
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
it 'appends all elements from an array' do
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