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
|
require 'spec_helper'
describe User do
describe "has_developer_access?" do
before do
@user = described_class.new({})
end
let(:project_with_owner_access) do
{
"name" => "gitlab-shell",
"permissions" => {
"project_access" => {
"access_level"=> 10,
"notification_level" => 3
},
"group_access" => {
"access_level" => 50,
"notification_level" => 3
}
}
}
end
let(:project_with_reporter_access) do
{
"name" => "gitlab-shell",
"permissions" => {
"project_access" => {
"access_level" => 20,
"notification_level" => 3
},
"group_access" => {
"access_level" => 10,
"notification_level" => 3
}
}
}
end
it "returns false for reporter" do
allow(@user).to receive(:project_info).and_return(project_with_reporter_access)
expect(@user.has_developer_access?(1)).to be_falsey
end
it "returns true for owner" do
allow(@user).to receive(:project_info).and_return(project_with_owner_access)
expect(@user.has_developer_access?(1)).to be_truthy
end
end
describe "authorized_projects" do
let (:user) { described_class.new({}) }
before do
FactoryGirl.create :project, gitlab_id: 1
FactoryGirl.create :project, gitlab_id: 2
gitlab_project = OpenStruct.new({id: 1})
gitlab_project1 = OpenStruct.new({id: 2})
allow_any_instance_of(described_class).to receive(:gitlab_projects).and_return([gitlab_project, gitlab_project1])
end
it "returns projects" do
allow_any_instance_of(described_class).to receive(:can_manage_project?).and_return(true)
expect(user.authorized_projects.count).to eq 2
end
it "empty list if user miss manage permission" do
allow_any_instance_of(described_class).to receive(:can_manage_project?).and_return(false)
expect(user.authorized_projects.count).to eq 0
end
end
describe "authorized_runners" do
it "returns authorized runners" do
project = FactoryGirl.create :project, gitlab_id: 1
project1 = FactoryGirl.create :project, gitlab_id: 2
gitlab_project = OpenStruct.new({id: 1})
gitlab_project1 = OpenStruct.new({id: 2})
allow_any_instance_of(described_class).to receive(:gitlab_projects).and_return([gitlab_project, gitlab_project1])
allow_any_instance_of(described_class).to receive(:can_manage_project?).and_return(true)
user = described_class.new({})
runner = FactoryGirl.create :specific_runner
runner1 = FactoryGirl.create :specific_runner
runner2 = FactoryGirl.create :specific_runner
project.runners << runner
project1.runners << runner1
expect(user.authorized_runners).to include(runner, runner1)
expect(user.authorized_runners).not_to include(runner2)
end
end
end
|