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
require 'spec_helper'
describe Projects::ForksController do
let(:user) { create(:user) }
let(:project) { create(:project, :public, :repository) }
let(:forked_project) { Projects::ForkService.new(project, user).execute }
let(:group) { create(:group, owner: forked_project.creator) }
describe 'GET index' do
def get_forks
get :index,
namespace_id: project.namespace.to_param,
project_id: project.to_param
end
context 'when fork is public' do
before { forked_project.update_attribute(:visibility_level, Project::PUBLIC) }
it 'is visible for non logged in users' do
get_forks
expect(assigns[:forks]).to be_present
end
end
context 'when fork is private' do
before do
forked_project.update_attributes(visibility_level: Project::PRIVATE, group: group)
end
it 'is not be visible for non logged in users' do
get_forks
expect(assigns[:forks]).to be_blank
end
context 'when user is logged in' do
before { sign_in(project.creator) }
context 'when user is not a Project member neither a group member' do
it 'does not see the Project listed' do
get_forks
expect(assigns[:forks]).to be_blank
end
end
context 'when user is a member of the Project' do
before { forked_project.team << [project.creator, :developer] }
it 'sees the project listed' do
get_forks
expect(assigns[:forks]).to be_present
end
end
context 'when user is a member of the Group' do
before { forked_project.group.add_developer(project.creator) }
it 'sees the project listed' do
get_forks
expect(assigns[:forks]).to be_present
end
end
end
end
end
describe 'GET new' do
def get_new
get :new,
namespace_id: project.namespace.to_param,
project_id: project.to_param
end
context 'when user is signed in' do
it 'responds with status 200' do
sign_in(user)
get_new
expect(response).to have_http_status(200)
end
end
context 'when user is not signed in' do
it 'redirects to the sign-in page' do
sign_out(user)
get_new
expect(response).to redirect_to(new_user_session_path)
end
end
end
describe 'POST create' do
def post_create
post :create,
namespace_id: project.namespace.to_param,
project_id: project.to_param,
namespace_key: user.namespace.id
end
context 'when user is signed in' do
it 'responds with status 302' do
sign_in(user)
post_create
expect(response).to have_http_status(302)
expect(response).to redirect_to(namespace_project_import_path(user.namespace, project))
end
end
context 'when user is not signed in' do
it 'redirects to the sign-in page' do
sign_out(user)
post_create
expect(response).to redirect_to(new_user_session_path)
end
end
end
end