app: move destroy to NewAdministrateur::ProceduresController
The code was already moved; only the route and tests were not.
This commit is contained in:
parent
3e83ad454f
commit
56fa7e7cd6
3 changed files with 66 additions and 66 deletions
|
@ -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
|
||||
|
|
|
@ -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) }
|
||||
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Reference in a new issue