refactor(revision): test for type_de_champ having a unique revision
This commit is contained in:
parent
588641764d
commit
98814c3812
2 changed files with 6 additions and 2 deletions
|
@ -56,7 +56,7 @@ class ProcedureRevision < ApplicationRecord
|
||||||
def find_or_clone_type_de_champ(id)
|
def find_or_clone_type_de_champ(id)
|
||||||
type_de_champ = find_type_de_champ_by_id(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
|
type_de_champ
|
||||||
elsif type_de_champ.parent.present?
|
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)
|
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)
|
def remove_type_de_champ(id)
|
||||||
type_de_champ = find_type_de_champ_by_id(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
|
type_de_champ.destroy
|
||||||
elsif type_de_champ.parent.present?
|
elsif type_de_champ.parent.present?
|
||||||
find_or_clone_type_de_champ(id).destroy
|
find_or_clone_type_de_champ(id).destroy
|
||||||
|
|
|
@ -164,6 +164,10 @@ class TypeDeChamp < ApplicationRecord
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def only_present_on_draft?
|
||||||
|
revisions.size == 1
|
||||||
|
end
|
||||||
|
|
||||||
def non_fillable?
|
def non_fillable?
|
||||||
type_champ.in?([
|
type_champ.in?([
|
||||||
TypeDeChamp.type_champs.fetch(:header_section),
|
TypeDeChamp.type_champs.fetch(:header_section),
|
||||||
|
|
Loading…
Reference in a new issue