From e2d2bbccbd516dc4869df723698929d8ded74669 Mon Sep 17 00:00:00 2001 From: Allison Browne <abrowne@gitlab.com> Date: Wed, 7 Jul 2021 08:59:53 -0400 Subject: [PATCH] Fix delete pipeline feature spec --- app/services/ci/destroy_pipeline_service.rb | 2 +- .../projects/pipelines/pipeline_spec.rb | 46 ++++++++++++------- 2 files changed, 31 insertions(+), 17 deletions(-) diff --git a/app/services/ci/destroy_pipeline_service.rb b/app/services/ci/destroy_pipeline_service.rb index 9ebd1a4462a..494fcb23a06 100644 --- a/app/services/ci/destroy_pipeline_service.rb +++ b/app/services/ci/destroy_pipeline_service.rb @@ -9,7 +9,7 @@ module Ci pipeline.cancel_running if pipeline.cancelable? && ::Feature.enabled?(:cancel_pipelines_prior_to_destroy, default_enabled: :yaml) - pipeline.destroy! + pipeline.reset.destroy! ServiceResponse.success(message: 'Pipeline not found') rescue ActiveRecord::RecordNotFound diff --git a/spec/features/projects/pipelines/pipeline_spec.rb b/spec/features/projects/pipelines/pipeline_spec.rb index 70dc0bd04e8..c5f5d9dcc70 100644 --- a/spec/features/projects/pipelines/pipeline_spec.rb +++ b/spec/features/projects/pipelines/pipeline_spec.rb @@ -434,30 +434,44 @@ RSpec.describe 'Pipeline', :js do end end - context 'deleting pipeline' do - context 'when user can not delete' do - before do - visit_pipeline + shared_context 'delete pipeline' do + context 'deleting pipeline' do + context 'when user can not delete' do + before do + visit_pipeline + end + + it { expect(page).not_to have_button('Delete') } end - it { expect(page).not_to have_button('Delete') } - end + context 'when deleting' do + before do + group.add_owner(user) - context 'when deleting' do - before do - group.add_owner(user) + visit_pipeline - visit_pipeline + click_button 'Delete' + click_button 'Delete pipeline' + end - click_button 'Delete' - click_button 'Delete pipeline' + it 'redirects to pipeline overview page', :sidekiq_inline do + expect(page).to have_content('The pipeline has been deleted') + expect(current_path).to eq(project_pipelines_path(project)) + end end + end + end - it 'redirects to pipeline overview page', :sidekiq_might_not_need_inline do - expect(page).to have_content('The pipeline has been deleted') - expect(current_path).to eq(project_pipelines_path(project)) - end + context 'when cancel_pipelines_prior_to_destroy is enabled' do + include_context 'delete pipeline' + end + + context 'when cancel_pipelines_prior_to_destroy is disabled' do + before do + stub_feature_flags(cancel_pipelines_prior_to_destroy: false) end + + include_context 'delete pipeline' end context 'when pipeline ref does not exist in repository anymore' do -- 2.30.9