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

project_auto_devops_spec.rb « models « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: f9ee9fe98bda3dad2b2fec61a9697583ac90b6ea (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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
require 'spec_helper'

describe ProjectAutoDevops do
  set(:project) { build(:project) }

  it { is_expected.to belong_to(:project) }

  it { is_expected.to define_enum_for(:deploy_strategy) }

  it { is_expected.to respond_to(:created_at) }
  it { is_expected.to respond_to(:updated_at) }

  describe '#has_domain?' do
    context 'when domain is defined' do
      let(:auto_devops) { build_stubbed(:project_auto_devops, project: project, domain: 'domain.com') }

      it { expect(auto_devops).to have_domain }
    end

    context 'when domain is empty' do
      let(:auto_devops) { build_stubbed(:project_auto_devops, project: project, domain: '') }

      context 'when there is an instance domain specified' do
        before do
          allow(Gitlab::CurrentSettings).to receive(:auto_devops_domain).and_return('example.com')
        end

        it { expect(auto_devops).to have_domain }
      end

      context 'when there is no instance domain specified' do
        before do
          allow(Gitlab::CurrentSettings).to receive(:auto_devops_domain).and_return(nil)
        end

        it { expect(auto_devops).not_to have_domain }
      end
    end
  end

  describe '#predefined_variables' do
    let(:auto_devops) { build_stubbed(:project_auto_devops, project: project, domain: domain) }

    context 'when domain is defined' do
      let(:domain) { 'example.com' }

      it 'returns AUTO_DEVOPS_DOMAIN' do
        expect(auto_devops.predefined_variables).to include(domain_variable)
      end
    end

    context 'when domain is not defined' do
      let(:domain) { nil }

      context 'when there is an instance domain specified' do
        before do
          allow(Gitlab::CurrentSettings).to receive(:auto_devops_domain).and_return('example.com')
        end

        it { expect(auto_devops.predefined_variables).to include(domain_variable) }
      end

      context 'when there is no instance domain specified' do
        before do
          allow(Gitlab::CurrentSettings).to receive(:auto_devops_domain).and_return(nil)
        end

        it { expect(auto_devops.predefined_variables).not_to include(domain_variable) }
      end
    end

    context 'when deploy_strategy is manual' do
      let(:domain) { 'example.com' }

      before do
        auto_devops.deploy_strategy = 'manual'
      end

      it do
        expect(auto_devops.predefined_variables.map { |var| var[:key] })
          .to include("STAGING_ENABLED", "INCREMENTAL_ROLLOUT_ENABLED")
      end
    end

    context 'when deploy_strategy is continuous' do
      let(:domain) { 'example.com' }

      before do
        auto_devops.deploy_strategy = 'continuous'
      end

      it do
        expect(auto_devops.predefined_variables.map { |var| var[:key] })
          .not_to include("STAGING_ENABLED", "INCREMENTAL_ROLLOUT_ENABLED")
      end
    end

    def domain_variable
      { key: 'AUTO_DEVOPS_DOMAIN', value: 'example.com', public: true }
    end
  end
end