Merge pull request #11121 from mfo/US/fix-repetition-prefill
ETQ consommateur de l'API de pré-remplissage, je peux pre-remplir plus d'un row d'une repetition
This commit is contained in:
commit
586b8ed993
2 changed files with 25 additions and 0 deletions
|
@ -9,6 +9,7 @@ module DossierPrefillableConcern
|
||||||
attributes = { prefilled: true }
|
attributes = { prefilled: true }
|
||||||
attributes[:champs_attributes] = champs_attributes.map { |h| h.merge(prefilled: true) }
|
attributes[:champs_attributes] = champs_attributes.map { |h| h.merge(prefilled: true) }
|
||||||
attributes[:individual_attributes] = identity_attributes if identity_attributes.present?
|
attributes[:individual_attributes] = identity_attributes if identity_attributes.present?
|
||||||
|
reload
|
||||||
|
|
||||||
assign_attributes(attributes)
|
assign_attributes(attributes)
|
||||||
save(validate: false)
|
save(validate: false)
|
||||||
|
|
|
@ -72,6 +72,30 @@ RSpec.describe API::Public::V1::DossiersController, type: :controller do
|
||||||
expect(dossier.individual.gender).to eq(genre_value)
|
expect(dossier.individual.gender).to eq(genre_value)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context 'when prefill given values contains more than one rows for repetitions' do
|
||||||
|
let(:procedure) { create(:procedure, :published, types_de_champ_public:) }
|
||||||
|
let(:types_de_champ_public) do
|
||||||
|
[
|
||||||
|
type: :repetition,
|
||||||
|
children: [
|
||||||
|
{ type: :text, libelle: 'child of repet text' }
|
||||||
|
]
|
||||||
|
]
|
||||||
|
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) { 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
|
end
|
||||||
|
|
||||||
context 'when the dossier can not be saved' do
|
context 'when the dossier can not be saved' do
|
||||||
|
|
Loading…
Reference in a new issue