debian-mirror-gitlab/spec/controllers/projects/forks_controller_spec.rb

261 lines
6.3 KiB
Ruby
Raw Normal View History

2019-07-31 22:56:46 +05:30
# frozen_string_literal: true
2016-06-02 11:05:42 +05:30
require 'spec_helper'
describe Projects::ForksController do
let(:user) { create(:user) }
2017-08-17 22:00:37 +05:30
let(:project) { create(:project, :public, :repository) }
2019-12-04 20:38:33 +05:30
let(:forked_project) { Projects::ForkService.new(project, user, name: 'Some name').execute }
2018-10-15 14:42:47 +05:30
let(:group) { create(:group) }
before do
group.add_owner(user)
end
2016-06-02 11:05:42 +05:30
2020-03-13 15:44:24 +05:30
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
expect(response).to have_gitlab_http_status(:not_found)
end
end
2016-06-02 11:05:42 +05:30
describe 'GET index' do
2019-12-04 20:38:33 +05:30
def get_forks(search: nil)
2016-06-02 11:05:42 +05:30
get :index,
2019-02-15 15:39:39 +05:30
params: {
namespace_id: project.namespace,
2019-12-04 20:38:33 +05:30
project_id: project,
search: search
2019-02-15 15:39:39 +05:30
}
2016-06-02 11:05:42 +05:30
end
context 'when fork is public' do
2017-09-10 17:25:29 +05:30
before do
forked_project.update_attribute(:visibility_level, Project::PUBLIC)
end
2016-06-02 11:05:42 +05:30
2016-09-13 17:45:13 +05:30
it 'is visible for non logged in users' do
2016-06-02 11:05:42 +05:30
get_forks
expect(assigns[:forks]).to be_present
end
2019-12-04 20:38:33 +05:30
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-06-02 11:05:42 +05:30
end
context 'when fork is private' do
before do
2018-11-18 11:00:15 +05:30
forked_project.update(visibility_level: Project::PRIVATE, group: group)
2016-06-02 11:05:42 +05:30
end
2019-12-04 20:38:33 +05:30
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-06-02 11:05:42 +05:30
get_forks
expect(assigns[:forks]).to be_blank
end
2019-12-04 20:38:33 +05:30
include_examples 'forks counts'
2016-06-02 11:05:42 +05:30
context 'when user is logged in' do
2017-09-10 17:25:29 +05:30
before do
sign_in(project.creator)
end
2016-06-02 11:05:42 +05:30
context 'when user is not a Project member neither a group member' do
2016-09-13 17:45:13 +05:30
it 'does not see the Project listed' do
2016-06-02 11:05:42 +05:30
get_forks
expect(assigns[:forks]).to be_blank
end
end
context 'when user is a member of the Project' do
2017-09-10 17:25:29 +05:30
before do
2018-03-17 18:26:18 +05:30
forked_project.add_developer(project.creator)
2017-09-10 17:25:29 +05:30
end
2016-06-02 11:05:42 +05:30
2016-09-13 17:45:13 +05:30
it 'sees the project listed' do
2016-06-02 11:05:42 +05:30
get_forks
expect(assigns[:forks]).to be_present
end
2019-12-04 20:38:33 +05:30
include_examples 'forks counts'
2016-06-02 11:05:42 +05:30
end
context 'when user is a member of the Group' do
2017-09-10 17:25:29 +05:30
before do
forked_project.group.add_developer(project.creator)
end
2016-06-02 11:05:42 +05:30
2016-09-13 17:45:13 +05:30
it 'sees the project listed' do
2016-06-02 11:05:42 +05:30
get_forks
expect(assigns[:forks]).to be_present
end
2019-12-04 20:38:33 +05:30
include_examples 'forks counts'
2016-06-02 11:05:42 +05:30
end
end
end
end
2017-08-17 22:00:37 +05:30
describe 'GET new' do
2020-03-13 15:44:24 +05:30
subject do
2017-08-17 22:00:37 +05:30
get :new,
2020-03-13 15:44:24 +05:30
params: {
namespace_id: project.namespace,
project_id: project
}
2017-08-17 22:00:37 +05:30
end
context 'when user is signed in' do
it 'responds with status 200' do
sign_in(user)
2020-03-13 15:44:24 +05:30
subject
2017-08-17 22:00:37 +05:30
2020-03-13 15:44:24 +05:30
expect(response).to have_gitlab_http_status(:ok)
2017-08-17 22:00:37 +05:30
end
end
context 'when user is not signed in' do
it 'redirects to the sign-in page' do
sign_out(user)
2020-03-13 15:44:24 +05:30
subject
2017-08-17 22:00:37 +05:30
expect(response).to redirect_to(new_user_session_path)
end
end
2020-03-13 15:44:24 +05:30
it_behaves_like 'forking disabled'
2017-08-17 22:00:37 +05:30
end
describe 'POST create' do
2020-03-13 15:44:24 +05:30
let(:params) do
{
namespace_id: project.namespace,
project_id: project,
namespace_key: user.namespace.id
}
end
subject do
post :create, params: params
2017-08-17 22:00:37 +05:30
end
context 'when user is signed in' do
2019-09-30 21:07:59 +05:30
before do
2017-08-17 22:00:37 +05:30
sign_in(user)
2019-09-30 21:07:59 +05:30
end
2017-08-17 22:00:37 +05:30
2019-09-30 21:07:59 +05:30
it 'responds with status 302' do
2020-03-13 15:44:24 +05:30
subject
2017-08-17 22:00:37 +05:30
2020-03-13 15:44:24 +05:30
expect(response).to have_gitlab_http_status(:found)
2017-08-17 22:00:37 +05:30
expect(response).to redirect_to(namespace_project_import_path(user.namespace, project))
end
2019-09-30 21:07:59 +05:30
2020-04-08 14:13:33 +05:30
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-03-13 15:44:24 +05:30
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
it 'passes continue params to the redirect' do
subject
2019-09-30 21:07:59 +05:30
2020-03-13 15:44:24 +05:30
expect(response).to have_gitlab_http_status(:found)
expect(response).to redirect_to(namespace_project_import_path(user.namespace, project, continue: continue_params))
end
2019-09-30 21:07:59 +05:30
end
2017-08-17 22:00:37 +05:30
end
context 'when user is not signed in' do
it 'redirects to the sign-in page' do
sign_out(user)
2020-03-13 15:44:24 +05:30
subject
2017-08-17 22:00:37 +05:30
expect(response).to redirect_to(new_user_session_path)
end
end
2020-03-13 15:44:24 +05:30
it_behaves_like 'forking disabled'
2017-08-17 22:00:37 +05:30
end
2016-06-02 11:05:42 +05:30
end