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

tracings_controller_spec.rb « projects « controllers « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 80e21349e20fa2fcd01318f1712e764bffc1c67b (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
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Projects::TracingsController do
  let_it_be(:user) { create(:user) }

  describe 'GET show' do
    shared_examples 'user with read access' do |visibility_level|
      let(:project) { create(:project, visibility_level) }

      %w[developer maintainer].each do |role|
        context "with a #{visibility_level} project and #{role} role" do
          before do
            project.add_role(user, role)
          end

          it 'renders OK' do
            get :show, params: { namespace_id: project.namespace, project_id: project }

            expect(response).to have_gitlab_http_status(:ok)
            expect(response).to render_template(:show)
          end
        end
      end
    end

    shared_examples 'user without read access' do |visibility_level|
      let(:project) { create(:project, visibility_level) }

      %w[guest reporter].each do |role|
        context "with a #{visibility_level} project and #{role} role" do
          before do
            project.add_role(user, role)
          end

          it 'returns 404' do
            get :show, params: { namespace_id: project.namespace, project_id: project }

            expect(response).to have_gitlab_http_status(:not_found)
          end
        end
      end
    end

    before do
      sign_in(user)
    end

    context 'with maintainer role' do
      it_behaves_like 'user with read access', :public
      it_behaves_like 'user with read access', :internal
      it_behaves_like 'user with read access', :private

      context 'feature flag disabled' do
        before do
          stub_feature_flags(monitor_tracing: false)
        end

        it_behaves_like 'user without read access', :public
        it_behaves_like 'user without read access', :internal
        it_behaves_like 'user without read access', :private
      end
    end

    context 'without maintainer role' do
      it_behaves_like 'user without read access', :public
      it_behaves_like 'user without read access', :internal
      it_behaves_like 'user without read access', :private
    end
  end
end