2019-04-15 06:17:05 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-03-02 12:35:56 -05:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe Projects::ForksController do
|
|
|
|
let(:user) { create(:user) }
|
2017-01-25 16:44:33 -05:00
|
|
|
let(:project) { create(:project, :public, :repository) }
|
2016-03-02 12:35:56 -05:00
|
|
|
let(:forked_project) { Projects::ForkService.new(project, user).execute }
|
2018-04-23 11:48:26 -04:00
|
|
|
let(:group) { create(:group) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
group.add_owner(user)
|
|
|
|
end
|
2016-03-02 12:35:56 -05:00
|
|
|
|
|
|
|
describe 'GET index' do
|
|
|
|
def get_forks
|
|
|
|
get :index,
|
2018-12-17 17:52:17 -05:00
|
|
|
params: {
|
|
|
|
namespace_id: project.namespace,
|
|
|
|
project_id: project
|
|
|
|
}
|
2016-03-02 12:35:56 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'when fork is public' do
|
2017-06-14 14:18:56 -04:00
|
|
|
before do
|
|
|
|
forked_project.update_attribute(:visibility_level, Project::PUBLIC)
|
|
|
|
end
|
2016-03-02 12:35:56 -05:00
|
|
|
|
2016-07-25 14:16:19 -04:00
|
|
|
it 'is visible for non logged in users' do
|
2016-03-02 12:35:56 -05:00
|
|
|
get_forks
|
|
|
|
|
|
|
|
expect(assigns[:forks]).to be_present
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when fork is private' do
|
|
|
|
before do
|
2018-07-02 06:43:06 -04:00
|
|
|
forked_project.update(visibility_level: Project::PRIVATE, group: group)
|
2016-03-02 12:35:56 -05:00
|
|
|
end
|
|
|
|
|
2016-07-25 14:16:19 -04:00
|
|
|
it 'is not be visible for non logged in users' do
|
2016-03-02 12:35:56 -05:00
|
|
|
get_forks
|
|
|
|
|
|
|
|
expect(assigns[:forks]).to be_blank
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when user is logged in' do
|
2017-06-14 14:18:56 -04:00
|
|
|
before do
|
|
|
|
sign_in(project.creator)
|
|
|
|
end
|
2016-03-02 12:35:56 -05:00
|
|
|
|
|
|
|
context 'when user is not a Project member neither a group member' do
|
2016-07-25 14:16:19 -04:00
|
|
|
it 'does not see the Project listed' do
|
2016-03-02 12:35:56 -05:00
|
|
|
get_forks
|
|
|
|
|
|
|
|
expect(assigns[:forks]).to be_blank
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when user is a member of the Project' do
|
2017-06-14 14:18:56 -04:00
|
|
|
before do
|
2017-12-22 03:18:28 -05:00
|
|
|
forked_project.add_developer(project.creator)
|
2017-06-14 14:18:56 -04:00
|
|
|
end
|
2016-03-02 12:35:56 -05:00
|
|
|
|
2016-07-25 14:16:19 -04:00
|
|
|
it 'sees the project listed' do
|
2016-03-02 12:35:56 -05:00
|
|
|
get_forks
|
|
|
|
|
|
|
|
expect(assigns[:forks]).to be_present
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when user is a member of the Group' do
|
2017-06-14 14:18:56 -04:00
|
|
|
before do
|
|
|
|
forked_project.group.add_developer(project.creator)
|
|
|
|
end
|
2016-03-02 12:35:56 -05:00
|
|
|
|
2016-07-25 14:16:19 -04:00
|
|
|
it 'sees the project listed' do
|
2016-03-02 12:35:56 -05:00
|
|
|
get_forks
|
|
|
|
|
|
|
|
expect(assigns[:forks]).to be_present
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2016-11-12 18:59:43 -05:00
|
|
|
|
|
|
|
describe 'GET new' do
|
2016-11-14 17:59:11 -05:00
|
|
|
def get_new
|
|
|
|
get :new,
|
2018-12-17 17:52:17 -05:00
|
|
|
params: {
|
|
|
|
namespace_id: project.namespace,
|
|
|
|
project_id: project
|
|
|
|
}
|
2016-11-14 17:59:11 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'when user is signed in' do
|
|
|
|
it 'responds with status 200' do
|
|
|
|
sign_in(user)
|
|
|
|
|
|
|
|
get_new
|
|
|
|
|
2017-10-19 14:28:19 -04:00
|
|
|
expect(response).to have_gitlab_http_status(200)
|
2016-11-14 17:59:11 -05:00
|
|
|
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
|
2019-06-20 13:45:01 -04:00
|
|
|
def post_create(params = {})
|
2016-11-14 17:59:11 -05:00
|
|
|
post :create,
|
2018-12-17 17:52:17 -05:00
|
|
|
params: {
|
|
|
|
namespace_id: project.namespace,
|
|
|
|
project_id: project,
|
|
|
|
namespace_key: user.namespace.id
|
2019-06-20 13:45:01 -04:00
|
|
|
}.merge(params)
|
2016-11-14 17:59:11 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'when user is signed in' do
|
2019-06-20 13:45:01 -04:00
|
|
|
before do
|
2016-11-14 17:59:11 -05:00
|
|
|
sign_in(user)
|
2019-06-20 13:45:01 -04:00
|
|
|
end
|
2016-11-14 17:59:11 -05:00
|
|
|
|
2019-06-20 13:45:01 -04:00
|
|
|
it 'responds with status 302' do
|
2016-11-14 17:59:11 -05:00
|
|
|
post_create
|
|
|
|
|
2017-10-19 14:28:19 -04:00
|
|
|
expect(response).to have_gitlab_http_status(302)
|
2016-11-15 13:23:20 -05:00
|
|
|
expect(response).to redirect_to(namespace_project_import_path(user.namespace, project))
|
2016-11-14 17:59:11 -05:00
|
|
|
end
|
2019-06-20 13:45:01 -04:00
|
|
|
|
|
|
|
it 'passes continue params to the redirect' do
|
|
|
|
continue_params = { to: '/-/ide/project/path', notice: 'message' }
|
|
|
|
post_create continue: continue_params
|
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(302)
|
|
|
|
expect(response).to redirect_to(namespace_project_import_path(user.namespace, project, continue: continue_params))
|
|
|
|
end
|
2016-11-14 17:59:11 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'when user is not signed in' do
|
2016-11-12 18:59:43 -05:00
|
|
|
it 'redirects to the sign-in page' do
|
2016-11-14 17:59:11 -05:00
|
|
|
sign_out(user)
|
|
|
|
|
|
|
|
post_create
|
2016-11-12 18:59:43 -05:00
|
|
|
|
2016-11-14 17:59:11 -05:00
|
|
|
expect(response).to redirect_to(new_user_session_path)
|
2016-11-12 18:59:43 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2016-03-02 12:35:56 -05:00
|
|
|
end
|