2019-04-15 10:17:05 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-03-02 17:35:56 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-03 18:08:28 +00:00
|
|
|
RSpec.describe Projects::ForksController do
|
2016-03-02 17:35:56 +00:00
|
|
|
let(:user) { create(:user) }
|
2017-01-25 21:44:33 +00:00
|
|
|
let(:project) { create(:project, :public, :repository) }
|
2019-08-17 09:14:51 +00:00
|
|
|
let(:forked_project) { Projects::ForkService.new(project, user, name: 'Some name').execute }
|
2018-04-23 15:48:26 +00:00
|
|
|
let(:group) { create(:group) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
group.add_owner(user)
|
|
|
|
end
|
2016-03-02 17:35:56 +00:00
|
|
|
|
2020-01-17 18:08:41 +00:00
|
|
|
shared_examples 'forking disabled' do
|
|
|
|
let(:project) { create(:project, :private, :repository, :forking_disabled) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
project.add_developer(user)
|
|
|
|
sign_in(user)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns with 404' do
|
|
|
|
subject
|
|
|
|
|
2020-01-28 12:08:44 +00:00
|
|
|
expect(response).to have_gitlab_http_status(:not_found)
|
2020-01-17 18:08:41 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-03-02 17:35:56 +00:00
|
|
|
describe 'GET index' do
|
2019-08-17 09:14:51 +00:00
|
|
|
def get_forks(search: nil)
|
2016-03-02 17:35:56 +00:00
|
|
|
get :index,
|
2018-12-17 22:52:17 +00:00
|
|
|
params: {
|
|
|
|
namespace_id: project.namespace,
|
2019-08-17 09:14:51 +00:00
|
|
|
project_id: project,
|
|
|
|
search: search
|
2018-12-17 22:52:17 +00:00
|
|
|
}
|
2016-03-02 17:35:56 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'when fork is public' do
|
2017-06-14 18:18:56 +00:00
|
|
|
before do
|
|
|
|
forked_project.update_attribute(:visibility_level, Project::PUBLIC)
|
|
|
|
end
|
2016-03-02 17:35:56 +00:00
|
|
|
|
2016-07-25 18:16:19 +00:00
|
|
|
it 'is visible for non logged in users' do
|
2016-03-02 17:35:56 +00:00
|
|
|
get_forks
|
|
|
|
|
|
|
|
expect(assigns[:forks]).to be_present
|
|
|
|
end
|
2019-08-17 09:14:51 +00:00
|
|
|
|
|
|
|
it 'forks counts are correct' do
|
|
|
|
get_forks
|
|
|
|
|
|
|
|
expect(assigns[:total_forks_count]).to eq(1)
|
|
|
|
expect(assigns[:public_forks_count]).to eq(1)
|
|
|
|
expect(assigns[:internal_forks_count]).to eq(0)
|
|
|
|
expect(assigns[:private_forks_count]).to eq(0)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'after search' do
|
|
|
|
it 'forks counts are correct' do
|
|
|
|
get_forks(search: 'Non-matching query')
|
|
|
|
|
|
|
|
expect(assigns[:total_forks_count]).to eq(1)
|
|
|
|
expect(assigns[:public_forks_count]).to eq(1)
|
|
|
|
expect(assigns[:internal_forks_count]).to eq(0)
|
|
|
|
expect(assigns[:private_forks_count]).to eq(0)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when fork is internal' do
|
|
|
|
before do
|
|
|
|
forked_project.update(visibility_level: Project::INTERNAL, group: group)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'forks counts are correct' do
|
|
|
|
get_forks
|
|
|
|
|
|
|
|
expect(assigns[:total_forks_count]).to eq(1)
|
|
|
|
expect(assigns[:public_forks_count]).to eq(0)
|
|
|
|
expect(assigns[:internal_forks_count]).to eq(1)
|
|
|
|
expect(assigns[:private_forks_count]).to eq(0)
|
|
|
|
end
|
2016-03-02 17:35:56 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'when fork is private' do
|
|
|
|
before do
|
2018-07-02 10:43:06 +00:00
|
|
|
forked_project.update(visibility_level: Project::PRIVATE, group: group)
|
2016-03-02 17:35:56 +00:00
|
|
|
end
|
|
|
|
|
2019-08-17 09:14:51 +00:00
|
|
|
shared_examples 'forks counts' do
|
|
|
|
it 'forks counts are correct' do
|
|
|
|
get_forks
|
|
|
|
|
|
|
|
expect(assigns[:total_forks_count]).to eq(1)
|
|
|
|
expect(assigns[:public_forks_count]).to eq(0)
|
|
|
|
expect(assigns[:internal_forks_count]).to eq(0)
|
|
|
|
expect(assigns[:private_forks_count]).to eq(1)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'is not visible for non logged in users' do
|
2016-03-02 17:35:56 +00:00
|
|
|
get_forks
|
|
|
|
|
|
|
|
expect(assigns[:forks]).to be_blank
|
|
|
|
end
|
|
|
|
|
2019-08-17 09:14:51 +00:00
|
|
|
include_examples 'forks counts'
|
|
|
|
|
2016-03-02 17:35:56 +00:00
|
|
|
context 'when user is logged in' do
|
2017-06-14 18:18:56 +00:00
|
|
|
before do
|
|
|
|
sign_in(project.creator)
|
|
|
|
end
|
2016-03-02 17:35:56 +00:00
|
|
|
|
|
|
|
context 'when user is not a Project member neither a group member' do
|
2016-07-25 18:16:19 +00:00
|
|
|
it 'does not see the Project listed' do
|
2016-03-02 17:35:56 +00:00
|
|
|
get_forks
|
|
|
|
|
|
|
|
expect(assigns[:forks]).to be_blank
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when user is a member of the Project' do
|
2017-06-14 18:18:56 +00:00
|
|
|
before do
|
2017-12-22 08:18:28 +00:00
|
|
|
forked_project.add_developer(project.creator)
|
2017-06-14 18:18:56 +00:00
|
|
|
end
|
2016-03-02 17:35:56 +00:00
|
|
|
|
2016-07-25 18:16:19 +00:00
|
|
|
it 'sees the project listed' do
|
2016-03-02 17:35:56 +00:00
|
|
|
get_forks
|
|
|
|
|
|
|
|
expect(assigns[:forks]).to be_present
|
|
|
|
end
|
2019-08-17 09:14:51 +00:00
|
|
|
|
|
|
|
include_examples 'forks counts'
|
2016-03-02 17:35:56 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'when user is a member of the Group' do
|
2017-06-14 18:18:56 +00:00
|
|
|
before do
|
|
|
|
forked_project.group.add_developer(project.creator)
|
|
|
|
end
|
2016-03-02 17:35:56 +00:00
|
|
|
|
2016-07-25 18:16:19 +00:00
|
|
|
it 'sees the project listed' do
|
2016-03-02 17:35:56 +00:00
|
|
|
get_forks
|
|
|
|
|
|
|
|
expect(assigns[:forks]).to be_present
|
|
|
|
end
|
2019-08-17 09:14:51 +00:00
|
|
|
|
|
|
|
include_examples 'forks counts'
|
2016-03-02 17:35:56 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2016-11-12 23:59:43 +00:00
|
|
|
|
|
|
|
describe 'GET new' do
|
2020-01-17 18:08:41 +00:00
|
|
|
subject do
|
2016-11-14 22:59:11 +00:00
|
|
|
get :new,
|
2020-01-17 18:08:41 +00:00
|
|
|
params: {
|
|
|
|
namespace_id: project.namespace,
|
|
|
|
project_id: project
|
|
|
|
}
|
2016-11-14 22:59:11 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'when user is signed in' do
|
|
|
|
it 'responds with status 200' do
|
|
|
|
sign_in(user)
|
|
|
|
|
2020-01-17 18:08:41 +00:00
|
|
|
subject
|
2016-11-14 22:59:11 +00:00
|
|
|
|
2020-01-28 12:08:44 +00:00
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
2016-11-14 22:59:11 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when user is not signed in' do
|
|
|
|
it 'redirects to the sign-in page' do
|
|
|
|
sign_out(user)
|
|
|
|
|
2020-01-17 18:08:41 +00:00
|
|
|
subject
|
2016-11-14 22:59:11 +00:00
|
|
|
|
|
|
|
expect(response).to redirect_to(new_user_session_path)
|
|
|
|
end
|
|
|
|
end
|
2020-01-17 18:08:41 +00:00
|
|
|
|
|
|
|
it_behaves_like 'forking disabled'
|
2016-11-14 22:59:11 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
describe 'POST create' do
|
2020-01-17 18:08:41 +00:00
|
|
|
let(:params) do
|
|
|
|
{
|
|
|
|
namespace_id: project.namespace,
|
|
|
|
project_id: project,
|
|
|
|
namespace_key: user.namespace.id
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
subject do
|
|
|
|
post :create, params: params
|
2016-11-14 22:59:11 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'when user is signed in' do
|
2019-06-20 17:45:01 +00:00
|
|
|
before do
|
2016-11-14 22:59:11 +00:00
|
|
|
sign_in(user)
|
2019-06-20 17:45:01 +00:00
|
|
|
end
|
2016-11-14 22:59:11 +00:00
|
|
|
|
2019-06-20 17:45:01 +00:00
|
|
|
it 'responds with status 302' do
|
2020-01-17 18:08:41 +00:00
|
|
|
subject
|
2016-11-14 22:59:11 +00:00
|
|
|
|
2020-01-28 12:08:44 +00:00
|
|
|
expect(response).to have_gitlab_http_status(:found)
|
2016-11-15 18:23:20 +00:00
|
|
|
expect(response).to redirect_to(namespace_project_import_path(user.namespace, project))
|
2016-11-14 22:59:11 +00:00
|
|
|
end
|
2019-06-20 17:45:01 +00:00
|
|
|
|
2020-02-20 09:09:13 +00:00
|
|
|
context 'when target namespace is not valid for forking' do
|
|
|
|
let(:params) { super().merge(namespace_key: another_group.id) }
|
|
|
|
let(:another_group) { create :group }
|
|
|
|
|
|
|
|
it 'responds with :not_found' do
|
|
|
|
subject
|
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(:not_found)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-01-17 18:08:41 +00:00
|
|
|
context 'continue params' do
|
|
|
|
let(:params) do
|
|
|
|
{
|
|
|
|
namespace_id: project.namespace,
|
|
|
|
project_id: project,
|
|
|
|
namespace_key: user.namespace.id,
|
|
|
|
continue: continue_params
|
|
|
|
}
|
|
|
|
end
|
|
|
|
let(:continue_params) do
|
|
|
|
{
|
|
|
|
to: '/-/ide/project/path',
|
|
|
|
notice: 'message'
|
|
|
|
}
|
|
|
|
end
|
2019-06-20 17:45:01 +00:00
|
|
|
|
2020-01-17 18:08:41 +00:00
|
|
|
it 'passes continue params to the redirect' do
|
|
|
|
subject
|
|
|
|
|
2020-01-28 12:08:44 +00:00
|
|
|
expect(response).to have_gitlab_http_status(:found)
|
2020-01-17 18:08:41 +00:00
|
|
|
expect(response).to redirect_to(namespace_project_import_path(user.namespace, project, continue: continue_params))
|
|
|
|
end
|
2019-06-20 17:45:01 +00:00
|
|
|
end
|
2016-11-14 22:59:11 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'when user is not signed in' do
|
2016-11-12 23:59:43 +00:00
|
|
|
it 'redirects to the sign-in page' do
|
2016-11-14 22:59:11 +00:00
|
|
|
sign_out(user)
|
|
|
|
|
2020-01-17 18:08:41 +00:00
|
|
|
subject
|
2016-11-12 23:59:43 +00:00
|
|
|
|
2016-11-14 22:59:11 +00:00
|
|
|
expect(response).to redirect_to(new_user_session_path)
|
2016-11-12 23:59:43 +00:00
|
|
|
end
|
|
|
|
end
|
2020-01-17 18:08:41 +00:00
|
|
|
|
|
|
|
it_behaves_like 'forking disabled'
|
2016-11-12 23:59:43 +00:00
|
|
|
end
|
2016-03-02 17:35:56 +00:00
|
|
|
end
|