Merge pull request #2727 from betagouv/fix-destroy

Fix scope for logo/notice/deliberation deletion
This commit is contained in:
gregoirenovel 2018-10-02 11:14:27 +02:00 committed by GitHub
commit cc2294918d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 52 additions and 20 deletions

View file

@ -2,7 +2,7 @@ class Admin::ProceduresController < AdminController
include SmartListing::Helper::ControllerExtensions include SmartListing::Helper::ControllerExtensions
helper SmartListing::Helper helper SmartListing::Helper
before_action :retrieve_procedure, only: [:show, :edit] before_action :retrieve_procedure, only: [:show, :edit, :delete_logo, :delete_deliberation, :delete_notice]
def index def index
@procedures = smart_listing_create :procedures, @procedures = smart_listing_create :procedures,
@ -252,31 +252,25 @@ class Admin::ProceduresController < AdminController
end end
def delete_logo def delete_logo
procedure = Procedure.find(params[:id]) @procedure.remove_logo!
@procedure.save
procedure.remove_logo!
procedure.save
flash.notice = 'le logo a bien été supprimé' flash.notice = 'le logo a bien été supprimé'
redirect_to edit_admin_procedure_path(procedure) redirect_to edit_admin_procedure_path(@procedure)
end end
def delete_deliberation def delete_deliberation
procedure = Procedure.find(params[:id]) @procedure.deliberation.purge_later
procedure.deliberation.purge_later
flash.notice = 'la délibération a bien été supprimée' flash.notice = 'la délibération a bien été supprimée'
redirect_to edit_admin_procedure_path(procedure) redirect_to edit_admin_procedure_path(@procedure)
end end
def delete_notice def delete_notice
procedure = Procedure.find(params[:id]) @procedure.notice.purge_later
procedure.notice.purge_later
flash.notice = 'la notice a bien été supprimée' flash.notice = 'la notice a bien été supprimée'
redirect_to edit_admin_procedure_path(procedure) redirect_to edit_admin_procedure_path(@procedure)
end end
private private

View file

@ -713,15 +713,53 @@ describe Admin::ProceduresController, type: :controller do
end end
describe "DELETE #delete_deliberation" do describe "DELETE #delete_deliberation" do
let(:procedure) { create(:procedure, :with_deliberation) } context "with a demarche the admin owns" do
let(:procedure) { create(:procedure, :with_deliberation, administrateur: admin) }
before do before do
delete :delete_deliberation, params: { id: procedure.id } delete :delete_deliberation, params: { id: procedure.id }
procedure.reload procedure.reload
end
it { expect(procedure.deliberation.attached?).to eq(false) }
it { expect(response).to redirect_to(edit_admin_procedure_path(procedure)) }
end end
it { expect(procedure.deliberation.attached?).to eq(false) } context "with a demarche the admin does not own" do
it { expect(response).to redirect_to(edit_admin_procedure_path(procedure)) } let(:procedure) { create(:procedure, :with_deliberation) }
before do
delete :delete_deliberation, params: { id: procedure.id }
procedure.reload
end
it { expect(response.status).to eq(404) }
end
end
describe "DELETE #delete_notice" do
context "with a demarche the admin owns" do
let(:procedure) { create(:procedure, :with_notice, administrateur: admin) }
before do
delete :delete_notice, params: { id: procedure.id }
procedure.reload
end
it { expect(procedure.notice.attached?).to eq(false) }
it { expect(response).to redirect_to(edit_admin_procedure_path(procedure)) }
end
context "with a demarche the admin does not own" do
let(:procedure) { create(:procedure, :with_notice) }
before do
delete :delete_notice, params: { id: procedure.id }
procedure.reload
end
it { expect(response.status).to eq(404) }
end
end end
describe "GET #check_availability" do describe "GET #check_availability" do