refactor(revision): test for type_de_champ having a unique revision

This commit is contained in:
Paul Chavard 2022-05-06 10:52:54 +02:00
parent 588641764d
commit 98814c3812
2 changed files with 6 additions and 2 deletions

View file

@ -56,7 +56,7 @@ class ProcedureRevision < ApplicationRecord
def find_or_clone_type_de_champ(id)
type_de_champ = find_type_de_champ_by_id(id)
if type_de_champ.revision == self
if type_de_champ.only_present_on_draft?
type_de_champ
elsif type_de_champ.parent.present?
find_or_clone_type_de_champ(type_de_champ.parent.stable_id).types_de_champ.find_by!(stable_id: id)
@ -88,7 +88,7 @@ class ProcedureRevision < ApplicationRecord
def remove_type_de_champ(id)
type_de_champ = find_type_de_champ_by_id(id)
if type_de_champ.revision == self
if type_de_champ.only_present_on_draft?
type_de_champ.destroy
elsif type_de_champ.parent.present?
find_or_clone_type_de_champ(id).destroy

View file

@ -164,6 +164,10 @@ class TypeDeChamp < ApplicationRecord
end
end
def only_present_on_draft?
revisions.size == 1
end
def non_fillable?
type_champ.in?([
TypeDeChamp.type_champs.fetch(:header_section),