diff options
author | Douwe Maan <douwe@gitlab.com> | 2017-06-20 21:20:00 +0300 |
---|---|---|
committer | Douwe Maan <douwe@gitlab.com> | 2017-06-20 21:20:00 +0300 |
commit | 780adff549a48b6c4d0ba77725b4027b0616178f (patch) | |
tree | 53fd06bf31fa4adef8f2cbe7c826f9d951958a7e /spec/services/projects/transfer_service_spec.rb | |
parent | c0dd3ef0e01c39e135c96188694a6560d050bf0a (diff) | |
parent | 6db1a28016899170e947b045c2769639b479d72a (diff) |
Merge branch '30213-project-transfer-move-rollback' into 'master'
Rollback project folder move after error in Projects::TransferService
Closes #30213
See merge request !11877
Diffstat (limited to 'spec/services/projects/transfer_service_spec.rb')
-rw-r--r-- | spec/services/projects/transfer_service_spec.rb | 61 |
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 5d2f4cf17fb..63bd0353d50 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) |