collection_spec.rb 1.66 KB
Newer Older
1
2
3
4
5
require 'spec_helper'

describe Gitlab::Ci::Variables::Collection do
  describe '.new' do
    it 'can be initialized with an array' do
6
7
      variable = { key: 'VAR', value: 'value', public: true }

8
9
      collection = described_class.new([variable])

10
      expect(collection.first.to_hash).to eq variable
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
    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 }])
43
      variables = [{ key: 'TEST', value: 'something' }]
44
45
46
47
48
49
50
51
52
53
54
55

      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

56
57
  describe '#to_runner_variables' do
    it 'creates an array of hashes in a runner-compatible format' do
58
59
      collection = described_class.new([{ key: 'TEST', value: 1 }])

60
      expect(collection.to_runner_variables)
61
        .to eq [{ key: 'TEST', value: 1, public: true }]
62
63
64
    end
  end
end