summaryrefslogtreecommitdiff
path: root/spec/controllers/projects/pipelines_settings_controller_spec.rb
blob: 913b9bd804a516eb3e1f3d8eeaa3ab02e10ea45f (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
require 'spec_helper'

describe Projects::PipelinesSettingsController do
  set(:user) { create(:user) }
  set(:project_auto_devops) { create(:project_auto_devops) }
  let(:project) { project_auto_devops.project }

  before do
    project.add_master(user)

    sign_in(user)
  end

  describe 'PATCH update' do
    subject do
      patch :update,
        namespace_id: project.namespace.to_param,
        project_id: project,
        project: {
          auto_devops_attributes: params
        }
    end

    context 'when updating the auto_devops settings' do
      let(:params) { { enabled: '', domain: 'mepmep.md' } }

      it 'redirects to the settings page' do
        subject

        expect(response).to have_gitlab_http_status(302)
        expect(flash[:notice]).to eq("Pipelines settings for '#{project.name}' were successfully updated.")
      end

      context 'following the instance default' do
        let(:params) { { enabled: '' } }

        it 'allows enabled to be set to nil' do
          subject
          project_auto_devops.reload

          expect(project_auto_devops.enabled).to be_nil
        end
      end

      context 'when run_auto_devops_pipeline is true' do
        before do
          expect_any_instance_of(Projects::UpdateService).to receive(:run_auto_devops_pipeline?).and_return(true)
        end

        context 'when the project repository is empty' do
          it 'sets a warning flash' do
            expect(subject).to set_flash[:warning]
          end

          it 'does not queue a CreatePipelineWorker' do
            expect(CreatePipelineWorker).not_to receive(:perform_async).with(project.id, user.id, project.default_branch, :web, any_args)

            subject
          end
        end

        context 'when the project repository is not empty' do
          let(:project) { create(:project, :repository) }

          it 'sets a success flash' do
            allow(CreatePipelineWorker).to receive(:perform_async).with(project.id, user.id, project.default_branch, :web, any_args)

            expect(subject).to set_flash[:success]
          end

          it 'queues a CreatePipelineWorker' do
            expect(CreatePipelineWorker).to receive(:perform_async).with(project.id, user.id, project.default_branch, :web, any_args)

            subject
          end
        end
      end

      context 'when run_auto_devops_pipeline is not true' do
        before do
          expect_any_instance_of(Projects::UpdateService).to receive(:run_auto_devops_pipeline?).and_return(false)
        end

        it 'does not queue a CreatePipelineWorker' do
          expect(CreatePipelineWorker).not_to receive(:perform_async).with(project.id, user.id, :web, any_args)

          subject
        end
      end
    end
  end
end