summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorAngus MacArthur <amacarthur@blackberry.com>2013-03-19 11:37:50 -0400
committerAngus MacArthur <amacarthur@blackberry.com>2013-04-15 01:54:52 -0400
commitae33fdf297e03866ecc6c31c5470dd5ad72d1328 (patch)
tree6b3b8fb315fbc3e0b6ebf6dbb527abe9bcb3d245 /spec
parente996c52636f46b193b5ff7291e9b835c317e5438 (diff)
downloadgitlab-ce-ae33fdf297e03866ecc6c31c5470dd5ad72d1328.tar.gz
updated fork feature to use gitlab-shell for v5 of gitlab
Diffstat (limited to 'spec')
-rw-r--r--spec/contexts/fork_context_spec.rb41
-rw-r--r--spec/factories/forked_project_links.rb8
-rw-r--r--spec/lib/gitlab/backend/shell_spec.rb1
-rw-r--r--spec/models/forked_project_link_spec.rb56
-rw-r--r--spec/models/project_spec.rb1
-rw-r--r--spec/routing/project_routing_spec.rb5
6 files changed, 112 insertions, 0 deletions
diff --git a/spec/contexts/fork_context_spec.rb b/spec/contexts/fork_context_spec.rb
new file mode 100644
index 00000000000..285590bdd84
--- /dev/null
+++ b/spec/contexts/fork_context_spec.rb
@@ -0,0 +1,41 @@
+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
+ end
+
+ context 'fork project' do
+ before 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 }
+ end
+
+ context 'fork project failure' do
+ before do
+ #corrupt the project so the attempt to fork will fail
+ @from_project = create(:project, path: "empty")
+ @to_project = fork_project(@from_project, @to_user, false)
+ 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
+ end
+
+ def fork_project(from_project, user, fork_success = true)
+ context = Projects::ForkContext.new(from_project, user)
+ shell = mock("gitlab_shell")
+ shell.stub(fork_repository: fork_success)
+ context.stub(gitlab_shell: shell)
+ context.execute
+ end
+
+end
diff --git a/spec/factories/forked_project_links.rb b/spec/factories/forked_project_links.rb
new file mode 100644
index 00000000000..64bcdf09429
--- /dev/null
+++ b/spec/factories/forked_project_links.rb
@@ -0,0 +1,8 @@
+# Read about factories at https://github.com/thoughtbot/factory_girl
+
+FactoryGirl.define do
+ factory :forked_project_link do
+ association :forked_to_project, factory: :project
+ association :forked_from_project, factory: :project
+ end
+end
diff --git a/spec/lib/gitlab/backend/shell_spec.rb b/spec/lib/gitlab/backend/shell_spec.rb
index 3c04f4bbeb6..f00ec0fa401 100644
--- a/spec/lib/gitlab/backend/shell_spec.rb
+++ b/spec/lib/gitlab/backend/shell_spec.rb
@@ -12,6 +12,7 @@ describe Gitlab::Shell do
it { should respond_to :remove_key }
it { should respond_to :add_repository }
it { should respond_to :remove_repository }
+ it { should respond_to :fork_repository }
it { gitlab_shell.url_to_repo('diaspora').should == Gitlab.config.gitlab_shell.ssh_path_prefix + "diaspora.git" }
end
diff --git a/spec/models/forked_project_link_spec.rb b/spec/models/forked_project_link_spec.rb
new file mode 100644
index 00000000000..c362b21f088
--- /dev/null
+++ b/spec/models/forked_project_link_spec.rb
@@ -0,0 +1,56 @@
+require 'spec_helper'
+
+describe ForkedProjectLink, "add link on fork" do
+ let(:project_from) {create(:project)}
+ let(:namespace) {create(:namespace)}
+ let(:user) {create(:user, namespace: namespace)}
+
+ before do
+ @project_to = fork_project(project_from, user)
+ end
+
+ it "project_to should know it is forked" do
+ @project_to.forked?.should be_true
+ end
+
+ it "project should know who it is forked from" do
+ @project_to.forked_from_project.should == project_from
+ end
+end
+
+describe :forked_from_project do
+ let(:forked_project_link) {build(:forked_project_link)}
+ let(:project_from) {create(:project)}
+ let(:project_to) {create(:project, forked_project_link: forked_project_link)}
+
+
+ before :each do
+ forked_project_link.forked_from_project = project_from
+ forked_project_link.forked_to_project = project_to
+ forked_project_link.save!
+ end
+
+
+ it "project_to should know it is forked" do
+ project_to.forked?.should be_true
+ end
+
+ it "project_from should not be forked" do
+ project_from.forked?.should be_false
+ end
+
+ it "project_to.destroy should destroy fork_link" do
+ forked_project_link.should_receive(:destroy)
+ project_to.destroy
+ end
+
+end
+
+def fork_project(from_project, user)
+ context = Projects::ForkContext.new(from_project, user)
+ shell = mock("gitlab_shell")
+ shell.stub(fork_repository: true)
+ context.stub(gitlab_shell: shell)
+ context.execute
+end
+
diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb
index fedf17b1ba0..b7eb7391072 100644
--- a/spec/models/project_spec.rb
+++ b/spec/models/project_spec.rb
@@ -40,6 +40,7 @@ describe Project do
it { should have_many(:deploy_keys).dependent(:destroy) }
it { should have_many(:hooks).dependent(:destroy) }
it { should have_many(:protected_branches).dependent(:destroy) }
+ it { should have_one(:forked_project_link).dependent(:destroy) }
end
describe "Mass assignment" do
diff --git a/spec/routing/project_routing_spec.rb b/spec/routing/project_routing_spec.rb
index 064177f8f21..dd4fb54af69 100644
--- a/spec/routing/project_routing_spec.rb
+++ b/spec/routing/project_routing_spec.rb
@@ -55,6 +55,7 @@ end
# projects POST /projects(.:format) projects#create
# new_project GET /projects/new(.:format) projects#new
+# fork_project POST /:id/fork(.:format) projects#fork
# wall_project GET /:id/wall(.:format) projects#wall
# files_project GET /:id/files(.:format) projects#files
# edit_project GET /:id/edit(.:format) projects#edit
@@ -70,6 +71,10 @@ describe ProjectsController, "routing" do
get("/projects/new").should route_to('projects#new')
end
+ it "to #fork" do
+ post("/gitlabhq/fork").should route_to('projects#fork', id: 'gitlabhq')
+ end
+
it "to #wall" do
get("/gitlabhq/wall").should route_to('walls#show', project_id: 'gitlabhq')
end