fix(editor champ): do not raise on destroy replay

This commit is contained in:
simon lehericey 2022-10-11 16:27:49 +02:00
parent b6f3b51522
commit 7672ad3fe9
3 changed files with 12 additions and 3 deletions

View file

@ -72,9 +72,11 @@ module Administrateurs
reset_procedure reset_procedure
flash.notice = "Formulaire enregistré" flash.notice = "Formulaire enregistré"
if @coordinate.present?
@destroyed = @coordinate @destroyed = @coordinate
@morphed = champ_components_starting_at(@coordinate) @morphed = champ_components_starting_at(@coordinate)
end end
end
private private

View file

@ -97,6 +97,9 @@ class ProcedureRevision < ApplicationRecord
def remove_type_de_champ(stable_id) def remove_type_de_champ(stable_id)
coordinate, tdc = coordinate_and_tdc(stable_id) coordinate, tdc = coordinate_and_tdc(stable_id)
# in case of replay
return nil if coordinate.nil?
children = children_of(tdc).to_a children = children_of(tdc).to_a
coordinate.destroy coordinate.destroy

View file

@ -175,9 +175,13 @@ describe ProcedureRevision do
it 'reorders' do it 'reorders' do
expect(draft.revision_types_de_champ_public.pluck(:position)).to eq([0, 1, 2]) expect(draft.revision_types_de_champ_public.pluck(:position)).to eq([0, 1, 2])
draft.remove_type_de_champ(draft.types_de_champ_public[1].stable_id) first_stable_id = draft.types_de_champ_public[1].stable_id
draft.remove_type_de_champ(first_stable_id)
expect(draft.revision_types_de_champ_public.pluck(:position)).to eq([0, 1]) expect(draft.revision_types_de_champ_public.pluck(:position)).to eq([0, 1])
expect { draft.remove_type_de_champ(first_stable_id) }.not_to raise_error
end end
end end