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
require 'spec_helper'
describe Ci::TriggerPolicy, :models do
let(:user) { create(:user) }
let(:project) { create(:empty_project) }
let(:trigger) { create(:ci_trigger, project: project, owner: owner) }
let(:policies) do
described_class.abilities(user, trigger).to_set
end
shared_examples 'allows to admin and manage trigger' do
it 'does include ability to admin trigger' do
expect(policies).to include :admin_trigger
end
it 'does include ability to manage trigger' do
expect(policies).to include :manage_trigger
end
end
shared_examples 'allows to manage trigger' do
it 'does not include ability to admin trigger' do
expect(policies).not_to include :admin_trigger
end
it 'does include ability to manage trigger' do
expect(policies).to include :manage_trigger
end
end
shared_examples 'disallows to admin and manage trigger' do
it 'does not include ability to admin trigger' do
expect(policies).not_to include :admin_trigger
end
it 'does not include ability to manage trigger' do
expect(policies).not_to include :manage_trigger
end
end
describe '#rules' do
context 'when owner is undefined' do
let(:owner) { nil }
context 'when user is master of the project' do
before do
project.team << [user, :master]
end
it_behaves_like 'allows to admin and manage trigger'
end
context 'when user is developer of the project' do
before do
project.team << [user, :developer]
end
it_behaves_like 'disallows to admin and manage trigger'
end
context 'when user is not member of the project' do
it_behaves_like 'disallows to admin and manage trigger'
end
end
context 'when owner is an user' do
let(:owner) { user }
context 'when user is master of the project' do
before do
project.team << [user, :master]
end
it_behaves_like 'allows to admin and manage trigger'
end
end
context 'when owner is another user' do
let(:owner) { create(:user) }
context 'when user is master of the project' do
before do
project.team << [user, :master]
end
it_behaves_like 'allows to manage trigger'
end
context 'when user is developer of the project' do
before do
project.team << [user, :developer]
end
it_behaves_like 'disallows to admin and manage trigger'
end
context 'when user is not member of the project' do
it_behaves_like 'disallows to admin and manage trigger'
end
end
end
end