poc(spec): renumber only at one point

This commit is contained in:
Martin 2024-01-18 10:13:16 +01:00 committed by mfo
parent a9c0d3e7e9
commit 434cd77030
2 changed files with 9 additions and 3 deletions

View file

@ -72,7 +72,6 @@ class ProcedureRevision < ApplicationRecord
end
end
# []
def move_type_de_champ(stable_id, position)
coordinate, _ = coordinate_and_tdc(stable_id)
siblings = coordinate.siblings
@ -89,6 +88,12 @@ class ProcedureRevision < ApplicationRecord
coordinate
end
def renumber(siblings)
siblings.to_a.compact.each.with_index do |sibling, position|
sibling.update_column(:position, position)
end
end
def remove_type_de_champ(stable_id)
coordinate, tdc = coordinate_and_tdc(stable_id)
@ -101,9 +106,9 @@ class ProcedureRevision < ApplicationRecord
children.each(&:destroy_if_orphan)
tdc.destroy_if_orphan
# they are not aware of the removal
coordinate.siblings.where("position >= ?", coordinate.position).update_all("position = position - 1")
# they are not aware of the removal
types_de_champ_public.reset
types_de_champ_private.reset

View file

@ -1931,7 +1931,8 @@ describe Dossier, type: :model do
procedure.publish!
dossier
procedure.draft_revision.remove_type_de_champ(text_type_de_champ.stable_id)
procedure.draft_revision.add_type_de_champ(type_champ: TypeDeChamp.type_champs.fetch(:text), libelle: 'New text field')
coordinate = procedure.draft_revision.add_type_de_champ(type_champ: TypeDeChamp.type_champs.fetch(:text), libelle: 'New text field')
procedure.draft_revision.renumber(coordinate.revision_type_de_champ.siblings)
procedure.draft_revision.find_and_ensure_exclusive_use(yes_no_type_de_champ.stable_id).update(libelle: 'Updated yes/no')
procedure.draft_revision.find_and_ensure_exclusive_use(commune_type_de_champ.stable_id).update(libelle: 'Commune de naissance')
procedure.draft_revision.find_and_ensure_exclusive_use(repetition_type_de_champ.stable_id).update(libelle: 'Repetition')