From ad832b9401162a3f899ddc62249948c26dfcd9ca Mon Sep 17 00:00:00 2001 From: mfo Date: Fri, 6 Dec 2024 17:32:35 +0100 Subject: [PATCH] fix(prefill.repetitions): with more than one row, should be able to prefill champs repetition rows --- app/models/concerns/dossier_prefillable_concern.rb | 1 + .../api/public/v1/dossiers_controller_spec.rb | 9 ++++++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/app/models/concerns/dossier_prefillable_concern.rb b/app/models/concerns/dossier_prefillable_concern.rb index d0c21a2bf..526d66698 100644 --- a/app/models/concerns/dossier_prefillable_concern.rb +++ b/app/models/concerns/dossier_prefillable_concern.rb @@ -9,6 +9,7 @@ module DossierPrefillableConcern attributes = { prefilled: true } attributes[:champs_attributes] = champs_attributes.map { |h| h.merge(prefilled: true) } attributes[:individual_attributes] = identity_attributes if identity_attributes.present? + reload assign_attributes(attributes) save(validate: false) diff --git a/spec/controllers/api/public/v1/dossiers_controller_spec.rb b/spec/controllers/api/public/v1/dossiers_controller_spec.rb index 39c454962..0fb8a2dba 100644 --- a/spec/controllers/api/public/v1/dossiers_controller_spec.rb +++ b/spec/controllers/api/public/v1/dossiers_controller_spec.rb @@ -85,12 +85,15 @@ RSpec.describe API::Public::V1::DossiersController, type: :controller do end let(:prefilled_champs) { TypesDeChamp::PrefillTypeDeChamp.wrap(procedure.published_revision.types_de_champ, procedure.active_revision) } let(:prefilled_champs_as_params) { prefilled_champs.map { |type_de_champ| ["champ_#{type_de_champ.to_typed_id_for_query}", type_de_champ.example_value] }.to_h } - let(:params) do - prefilled_champs_as_params.merge(id: procedure.id) - end + let(:params) { prefilled_champs_as_params.merge(id: procedure.id) } it "updates the champs with the new values and mark them as prefilled" do expect { create_request }.not_to raise_error(ActiveRecord::RecordNotFound) + dossier = Dossier.last + + first_row = dossier.project_champs_public.first.rows.first + second_row = dossier.project_champs_public.first.rows.last + expect(dossier.project_champs_public.first.rows.flatten.map(&:value)).to match_array(['Texte court', 'Texte court']) end end end