fix(dossier): ensure submitted dossiers always have groupe instructeur
This commit is contained in:
parent
0a4d87abdb
commit
91caef0bfe
2 changed files with 25 additions and 2 deletions
|
@ -362,7 +362,7 @@ module Users
|
|||
Dossier.with_champs.find(params[:id])
|
||||
end
|
||||
|
||||
def change_groupe_instructeur?
|
||||
def should_change_groupe_instructeur?
|
||||
if params[:dossier].key?(:groupe_instructeur_id)
|
||||
groupe_instructeur_id = params[:dossier][:groupe_instructeur_id]
|
||||
if groupe_instructeur_id.nil?
|
||||
|
@ -380,6 +380,14 @@ module Users
|
|||
end
|
||||
end
|
||||
|
||||
def should_fill_groupe_instructeur?
|
||||
!@dossier.procedure.routee? && @dossier.groupe_instructeur_id.nil?
|
||||
end
|
||||
|
||||
def defaut_groupe_instructeur
|
||||
@dossier.procedure.defaut_groupe_instructeur
|
||||
end
|
||||
|
||||
def update_dossier_and_compute_errors
|
||||
errors = []
|
||||
|
||||
|
@ -396,11 +404,15 @@ module Users
|
|||
|
||||
if !@dossier.save(**validation_options)
|
||||
errors += @dossier.errors.full_messages
|
||||
elsif change_groupe_instructeur?
|
||||
elsif should_change_groupe_instructeur?
|
||||
@dossier.assign_to_groupe_instructeur(groupe_instructeur_from_params)
|
||||
end
|
||||
end
|
||||
|
||||
if should_fill_groupe_instructeur?
|
||||
@dossier.assign_to_groupe_instructeur(defaut_groupe_instructeur)
|
||||
end
|
||||
|
||||
if !save_draft?
|
||||
errors += @dossier.check_mandatory_champs
|
||||
|
||||
|
|
|
@ -464,6 +464,17 @@ describe Users::DossiersController, type: :controller do
|
|||
end
|
||||
end
|
||||
|
||||
context "when the dossier was created on a routee procedure, but routage was later disabled" do
|
||||
let(:dossier) { create(:dossier, groupe_instructeur: nil, user: user) }
|
||||
|
||||
it "sets a default groupe_instructeur" do
|
||||
subject
|
||||
|
||||
expect(response).to redirect_to(merci_dossier_path(dossier))
|
||||
expect(dossier.reload.groupe_instructeur).to eq(dossier.procedure.defaut_groupe_instructeur)
|
||||
end
|
||||
end
|
||||
|
||||
context "on an closed procedure" do
|
||||
before { dossier.procedure.close! }
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue