Revert "ProcedureController: remove unused destroy method" (Sentry : #2149)
This reverts commit 6ca6669144
.
This commit is contained in:
parent
5c91ed4b46
commit
142f01d1bb
2 changed files with 59 additions and 0 deletions
|
@ -51,6 +51,17 @@ class Admin::ProceduresController < AdminController
|
||||||
redirect_to admin_procedures_draft_path
|
redirect_to admin_procedures_draft_path
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def destroy
|
||||||
|
procedure = current_administrateur.procedures.find(params[:id])
|
||||||
|
|
||||||
|
return render json: {}, status: 401 if procedure.publiee_ou_archivee?
|
||||||
|
|
||||||
|
procedure.destroy
|
||||||
|
|
||||||
|
flash.notice = 'Procédure supprimée'
|
||||||
|
redirect_to admin_procedures_draft_path
|
||||||
|
end
|
||||||
|
|
||||||
def new
|
def new
|
||||||
@procedure ||= Procedure.new
|
@procedure ||= Procedure.new
|
||||||
@procedure.module_api_carto ||= ModuleAPICarto.new
|
@procedure.module_api_carto ||= ModuleAPICarto.new
|
||||||
|
|
|
@ -54,6 +54,54 @@ describe Admin::ProceduresController, type: :controller do
|
||||||
it { expect(response.status).to eq(200) }
|
it { expect(response.status).to eq(200) }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe 'DELETE #destroy' do
|
||||||
|
let(:procedure_draft) { create :procedure, administrateur: admin, published_at: nil, archived_at: nil }
|
||||||
|
let(:procedure_published) { create :procedure, administrateur: admin, published_at: Time.now, archived_at: nil }
|
||||||
|
let(:procedure_archived) { create :procedure, administrateur: admin, published_at: nil, archived_at: Time.now }
|
||||||
|
|
||||||
|
subject { delete :destroy, params: {id: procedure.id} }
|
||||||
|
|
||||||
|
context 'when procedure is draft' do
|
||||||
|
let!(:procedure) { procedure_draft }
|
||||||
|
|
||||||
|
describe 'tech params' do
|
||||||
|
before do
|
||||||
|
subject
|
||||||
|
end
|
||||||
|
|
||||||
|
it { expect(subject.status).to eq 302 }
|
||||||
|
it { expect(flash[:notice]).to be_present }
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'destroy procedure is call' do
|
||||||
|
expect_any_instance_of(Procedure).to receive(:destroy)
|
||||||
|
subject
|
||||||
|
end
|
||||||
|
|
||||||
|
it { expect { subject }.to change { Procedure.count }.by(-1) }
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'when procedure is published' do
|
||||||
|
let(:procedure) { procedure_published }
|
||||||
|
|
||||||
|
it { expect(subject.status).to eq 401 }
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'when procedure is archived' do
|
||||||
|
let(:procedure) { procedure_published }
|
||||||
|
|
||||||
|
it { expect(subject.status).to eq 401 }
|
||||||
|
end
|
||||||
|
|
||||||
|
context "when administrateur does not own the procedure" do
|
||||||
|
let(:procedure_not_owned) { create :procedure, administrateur: create(:administrateur), published_at: nil, archived_at: nil }
|
||||||
|
|
||||||
|
subject { delete :destroy, params: {id: procedure_not_owned.id} }
|
||||||
|
|
||||||
|
it { expect{ subject }.to raise_error(ActiveRecord::RecordNotFound) }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
describe 'GET #edit' do
|
describe 'GET #edit' do
|
||||||
let(:published_at) { nil }
|
let(:published_at) { nil }
|
||||||
let(:procedure) { create(:procedure, administrateur: admin, published_at: published_at) }
|
let(:procedure) { create(:procedure, administrateur: admin, published_at: published_at) }
|
||||||
|
|
Loading…
Reference in a new issue