fix(prefill): don't mark the dossier as prefilled when it's not (#8464)

A dossier should not be marked as prefilled when it's not, meaning
when no prefill params are given.
This commit is contained in:
Sébastien Carceles 2023-01-19 11:51:56 +01:00 committed by GitHub
parent 51e97b2d89
commit 0046338e6a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 2 deletions

View file

@ -4,8 +4,10 @@ module DossierPrefillableConcern
extend ActiveSupport::Concern
def prefill!(champs_public_attributes)
return unless champs_public_attributes.any?
attr = { prefilled: true }
attr[:champs_public_attributes] = champs_public_attributes.map { |h| h.merge(prefilled: true) } if champs_public_attributes.any?
attr[:champs_public_attributes] = champs_public_attributes.map { |h| h.merge(prefilled: true) }
assign_attributes(attr)
save(validate: false)

View file

@ -17,7 +17,9 @@ RSpec.describe DossierPrefillableConcern do
context 'when champs_public_attributes is empty' do
let(:values) { [] }
it_behaves_like 'a dossier marked as prefilled'
it "doesn't mark the dossier as prefilled" do
expect { fill }.not_to change { dossier.reload.prefilled }.from(nil)
end
it "doesn't change champs_public" do
expect { fill }.not_to change { dossier.champs_public.to_a }