Merge pull request #1151 from sgmap/revert-destroy-procedure-deletion

Revert "ProcedureController: remove unused destroy method"
This commit is contained in:
gregoirenovel 2017-12-21 19:07:36 +01:00 committed by GitHub
commit f6d34e07b7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 59 additions and 0 deletions

View file

@ -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

View file

@ -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) }