diff --git a/app/models/concerns/dossier_clone_concern.rb b/app/models/concerns/dossier_clone_concern.rb index b950d63ef..8418f8ed4 100644 --- a/app/models/concerns/dossier_clone_concern.rb +++ b/app/models/concerns/dossier_clone_concern.rb @@ -106,7 +106,7 @@ module DossierCloneConcern end transaction do - cloned_dossier.save! + cloned_dossier.save!(validate: !fork) if fork cloned_dossier.rebase! diff --git a/spec/models/concern/dossier_clone_concern_spec.rb b/spec/models/concern/dossier_clone_concern_spec.rb index 65cdd735b..e1e4f6a8b 100644 --- a/spec/models/concern/dossier_clone_concern_spec.rb +++ b/spec/models/concern/dossier_clone_concern_spec.rb @@ -182,6 +182,32 @@ RSpec.describe DossierCloneConcern do expect(champ_pj_fork.updated_at).to eq(champ_pj.updated_at) } end + + context 'invalid origin' do + let(:procedure) do + create(:procedure, types_de_champ_public: [ + { type: :drop_down_list, libelle: "Le savez-vous?", stable_id: 992, drop_down_list_value: ["Oui", "Non", "Peut-ĂȘtre"].join("\r\n"), mandatory: true } + ]) + end + + before do + champ = dossier.champs.find { _1.stable_id == 992 } + champ.value = "Je ne sais pas" + champ.save!(validate: false) + end + + it 'can still fork' do + # rubocop:disable Lint/BooleanSymbol + expect(dossier.valid?(context: :false)).to be_falsey + + new_dossier.champs.load # load relation so champs are validated below + + expect(new_dossier.valid?(context: :false)).to be_falsey + expect(new_dossier.champs.find { _1.stable_id == 992 }.value).to eq("Je ne sais pas") + + # rubocop:enable Lint/BooleanSymbol + end + end end end