Welcome to mirror list, hosted at ThFree Co, Russian Federation.

release_spec.rb « builder « variables « ci « gitlab « lib « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 85b1659d07b6c5a5d34711cad4bd4d43f67eec54 (plain)
1
2
3
4
5
6
7
8
9
10
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Gitlab::Ci::Variables::Builder::Release do
  let_it_be(:project) { create(:project, :public, :repository) }
  let_it_be(:release) { create(:release, project: project) }

  let(:builder) { described_class.new(release) }

  describe '#variables' do
    let(:description_variable) do
      {
        key: 'CI_RELEASE_DESCRIPTION',
        value: release.description,
        public: true,
        masked: false,
        raw: true
      }
    end

    subject do
      builder.variables
    end

    context 'when the release is present' do
      let(:description_item) { item(description_variable) }

      it 'contains all the variables' do
        is_expected.to contain_exactly(description_item)
      end

      context 'for large description' do
        before do
          release.update_attribute(:description, "Test Description ..." * 5000)
        end

        it 'truncates' do
          expect(subject['CI_RELEASE_DESCRIPTION'].value.length).to eq(1024)
        end
      end

      context 'when description is nil' do
        before do
          release.update_attribute(:description, nil)
        end

        it 'returns without error' do
          builder = subject

          expect(builder).to match_array([])
          expect(builder.errors).to be_nil
        end
      end
    end

    context 'when the release is not present' do
      let(:release) { nil }

      it 'contains no variables' do
        is_expected.to match_array([])
      end
    end
  end

  def item(variable)
    ::Gitlab::Ci::Variables::Collection::Item.fabricate(variable)
  end
end