diff options
author | Angus MacArthur <amacarthur@blackberry.com> | 2013-05-02 15:30:13 -0400 |
---|---|---|
committer | Angus MacArthur <amacarthur@blackberry.com> | 2013-05-02 16:41:24 -0400 |
commit | de8df1be1a75cfde02a5a1d3f52a888b770c54e0 (patch) | |
tree | b5cbc003a547ac5a71b803293798995273434da3 /spec/contexts | |
parent | ae33fdf297e03866ecc6c31c5470dd5ad72d1328 (diff) | |
download | gitlab-ce-de8df1be1a75cfde02a5a1d3f52a888b770c54e0.tar.gz |
Fix bug for repeated fork requests
When asking to fork a project and a project with the same name
already exists (likely from a previous fork), the recovery from
the fork failure would inadvertantly delete the repo of the
existing destination project.
Diffstat (limited to 'spec/contexts')
-rw-r--r-- | spec/contexts/fork_context_spec.rb | 40 |
1 files changed, 28 insertions, 12 deletions
diff --git a/spec/contexts/fork_context_spec.rb b/spec/contexts/fork_context_spec.rb index 285590bdd84..ed51b0c3f8e 100644 --- a/spec/contexts/fork_context_spec.rb +++ b/spec/contexts/fork_context_spec.rb @@ -3,29 +3,45 @@ require 'spec_helper' describe Projects::ForkContext do describe :fork_by_user do before do - @from_user = create :user - @from_project = create(:project, creator_id: @from_user.id) - @to_user = create :user + @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) end context 'fork project' do - before do + + it "successfully creates project in the user namespace" do @to_project = fork_project(@from_project, @to_user) - end - it { @to_project.owner.should == @to_user } - it { @to_project.namespace.should == @to_user.namespace } + @to_project.owner.should == @to_user + @to_project.namespace.should == @to_user.namespace + end end context 'fork project failure' do - before do - #corrupt the project so the attempt to fork will fail - @from_project = create(:project, path: "empty") + + it "fails due to transaction failure" do + # make the mock gitlab-shell fail @to_project = fork_project(@from_project, @to_user, false) + + @to_project.errors.should_not be_empty + @to_project.errors[:base].should include("Fork transaction failed.") end - it {@to_project.errors.should_not be_empty} - it {@to_project.errors[:base].should include("Can't fork project. Please try again later") } + 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 end end |