diff --git a/app/models/concerns/dossier_prefillable_concern.rb b/app/models/concerns/dossier_prefillable_concern.rb index 35cf970ed..245527e6f 100644 --- a/app/models/concerns/dossier_prefillable_concern.rb +++ b/app/models/concerns/dossier_prefillable_concern.rb @@ -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) diff --git a/spec/models/concern/dossier_prefillable_concern_spec.rb b/spec/models/concern/dossier_prefillable_concern_spec.rb index 58de07d7d..3ab8f73e9 100644 --- a/spec/models/concern/dossier_prefillable_concern_spec.rb +++ b/spec/models/concern/dossier_prefillable_concern_spec.rb @@ -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 }