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

deployable_policy_shared_examples_ee.rb « ci « shared_examples « support « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: b1057b3f67a9bc6b8d78cf56539662a14507afa0 (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
# frozen_string_literal: true

RSpec.shared_examples 'a deployable job policy in EE' do |factory_type|
  using RSpec::Parameterized::TableSyntax

  let_it_be(:group) { create(:group) }
  let_it_be(:project) { create(:project, :repository, group: group) }

  let(:user) { create(:user) }
  let(:pipeline) { create(:ci_empty_pipeline, project: project) }
  let(:environment) { create(:environment, project: project, name: 'production') }

  let(:job) do
    create(factory_type, pipeline: pipeline, project: project, environment: 'production', ref: 'development')
  end

  describe '#update_build?' do
    subject { user.can?(:update_build, job) }

    it_behaves_like 'protected environments access', direct_access: true
  end

  describe '#update_commit_status?' do
    subject { user.can?(:update_commit_status, job) }

    it_behaves_like 'protected environments access', direct_access: true
  end

  describe '#erase_build?' do
    subject { user.can?(:erase_build, job) }

    context 'when the job triggerer is a project maintainer' do
      let_it_be_with_refind(:user) { create(:user).tap { |u| project.add_maintainer(u) } }

      before do
        stub_licensed_features(protected_environments: true)
      end

      it 'returns true for ci_build' do
        # Currently, we allow users to delete normal jobs only.
        if factory_type == :ci_build
          is_expected.to eq(true)
        else
          is_expected.to eq(false)
        end
      end

      context 'when environment is protected' do
        before do
          create(:protected_environment, name: environment.name, project: project)
        end

        it { is_expected.to eq(false) }
      end
    end
  end
end