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

149 lines
3.2 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) }
2016-06-02 11:05:42 +05:30
let(:forked_project) { Projects::ForkService.new(project, user).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
def get_forks
get :index,
2019-02-15 15:39:39 +05:30
params: {
namespace_id: project.namespace,
project_id: project
}
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
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
2016-09-13 17:45:13 +05:30
it 'is not be visible for non logged in users' do
2016-06-02 11:05:42 +05:30
get_forks
expect(assigns[:forks]).to be_blank
end
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
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
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
def post_create
post :create,
2019-02-15 15:39:39 +05:30
params: {
namespace_id: project.namespace,
project_id: project,
namespace_key: user.namespace.id
}
2017-08-17 22:00:37 +05:30
end
context 'when user is signed in' do
it 'responds with status 302' do
sign_in(user)
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
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