From 56fa7e7cd6f4c091c875103b2380f7df0bbf8c50 Mon Sep 17 00:00:00 2001 From: Pierre de La Morinerie Date: Tue, 31 Aug 2021 22:08:51 +0000 Subject: [PATCH] app: move destroy to NewAdministrateur::ProceduresController The code was already moved; only the route and tests were not. --- config/routes.rb | 2 +- .../admin/procedures_controller_spec.rb | 65 ------------------- .../procedures_controller_spec.rb | 65 +++++++++++++++++++ 3 files changed, 66 insertions(+), 66 deletions(-) diff --git a/config/routes.rb b/config/routes.rb index bbbca2581..81207b9a7 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -387,7 +387,7 @@ Rails.application.routes.draw do # namespace :admin, module: 'new_administrateur' do - resources :procedures, except: [:destroy] do + resources :procedures do collection do get 'new_from_existing' end diff --git a/spec/controllers/admin/procedures_controller_spec.rb b/spec/controllers/admin/procedures_controller_spec.rb index 7958f1787..fa526226e 100644 --- a/spec/controllers/admin/procedures_controller_spec.rb +++ b/spec/controllers/admin/procedures_controller_spec.rb @@ -35,71 +35,6 @@ describe Admin::ProceduresController, type: :controller do sign_in(admin.user) end - describe 'DELETE #destroy' do - let(:procedure_draft) { create(:procedure, administrateurs: [admin]) } - let(:procedure_published) { create(:procedure, :published, administrateurs: [admin]) } - let(:procedure_closed) { create(:procedure, :closed, administrateurs: [admin]) } - let(:procedure) { dossier.procedure } - - subject { delete :destroy, params: { id: procedure } } - - context 'when the procedure is a brouillon' do - let(:dossier) { create(:dossier, :en_instruction, procedure: procedure_draft) } - - before { subject } - - it 'discard the procedure' do - expect(procedure.reload.discarded?).to be_truthy - end - - it 'deletes associated dossiers' do - expect(procedure.dossiers.with_discarded.count).to eq(0) - end - - it 'redirects to the procedure drafts page' do - expect(response).to redirect_to admin_procedures_draft_path - expect(flash[:notice]).to be_present - end - end - - context 'when procedure is published' do - let(:dossier) { create(:dossier, :en_instruction, procedure: procedure_published) } - - before { subject } - - it { expect(response.status).to eq 403 } - - context 'when dossier is en_construction' do - let(:dossier) { create(:dossier, :en_construction, procedure: procedure_published) } - - it { expect(procedure.reload.close?).to be_truthy } - it { expect(procedure.reload.discarded?).to be_truthy } - it { expect(dossier.reload.discarded?).to be_truthy } - end - end - - context 'when procedure is closed' do - let(:dossier) { create(:dossier, :en_instruction, procedure: procedure_closed) } - - before { subject } - - it { expect(response.status).to eq 403 } - - context 'when dossier is en_construction' do - let(:dossier) { create(:dossier, :en_construction, procedure: procedure_published) } - - it { expect(procedure.reload.discarded?).to be_truthy } - it { expect(dossier.reload.discarded?).to be_truthy } - end - end - - context "when administrateur does not own the procedure" do - let(:dossier) { create(:dossier) } - - it { expect { subject }.to raise_error(ActiveRecord::RecordNotFound) } - end - end - describe 'PUT #archive' do let(:procedure) { create(:procedure, :published, administrateur: admin, lien_site_web: lien_site_web) } diff --git a/spec/controllers/new_administrateur/procedures_controller_spec.rb b/spec/controllers/new_administrateur/procedures_controller_spec.rb index eec73170c..a039c9133 100644 --- a/spec/controllers/new_administrateur/procedures_controller_spec.rb +++ b/spec/controllers/new_administrateur/procedures_controller_spec.rb @@ -294,6 +294,71 @@ describe NewAdministrateur::ProceduresController, type: :controller do end end + describe 'DELETE #destroy' do + let(:procedure_draft) { create(:procedure, administrateurs: [admin]) } + let(:procedure_published) { create(:procedure, :published, administrateurs: [admin]) } + let(:procedure_closed) { create(:procedure, :closed, administrateurs: [admin]) } + let(:procedure) { dossier.procedure } + + subject { delete :destroy, params: { id: procedure } } + + context 'when the procedure is a brouillon' do + let(:dossier) { create(:dossier, :en_instruction, procedure: procedure_draft) } + + before { subject } + + it 'discard the procedure' do + expect(procedure.reload.discarded?).to be_truthy + end + + it 'deletes associated dossiers' do + expect(procedure.dossiers.with_discarded.count).to eq(0) + end + + it 'redirects to the procedure drafts page' do + expect(response).to redirect_to admin_procedures_draft_path + expect(flash[:notice]).to be_present + end + end + + context 'when procedure is published' do + let(:dossier) { create(:dossier, :en_instruction, procedure: procedure_published) } + + before { subject } + + it { expect(response.status).to eq 403 } + + context 'when dossier is en_construction' do + let(:dossier) { create(:dossier, :en_construction, procedure: procedure_published) } + + it { expect(procedure.reload.close?).to be_truthy } + it { expect(procedure.reload.discarded?).to be_truthy } + it { expect(dossier.reload.discarded?).to be_truthy } + end + end + + context 'when procedure is closed' do + let(:dossier) { create(:dossier, :en_instruction, procedure: procedure_closed) } + + before { subject } + + it { expect(response.status).to eq 403 } + + context 'when dossier is en_construction' do + let(:dossier) { create(:dossier, :en_construction, procedure: procedure_published) } + + it { expect(procedure.reload.discarded?).to be_truthy } + it { expect(dossier.reload.discarded?).to be_truthy } + end + end + + context "when administrateur does not own the procedure" do + let(:dossier) { create(:dossier) } + + it { expect { subject }.to raise_error(ActiveRecord::RecordNotFound) } + end + end + describe 'PATCH #monavis' do let!(:procedure) { create(:procedure, administrateur: admin) } let(:procedure_params) {