Commit 3fd929fd authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Merge branch 'fork-star-bug' into 'master'

Fork star bug

Fix https://gitlab.com/gitlab-org/gitlab-ce/issues/523

See merge request !1039
parents 1a9b2a47 2e497d84
...@@ -7,7 +7,12 @@ module Projects ...@@ -7,7 +7,12 @@ module Projects
end end
def execute def execute
project = @from_project.dup project_params = {
visibility_level: @from_project.visibility_level,
description: @from_project.description,
}
project = Project.new(project_params)
project.name = @from_project.name project.name = @from_project.name
project.path = @from_project.path project.path = @from_project.path
project.namespace = current_user.namespace project.namespace = current_user.namespace
......
...@@ -5,44 +5,40 @@ describe Projects::ForkService do ...@@ -5,44 +5,40 @@ describe Projects::ForkService do
before do before do
@from_namespace = create(:namespace) @from_namespace = create(:namespace)
@from_user = create(:user, namespace: @from_namespace ) @from_user = create(:user, namespace: @from_namespace )
@from_project = create(:project, creator_id: @from_user.id, namespace: @from_namespace) @from_project = create(:project, creator_id: @from_user.id,
namespace: @from_namespace, star_count: 107,
description: 'wow such project')
@to_namespace = create(:namespace) @to_namespace = create(:namespace)
@to_user = create(:user, namespace: @to_namespace) @to_user = create(:user, namespace: @to_namespace)
end end
context 'fork project' do context 'fork project' do
describe "successfully creates project in the user namespace" do
let(:to_project) { fork_project(@from_project, @to_user) }
it "successfully creates project in the user namespace" do it { to_project.owner.should == @to_user }
@to_project = fork_project(@from_project, @to_user) it { to_project.namespace.should == @to_user.namespace }
it { to_project.star_count.should be_zero }
@to_project.owner.should == @to_user it { to_project.description.should == @from_project.description }
@to_project.namespace.should == @to_user.namespace
end end
end end
context 'fork project failure' do context 'fork project failure' do
it "fails due to transaction failure" do it "fails due to transaction failure" do
# make the mock gitlab-shell fail
@to_project = fork_project(@from_project, @to_user, false) @to_project = fork_project(@from_project, @to_user, false)
@to_project.errors.should_not be_empty @to_project.errors.should_not be_empty
@to_project.errors[:base].should include("Fork transaction failed.") @to_project.errors[:base].should include("Fork transaction failed.")
end end
end end
context 'project already exists' do context 'project already exists' do
it "should fail due to validation, not transaction failure" 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) @existing_project = create(:project, creator_id: @to_user.id, name: @from_project.name, namespace: @to_namespace)
@to_project = fork_project(@from_project, @to_user) @to_project = fork_project(@from_project, @to_user)
@existing_project.persisted?.should be_true @existing_project.persisted?.should be_true
@to_project.errors[:base].should include("Invalid fork destination") @to_project.errors[:base].should include("Invalid fork destination")
@to_project.errors[:base].should_not include("Fork transaction failed.") @to_project.errors[:base].should_not include("Fork transaction failed.")
end end
end end
end end
...@@ -53,5 +49,4 @@ describe Projects::ForkService do ...@@ -53,5 +49,4 @@ describe Projects::ForkService do
context.stub(gitlab_shell: shell) context.stub(gitlab_shell: shell)
context.execute context.execute
end end
end end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment