diff options
Diffstat (limited to 'spec/services/projects/destroy_service_spec.rb')
-rw-r--r-- | spec/services/projects/destroy_service_spec.rb | 62 |
1 files changed, 45 insertions, 17 deletions
diff --git a/spec/services/projects/destroy_service_spec.rb b/spec/services/projects/destroy_service_spec.rb index 90771825f5c..b1e10f4562e 100644 --- a/spec/services/projects/destroy_service_spec.rb +++ b/spec/services/projects/destroy_service_spec.rb @@ -2,19 +2,34 @@ require 'spec_helper' describe Projects::DestroyService, services: true do let!(:user) { create(:user) } - let!(:project) { create(:project, namespace: user.namespace) } + let!(:project) { create(:project, :repository, namespace: user.namespace) } let!(:path) { project.repository.path_to_repo } let!(:remove_path) { path.sub(/\.git\Z/, "+#{project.id}+deleted.git") } let!(:async) { false } # execute or async_execute shared_examples 'deleting the project' do it 'deletes the project' do - expect(Project.all).not_to include(project) + expect(Project.unscoped.all).not_to include(project) expect(Dir.exist?(path)).to be_falsey expect(Dir.exist?(remove_path)).to be_falsey end end + shared_examples 'deleting the project with pipeline and build' do + context 'with pipeline and build' do # which has optimistic locking + let!(:pipeline) { create(:ci_pipeline, project: project) } + let!(:build) { create(:ci_build, :artifacts, pipeline: pipeline) } + + before do + perform_enqueued_jobs do + destroy_project(project, user, {}) + end + end + + it_behaves_like 'deleting the project' + end + end + context 'Sidekiq inline' do before do # Run sidekiq immediatly to check that renamed repository will be removed @@ -35,30 +50,43 @@ describe Projects::DestroyService, services: true do it { expect(Dir.exist?(remove_path)).to be_truthy } end - context 'async delete of project with private issue visibility' do - let!(:async) { true } - + context 'when flushing caches fail' do before do - project.project_feature.update_attribute("issues_access_level", ProjectFeature::PRIVATE) - # Run sidekiq immediately to check that renamed repository will be removed - Sidekiq::Testing.inline! { destroy_project(project, user, {}) } + new_user = create(:user) + project.team.add_user(new_user, Gitlab::Access::DEVELOPER) + allow_any_instance_of(Projects::DestroyService).to receive(:flush_caches).and_raise(Redis::CannotConnectError) end - it_behaves_like 'deleting the project' - end + it 'keeps project team intact upon an error' do + Sidekiq::Testing.inline! do + begin + destroy_project(project, user, {}) + rescue Redis::CannotConnectError + end + end - context 'delete with pipeline' do # which has optimistic locking - let!(:pipeline) { create(:ci_pipeline, project: project) } + expect(project.team.members.count).to eq 1 + end + end - before do - expect(project).to receive(:destroy!).and_call_original + context 'with async_execute' do + let(:async) { true } - perform_enqueued_jobs do - destroy_project(project, user, {}) + context 'async delete of project with private issue visibility' do + before do + project.project_feature.update_attribute("issues_access_level", ProjectFeature::PRIVATE) + # Run sidekiq immediately to check that renamed repository will be removed + Sidekiq::Testing.inline! { destroy_project(project, user, {}) } end + + it_behaves_like 'deleting the project' end - it_behaves_like 'deleting the project' + it_behaves_like 'deleting the project with pipeline and build' + end + + context 'with execute' do + it_behaves_like 'deleting the project with pipeline and build' end context 'container registry' do |