diff options
Diffstat (limited to 'spec/services/projects/destroy_service_spec.rb')
-rw-r--r-- | spec/services/projects/destroy_service_spec.rb | 69 |
1 files changed, 54 insertions, 15 deletions
diff --git a/spec/services/projects/destroy_service_spec.rb b/spec/services/projects/destroy_service_spec.rb index ff2de45661f..0689a65c2f4 100644 --- a/spec/services/projects/destroy_service_spec.rb +++ b/spec/services/projects/destroy_service_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Projects::DestroyService, :aggregate_failures, :event_store_publisher do +RSpec.describe Projects::DestroyService, :aggregate_failures, :event_store_publisher, feature_category: :projects do include ProjectForksHelper include BatchDestroyDependentAssociationsHelper @@ -151,10 +151,22 @@ RSpec.describe Projects::DestroyService, :aggregate_failures, :event_store_publi it_behaves_like 'deleting the project' - it 'invalidates personal_project_count cache' do - expect(user).to receive(:invalidate_personal_projects_count) + context 'personal projects count cache' do + context 'when the executor is the creator of the project itself' do + it 'invalidates personal_project_count cache of the the owner of the personal namespace' do + expect(user).to receive(:invalidate_personal_projects_count) - destroy_project(project, user, {}) + destroy_project(project, user, {}) + end + end + + context 'when the executor is the instance administrator', :enable_admin_mode do + it 'invalidates personal_project_count cache of the the owner of the personal namespace' do + expect(user).to receive(:invalidate_personal_projects_count) + + destroy_project(project, create(:admin), {}) + end + end end context 'with running pipelines' do @@ -331,18 +343,30 @@ RSpec.describe Projects::DestroyService, :aggregate_failures, :event_store_publi end context 'when image repository deletion succeeds' do - it 'removes tags' do - expect_any_instance_of(Projects::ContainerRepository::CleanupTagsService) - .to receive(:execute).and_return({ status: :success }) + it 'returns true' do + expect_next_instance_of(Projects::ContainerRepository::CleanupTagsService) do |instance| + expect(instance).to receive(:execute).and_return(status: :success) + end - destroy_project(project, user) + expect(destroy_project(project, user)).to be true + end + end + + context 'when image repository deletion raises an error' do + it 'returns false' do + expect_next_instance_of(Projects::ContainerRepository::CleanupTagsService) do |service| + expect(service).to receive(:execute).and_raise(RuntimeError) + end + + expect(destroy_project(project, user)).to be false end end context 'when image repository deletion fails' do - it 'raises an exception' do - expect_any_instance_of(Projects::ContainerRepository::CleanupTagsService) - .to receive(:execute).and_raise(RuntimeError) + it 'returns false' do + expect_next_instance_of(Projects::ContainerRepository::DestroyService) do |service| + expect(service).to receive(:execute).and_return({ status: :error }) + end expect(destroy_project(project, user)).to be false end @@ -369,8 +393,9 @@ RSpec.describe Projects::DestroyService, :aggregate_failures, :event_store_publi context 'when image repository tags deletion succeeds' do it 'removes tags' do - expect_any_instance_of(ContainerRepository) - .to receive(:delete_tags!).and_return(true) + expect_next_instance_of(Projects::ContainerRepository::DestroyService) do |service| + expect(service).to receive(:execute).and_return({ status: :sucess }) + end destroy_project(project, user) end @@ -378,13 +403,27 @@ RSpec.describe Projects::DestroyService, :aggregate_failures, :event_store_publi context 'when image repository tags deletion fails' do it 'raises an exception' do - expect_any_instance_of(ContainerRepository) - .to receive(:delete_tags!).and_return(false) + expect_next_instance_of(Projects::ContainerRepository::DestroyService) do |service| + expect(service).to receive(:execute).and_return({ status: :error }) + end expect(destroy_project(project, user)).to be false end end end + + context 'when there are no tags for legacy root repository' do + before do + stub_container_registry_tags(repository: project.full_path, + tags: []) + end + + it 'does not try to destroy the repository' do + expect(Projects::ContainerRepository::DestroyService).not_to receive(:new) + + destroy_project(project, user) + end + end end context 'for a forked project with LFS objects' do |