summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorJames Edwards-Jones <jedwardsjones@gitlab.com>2017-06-02 14:44:59 +0100
committerJames Edwards-Jones <jedwardsjones@gitlab.com>2017-06-20 17:35:33 +0100
commit6db1a28016899170e947b045c2769639b479d72a (patch)
tree15d7f2d2c2cd8844cbcb0dc96ae43ed18f837ae5 /spec
parentf07aee72bef4604312e11a43fce3a47865bce100 (diff)
downloadgitlab-ce-6db1a28016899170e947b045c2769639b479d72a.tar.gz
Rollback project folder move after error in Projects::TransferService30213-project-transfer-move-rollback
Diffstat (limited to 'spec')
-rw-r--r--spec/services/projects/transfer_service_spec.rb61
1 files changed, 61 insertions, 0 deletions
diff --git a/spec/services/projects/transfer_service_spec.rb b/spec/services/projects/transfer_service_spec.rb
index b957517c715..feb14b0e2bc 100644
--- a/spec/services/projects/transfer_service_spec.rb
+++ b/spec/services/projects/transfer_service_spec.rb
@@ -19,6 +19,67 @@ describe Projects::TransferService, services: true do
it { expect(project.namespace).to eq(group) }
end
+ context 'when transfer succeeds' do
+ before do
+ group.add_owner(user)
+ end
+
+ it 'sends notifications' do
+ expect_any_instance_of(NotificationService).to receive(:project_was_moved)
+
+ transfer_project(project, user, group)
+ end
+
+ it 'executes system hooks' do
+ expect_any_instance_of(Projects::TransferService).to receive(:execute_system_hooks)
+
+ transfer_project(project, user, group)
+ end
+ end
+
+ context 'when transfer fails' do
+ let!(:original_path) { project_path(project) }
+
+ def attempt_project_transfer
+ expect do
+ transfer_project(project, user, group)
+ end.to raise_error(ActiveRecord::ActiveRecordError)
+ end
+
+ before do
+ group.add_owner(user)
+
+ expect_any_instance_of(Labels::TransferService).to receive(:execute).and_raise(ActiveRecord::StatementInvalid, "PG ERROR")
+ end
+
+ def project_path(project)
+ File.join(project.repository_storage_path, "#{project.path_with_namespace}.git")
+ end
+
+ def current_path
+ project_path(project)
+ end
+
+ it 'rolls back repo location' do
+ attempt_project_transfer
+
+ expect(Dir.exist?(original_path)).to be_truthy
+ expect(original_path).to eq current_path
+ end
+
+ it "doesn't send move notifications" do
+ expect_any_instance_of(NotificationService).not_to receive(:project_was_moved)
+
+ attempt_project_transfer
+ end
+
+ it "doesn't run system hooks" do
+ expect_any_instance_of(Projects::TransferService).not_to receive(:execute_system_hooks)
+
+ attempt_project_transfer
+ end
+ end
+
context 'namespace -> no namespace' do
before do
@result = transfer_project(project, user, nil)