From c417614695fb2fd13d4fbe6106f30a736426d8b3 Mon Sep 17 00:00:00 2001 From: Paul Chavard Date: Wed, 16 Oct 2024 14:15:26 +0200 Subject: [PATCH] fix(dossier): fix apply_diff with multiple changed rows --- app/models/concerns/dossier_clone_concern.rb | 5 +---- spec/models/concerns/dossier_clone_concern_spec.rb | 6 ++++-- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/app/models/concerns/dossier_clone_concern.rb b/app/models/concerns/dossier_clone_concern.rb index 07750548c..dd417cd8a 100644 --- a/app/models/concerns/dossier_clone_concern.rb +++ b/app/models/concerns/dossier_clone_concern.rb @@ -153,14 +153,11 @@ module DossierCloneConcern diff[:added].each { _1.update_column(:dossier_id, id) } - # a bit of a hack to work around unicity index - remove_group_id = ULID.generate diff[:updated].each do |champ| - champs_index.fetch(champ.public_id).update(row_id: remove_group_id) + champs_index.fetch(champ.public_id)&.destroy! champ.update_column(:dossier_id, id) end - Champ.where(row_id: remove_group_id).destroy_all diff[:removed].each(&:destroy!) end end diff --git a/spec/models/concerns/dossier_clone_concern_spec.rb b/spec/models/concerns/dossier_clone_concern_spec.rb index 9629d5df5..f5339d842 100644 --- a/spec/models/concerns/dossier_clone_concern_spec.rb +++ b/spec/models/concerns/dossier_clone_concern_spec.rb @@ -334,15 +334,17 @@ RSpec.describe DossierCloneConcern do subject { dossier.merge_fork(forked_dossier) } context 'with updated champ' do + let(:repetition_champ) { dossier.project_champs_public.last } let(:updated_champ) { forked_dossier.champs.find { _1.stable_id == 99 } } - let(:updated_repetition_champ) { forked_dossier.champs.find { _1.stable_id == 994 } } + let(:updated_repetition_champs) { forked_dossier.champs.filter { _1.stable_id == 994 } } before do + repetition_champ.add_row(updated_by: 'test') dossier.champs.each do |champ| champ.update(value: 'old value') end updated_champ.update(value: 'new value') - updated_repetition_champ.update(value: 'new value in repetition') + updated_repetition_champs.each { _1.update(value: 'new value in repetition') } dossier.debounce_index_search_terms_flag.remove end