Prevent project stars duplication when fork project

Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
This commit is contained in:
Dmitriy Zaporozhets 2014-08-25 12:19:52 +03:00
parent 1a9b2a47a1
commit 2e497d8438
No known key found for this signature in database
GPG Key ID: 627C5F589F467F17
2 changed files with 15 additions and 15 deletions

View File

@ -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

View File

@ -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
context.stub(gitlab_shell: shell) context.stub(gitlab_shell: shell)
context.execute context.execute
end end
end end