remove_repetition

This commit is contained in:
simon lehericey 2022-05-18 10:51:31 +02:00
parent 4d97f6aa8c
commit 633f0d1ce5
4 changed files with 14 additions and 7 deletions

View file

@ -157,9 +157,13 @@ class ProcedureRevision < ApplicationRecord
def children_of(tdc) def children_of(tdc)
parent_revision_type_de_champ = revision_types_de_champ.find_by(type_de_champ: tdc) parent_revision_type_de_champ = revision_types_de_champ.find_by(type_de_champ: tdc)
types_de_champ if parent_revision_type_de_champ.present?
.where(procedure_revision_types_de_champ: { parent_id: parent_revision_type_de_champ.id }) types_de_champ
.order("procedure_revision_types_de_champ.position") .where(procedure_revision_types_de_champ: { parent_id: parent_revision_type_de_champ.id })
.order("procedure_revision_types_de_champ.position")
else
TypeDeChamp.none
end
end end
private private

View file

@ -433,8 +433,11 @@ class TypeDeChamp < ApplicationRecord
end end
def remove_repetition def remove_repetition
if !repetition? if !repetition? && procedure.present?
types_de_champ.destroy_all procedure
.draft_revision # action occurs only on draft
.children_of(self)
.destroy_all
end end
end end
end end

View file

@ -409,7 +409,7 @@ describe ProcedureRevision do
let(:procedure) { create(:procedure, :with_repetition) } let(:procedure) { create(:procedure, :with_repetition) }
before do before do
child = new_draft.types_de_champ_public.last.types_de_champ.first child = new_draft.children_of(new_draft.types_de_champ_public.last).first
new_draft.find_or_clone_type_de_champ(child.stable_id).update(type_champ: :drop_down_list, drop_down_options: ['one', 'two']) new_draft.find_or_clone_type_de_champ(child.stable_id).update(type_champ: :drop_down_list, drop_down_options: ['one', 'two'])
end end

View file

@ -101,7 +101,7 @@ shared_examples 'type_de_champ_spec' do
let(:target_type_champ) { TypeDeChamp.type_champs.fetch(:text) } let(:target_type_champ) { TypeDeChamp.type_champs.fetch(:text) }
it 'removes the children types de champ' do it 'removes the children types de champ' do
expect(tdc.types_de_champ).to be_empty expect(procedure.draft_revision.children_of(tdc)).to be_empty
end end
end end
end end