Skip to content

Commit

Permalink
Merge tag '2023-06-23-01' into feature/import-2023-06-23
Browse files Browse the repository at this point in the history
# Conflicts:
#	db/schema.rb
  • Loading branch information
maatinito committed Sep 6, 2023
2 parents 6642380 + d53b4fb commit 685072d
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 10 deletions.
8 changes: 4 additions & 4 deletions app/models/concerns/dossier_clone_concern.rb
Original file line number Diff line number Diff line change
Expand Up @@ -145,25 +145,25 @@ def forked_groupe_instructeur_changed?
end

def apply_diff(diff)
champs_index = (champs + diff[:added]).index_by(&:stable_id_with_row)
champs_index = (champs_public_all + diff[:added]).index_by(&:stable_id_with_row)

diff[:added].each do |champ|
if champ.child?
champ.update_columns(dossier_id: id, parent_id: champs_index[champ.parent.stable_id_with_row].id)
champ.update_columns(dossier_id: id, parent_id: champs_index.fetch(champ.parent.stable_id_with_row).id)
else
champ.update_column(:dossier_id, id)
end
end

champs_to_remove = []
diff[:updated].each do |champ|
old_champ = champs_index[champ.stable_id_with_row]
old_champ = champs_index.fetch(champ.stable_id_with_row)
champs_to_remove << old_champ

if champ.child?
# we need to do that in order to avoid a foreign key constraint
old_champ.update(row_id: nil)
champ.update_columns(dossier_id: id, parent_id: champs_index[champ.parent.stable_id_with_row].id)
champ.update_columns(dossier_id: id, parent_id: champs_index.fetch(champ.parent.stable_id_with_row).id)
else
champ.update_column(:dossier_id, id)
end
Expand Down
8 changes: 4 additions & 4 deletions app/models/concerns/dossier_rebase_concern.rb
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,10 @@ def add_new_champs_for_revision(target_coordinate)
champs.filter { _1.stable_id == parent_stable_id }.each do |champ_repetition|
if champ_repetition.champs.present?
champ_repetition.champs.map(&:row_id).uniq.each do |row_id|
create_champ(target_coordinate, champ_repetition, row_id:)
champs << create_champ(target_coordinate, champ_repetition, row_id:)
end
elsif champ_repetition.mandatory?
create_champ(target_coordinate, champ_repetition, row_id: ULID.generate)
champs << create_champ(target_coordinate, champ_repetition, row_id: ULID.generate)
end
end
else
Expand All @@ -141,10 +141,10 @@ def add_new_champs_for_revision(target_coordinate)
end

def create_champ(target_coordinate, parent, row_id: nil)
champ = target_coordinate
target_coordinate
.type_de_champ
.build_champ(rebased_at: Time.zone.now, row_id:)
parent.champs << champ
.tap { parent.champs << _1 }
end

def purge_piece_justificative_file(champ)
Expand Down
1 change: 1 addition & 0 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -724,6 +724,7 @@
t.string "declarative_with_state"
t.bigint "defaut_groupe_instructeur_id"
t.string "description"
t.string "description_pj"
t.string "description_target_audience"
t.string "direction"
t.datetime "dossiers_count_computed_at"
Expand Down
11 changes: 9 additions & 2 deletions spec/models/concern/dossier_clone_concern_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,7 @@

context 'with new revision' do
let(:added_champ) { forked_dossier.champs.find { _1.libelle == "Un nouveau champ text" } }
let(:added_repetition_champ) { forked_dossier.champs.find { _1.libelle == "Texte en répétition" } }
let(:removed_champ) { dossier.champs.find { _1.stable_id == 99 } }
let(:updated_champ) { dossier.champs.find { _1.stable_id == 991 } }

Expand All @@ -306,6 +307,11 @@
type_champ: TypeDeChamp.type_champs.fetch(:text),
libelle: "Un nouveau champ text"
})
procedure.draft_revision.add_type_de_champ({
type_champ: TypeDeChamp.type_champs.fetch(:text),
parent_stable_id: 993,
libelle: "Texte en répétition"
})
procedure.draft_revision.remove_type_de_champ(removed_champ.stable_id)
procedure.draft_revision.find_and_ensure_exclusive_use(updated_champ.stable_id).update(libelle: "Un nouveau libelle")
procedure.publish_revision!
Expand All @@ -314,13 +320,14 @@
subject {
added_champ.update(value: 'new value for added champ')
updated_champ.update(value: 'new value for updated champ')
added_repetition_champ.update(value: "new value in repetition champ")
dossier.reload
super()
dossier.reload
}

it { expect { subject }.to change { dossier.reload.champs.size }.by(0) }
it { expect { subject }.to change { dossier.reload.champs.order(:created_at).map(&:to_s) }.from(['old value', 'old value', 'Non', 'old value', 'old value']).to(['new value for updated champ', 'Non', 'old value', 'old value', 'new value for added champ']) }
it { expect { subject }.to change { dossier.reload.champs.size }.by(1) }
it { expect { subject }.to change { dossier.reload.champs.order(:created_at).map(&:to_s) }.from(['old value', 'old value', 'Non', 'old value', 'old value']).to(['new value for updated champ', 'Non', 'old value', 'old value', 'new value for added champ', 'new value in repetition champ']) }

it "dossier after merge should be on last published revision" do
expect(dossier.revision_id).to eq(procedure.revisions.first.id)
Expand Down

0 comments on commit 685072d

Please sign in to comment.