diff --git a/app/controllers/admin/procedures_controller.rb b/app/controllers/admin/procedures_controller.rb index 034df45e0..e451af182 100644 --- a/app/controllers/admin/procedures_controller.rb +++ b/app/controllers/admin/procedures_controller.rb @@ -45,7 +45,11 @@ class Admin::ProceduresController < AdminController def hide procedure = current_administrateur.procedures.find(params[:id]) procedure.hide! - procedure.procedure_path.destroy + # procedure should no longer be reachable so we delete its procedure_path + # that way it is also available for another procedure + # however, sometimes the path has already been deleted (ex: stolen by another procedure), + # so we're not certain the procedure has a procedure_path anymore + procedure.procedure_path.try(:destroy) flash.notice = "Procédure supprimée, en cas d'erreur contactez nous : contact@tps.apientreprise.fr" redirect_to admin_procedures_draft_path diff --git a/spec/controllers/admin/procedures_controller_spec.rb b/spec/controllers/admin/procedures_controller_spec.rb index 2564a49c6..829b3a7cb 100644 --- a/spec/controllers/admin/procedures_controller_spec.rb +++ b/spec/controllers/admin/procedures_controller_spec.rb @@ -559,5 +559,15 @@ describe Admin::ProceduresController, type: :controller do it { expect(procedure.hidden_at).not_to be_nil } it { expect(procedure.procedure_path).to be_nil } end + + context "when procedure has no path" do + let!(:procedure) { create :procedure, administrateur: admin } + + it { expect{ subject }.not_to raise_error } + it do + subject + expect(procedure.reload.hidden_at).not_to be_nil + end + end end end