blob: 81ca9670ac6f152a0803f0a45671b9d47c5ba00c (
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
|
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Sidebars::Projects::Menus::SettingsMenu, feature_category: :navigation do
let(:project) { build_stubbed(:project) }
let(:user) { project.first_owner }
let(:context) { Sidebars::Projects::Context.new(current_user: user, container: project) }
subject { described_class.new(context) }
describe '#render?' do
it 'returns false when menu does not have any menu items' do
allow(subject).to receive(:has_renderable_items?).and_return(false)
expect(subject.render?).to be false
end
end
describe '#separated?' do
it 'returns true' do
expect(subject.separated?).to be true
end
end
describe 'Menu items' do
subject { described_class.new(context).renderable_items.find { |e| e.item_id == item_id } }
shared_examples 'access rights checks' do
specify { is_expected.not_to be_nil }
describe 'when the user does not have access' do
let(:user) { nil }
specify { is_expected.to be_nil }
end
end
describe 'General' do
let(:item_id) { :general }
it_behaves_like 'access rights checks'
end
describe 'Integrations' do
let(:item_id) { :integrations }
it_behaves_like 'access rights checks'
end
describe 'Webhooks' do
let(:item_id) { :webhooks }
it_behaves_like 'access rights checks'
end
describe 'Access Tokens' do
let(:item_id) { :access_tokens }
it_behaves_like 'access rights checks'
describe 'when the user is not an admin but has manage_resource_access_tokens' do
before do
allow(Ability).to receive(:allowed?).and_call_original
allow(Ability).to receive(:allowed?).with(user, :admin_project, project).and_return(false)
allow(Ability).to receive(:allowed?).with(user, :manage_resource_access_tokens, project).and_return(true)
end
it 'includes access token menu item' do
expect(subject.title).to eql('Access Tokens')
end
end
end
describe 'Repository' do
let(:item_id) { :repository }
it_behaves_like 'access rights checks'
end
describe 'CI/CD' do
let(:item_id) { :ci_cd }
describe 'when project is archived' do
before do
allow(project).to receive(:archived?).and_return(true)
end
specify { is_expected.to be_nil }
end
describe 'when project is not archived' do
specify { is_expected.not_to be_nil }
describe 'when the user does not have access' do
let(:user) { nil }
specify { is_expected.to be_nil }
end
end
end
describe 'Monitor' do
let(:item_id) { :monitor }
describe 'when project is archived' do
before do
allow(project).to receive(:archived?).and_return(true)
end
specify { is_expected.to be_nil }
end
describe 'when project is not archived' do
specify { is_expected.not_to be_nil }
specify { expect(subject.title).to eq 'Monitor' }
describe 'when the user does not have access' do
let(:user) { nil }
specify { is_expected.to be_nil }
end
end
end
describe 'Merge requests' do
let(:item_id) { :merge_requests }
it_behaves_like 'access rights checks'
end
describe 'Packages and registries' do
let(:item_id) { :packages_and_registries }
let(:packages_enabled) { false }
before do
stub_container_registry_config(enabled: container_enabled)
stub_config(packages: { enabled: packages_enabled })
end
describe 'when container registry setting is disabled' do
let(:container_enabled) { false }
specify { is_expected.to be_nil }
end
describe 'when container registry setting is enabled' do
let(:container_enabled) { true }
specify { is_expected.not_to be_nil }
describe 'when the user does not have access' do
let(:user) { nil }
specify { is_expected.to be_nil }
end
end
describe 'when package registry setting is enabled' do
let(:container_enabled) { false }
let(:packages_enabled) { true }
specify { is_expected.not_to be_nil }
describe 'when the user does not have access' do
let(:user) { nil }
specify { is_expected.to be_nil }
end
end
end
describe 'Usage Quotas' do
let(:item_id) { :usage_quotas }
specify { is_expected.not_to be_nil }
describe 'when the user does not have access' do
let(:user) { nil }
specify { is_expected.to be_nil }
end
end
end
end
|