Merge pull request #1305 from betagouv/fix-1304

[Fix #1304] If procedure has no path do not crash when hiding it
This commit is contained in:
gregoirenovel 2018-01-18 18:57:46 +01:00 committed by GitHub
commit ccad372036
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 1 deletions

View file

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

View file

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