2013-03-19 11:37:50 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2014-01-16 13:29:18 -05:00
|
|
|
describe Projects::ForkService do
|
2013-03-19 11:37:50 -04:00
|
|
|
describe :fork_by_user do
|
|
|
|
before do
|
2013-05-02 15:30:13 -04:00
|
|
|
@from_namespace = create(:namespace)
|
|
|
|
@from_user = create(:user, namespace: @from_namespace )
|
|
|
|
@from_project = create(:project, creator_id: @from_user.id, namespace: @from_namespace)
|
|
|
|
@to_namespace = create(:namespace)
|
|
|
|
@to_user = create(:user, namespace: @to_namespace)
|
2013-03-19 11:37:50 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'fork project' do
|
2013-05-02 15:30:13 -04:00
|
|
|
|
|
|
|
it "successfully creates project in the user namespace" do
|
2013-03-19 11:37:50 -04:00
|
|
|
@to_project = fork_project(@from_project, @to_user)
|
|
|
|
|
2013-05-02 15:30:13 -04:00
|
|
|
@to_project.owner.should == @to_user
|
|
|
|
@to_project.namespace.should == @to_user.namespace
|
|
|
|
end
|
2013-03-19 11:37:50 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'fork project failure' do
|
2013-05-02 15:30:13 -04:00
|
|
|
|
|
|
|
it "fails due to transaction failure" do
|
|
|
|
# make the mock gitlab-shell fail
|
2013-03-19 11:37:50 -04:00
|
|
|
@to_project = fork_project(@from_project, @to_user, false)
|
2013-05-02 15:30:13 -04:00
|
|
|
|
|
|
|
@to_project.errors.should_not be_empty
|
|
|
|
@to_project.errors[:base].should include("Fork transaction failed.")
|
2013-03-19 11:37:50 -04:00
|
|
|
end
|
|
|
|
|
2013-05-02 15:30:13 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'project already exists' do
|
|
|
|
|
|
|
|
it "should fail due to validation, not transaction failure" do
|
|
|
|
@existing_project = create(:project, creator_id: @to_user.id, name: @from_project.name, namespace: @to_namespace)
|
|
|
|
@to_project = fork_project(@from_project, @to_user)
|
|
|
|
|
|
|
|
@existing_project.persisted?.should be_true
|
|
|
|
@to_project.errors[:base].should include("Invalid fork destination")
|
|
|
|
@to_project.errors[:base].should_not include("Fork transaction failed.")
|
|
|
|
end
|
2013-03-19 11:37:50 -04:00
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def fork_project(from_project, user, fork_success = true)
|
2014-01-16 13:29:18 -05:00
|
|
|
context = Projects::ForkService.new(from_project, user)
|
2013-12-14 08:43:48 -05:00
|
|
|
shell = double("gitlab_shell")
|
2013-03-19 11:37:50 -04:00
|
|
|
shell.stub(fork_repository: fork_success)
|
|
|
|
context.stub(gitlab_shell: shell)
|
|
|
|
context.execute
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|