remove_repetition
This commit is contained in:
parent
4d97f6aa8c
commit
633f0d1ce5
4 changed files with 14 additions and 7 deletions
|
@ -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)
|
||||||
|
|
||||||
|
if parent_revision_type_de_champ.present?
|
||||||
types_de_champ
|
types_de_champ
|
||||||
.where(procedure_revision_types_de_champ: { parent_id: parent_revision_type_de_champ.id })
|
.where(procedure_revision_types_de_champ: { parent_id: parent_revision_type_de_champ.id })
|
||||||
.order("procedure_revision_types_de_champ.position")
|
.order("procedure_revision_types_de_champ.position")
|
||||||
|
else
|
||||||
|
TypeDeChamp.none
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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
|
||||||
|
|
||||||
|
|
|
@ -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
|
||||||
|
|
Loading…
Reference in a new issue