[Fix #1304] If procedure has no path do not crash when hiding it
This commit is contained in:
parent
900fdc81ef
commit
e9ec9e410f
2 changed files with 15 additions and 1 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue