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

212 lines
5.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
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
def get_new
get :new,
2019-02-15 15:39:39 +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)
get_new
2018-03-17 18:26:18 +05:30
expect(response).to have_gitlab_http_status(200)
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)
get_new
expect(response).to redirect_to(new_user_session_path)
end
end
end
describe 'POST create' do
2019-09-30 21:07:59 +05:30
def post_create(params = {})
2017-08-17 22:00:37 +05:30
post :create,
2019-02-15 15:39:39 +05:30
params: {
namespace_id: project.namespace,
project_id: project,
namespace_key: user.namespace.id
2019-09-30 21:07:59 +05:30
}.merge(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
2017-08-17 22:00:37 +05:30
post_create
2018-03-17 18:26:18 +05:30
expect(response).to have_gitlab_http_status(302)
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
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
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)
post_create
expect(response).to redirect_to(new_user_session_path)
end
end
end
2016-06-02 11:05:42 +05:30
end