diff options
author | Tiago Botelho <tiagonbotelho@hotmail.com> | 2017-06-29 14:43:01 +0300 |
---|---|---|
committer | Tiago Botelho <tiagonbotelho@hotmail.com> | 2017-07-20 11:59:56 +0300 |
commit | 3491b19a4e67a9f439c12afac45ef38f3fce0ef5 (patch) | |
tree | a548a111e88c046315e0a2633aba5656be7603ba /spec | |
parent | f0e4e3993b1f5a21ab61aaff95f73ac4e5b88ad3 (diff) |
Add specs for ProjectDestroyWorker
Diffstat (limited to 'spec')
-rw-r--r-- | spec/features/projects/show_project_spec.rb | 30 | ||||
-rw-r--r-- | spec/workers/project_destroy_worker_spec.rb | 21 |
2 files changed, 47 insertions, 4 deletions
diff --git a/spec/features/projects/show_project_spec.rb b/spec/features/projects/show_project_spec.rb new file mode 100644 index 00000000000..5aa0d8f0026 --- /dev/null +++ b/spec/features/projects/show_project_spec.rb @@ -0,0 +1,30 @@ +require 'spec_helper' + +describe 'Project show page', feature: true do + context 'when project pending delete' do + let(:project) { create(:project, :empty_repo, pending_delete: true) } + let(:worker) { ProjectDestroyWorker.new } + + before do + sign_in(project.owner) + end + + it 'shows flash error if deletion for project fails' do + error_message = "some error message" + project.update_attributes(delete_error: error_message, pending_delete: false) + + visit namespace_project_path(project.namespace, project) + + expect(page).to have_selector('.project-deletion-failed-message') + expect(page).to have_content("This project was scheduled for deletion, but failed with the following message: #{error_message}") + end + + it 'renders 404 if project was successfully deleted' do + worker.perform(project.id, project.owner.id, {}) + + visit namespace_project_path(project.namespace, project) + + expect(page).to have_http_status(404) + end + end +end diff --git a/spec/workers/project_destroy_worker_spec.rb b/spec/workers/project_destroy_worker_spec.rb index 3d135f40c1f..29f0295de42 100644 --- a/spec/workers/project_destroy_worker_spec.rb +++ b/spec/workers/project_destroy_worker_spec.rb @@ -1,24 +1,37 @@ require 'spec_helper' describe ProjectDestroyWorker do - let(:project) { create(:project, :repository) } + let(:project) { create(:project, :repository, pending_delete: true) } let(:path) { project.repository.path_to_repo } subject { described_class.new } - describe "#perform" do - it "deletes the project" do + describe '#perform' do + it 'deletes the project' do subject.perform(project.id, project.owner.id, {}) expect(Project.all).not_to include(project) expect(Dir.exist?(path)).to be_falsey end - it "deletes the project but skips repo deletion" do + it 'deletes the project but skips repo deletion' do subject.perform(project.id, project.owner.id, { "skip_repo" => true }) expect(Project.all).not_to include(project) expect(Dir.exist?(path)).to be_truthy end + + describe 'when StandardError is raised' do + it 'reverts pending_delete attribute with a error message' do + allow_any_instance_of(::Projects::DestroyService).to receive(:execute).and_raise(StandardError, "some error message") + + expect do + subject.perform(project.id, project.owner.id, {}) + end.to change { project.reload.pending_delete }.from(true).to(false) + + expect(Project.all).to include(project) + expect(project.delete_error).to eq("some error message") + end + end end end |