2024-04-29 00:17:15 +02:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2020-08-27 19:55:37 +02:00
|
|
|
FactoryBot.define do
|
|
|
|
factory :procedure_revision do
|
2021-11-19 13:48:52 +01:00
|
|
|
transient do
|
|
|
|
from_original { nil }
|
|
|
|
end
|
|
|
|
|
|
|
|
after(:build) do |revision, evaluator|
|
|
|
|
if evaluator.from_original
|
2022-07-23 12:29:18 +02:00
|
|
|
from_revision = evaluator.from_original
|
2021-11-19 13:48:52 +01:00
|
|
|
|
2022-07-23 12:29:18 +02:00
|
|
|
revision.procedure = from_revision.procedure
|
|
|
|
revision.dossier_submitted_message_id = from_revision.dossier_submitted_message_id
|
|
|
|
|
|
|
|
coordinate_map = {}
|
|
|
|
revision.association(:revision_types_de_champ).target = from_revision.revision_types_de_champ.map do |from_coordinate|
|
|
|
|
parent = from_coordinate.parent.present? ? coordinate_map[from_coordinate.parent] : nil
|
|
|
|
|
|
|
|
coordinate = build(:procedure_revision_type_de_champ,
|
|
|
|
revision: revision,
|
|
|
|
type_de_champ: from_coordinate.type_de_champ,
|
|
|
|
position: from_coordinate.position,
|
|
|
|
parent: parent)
|
|
|
|
|
|
|
|
if parent.present?
|
|
|
|
parent.association(:revision_types_de_champ).target << coordinate
|
|
|
|
elsif from_coordinate.private?
|
|
|
|
revision.association(:revision_types_de_champ_private).target << coordinate
|
|
|
|
else
|
|
|
|
revision.association(:revision_types_de_champ_public).target << coordinate
|
|
|
|
end
|
|
|
|
|
|
|
|
coordinate_map[from_coordinate] = coordinate
|
|
|
|
coordinate
|
2021-11-19 13:48:52 +01:00
|
|
|
end
|
2022-07-23 12:29:18 +02:00
|
|
|
revision.association(:types_de_champ).target = revision.revision_types_de_champ.map(&:type_de_champ)
|
|
|
|
revision.association(:types_de_champ_public).target = revision.revision_types_de_champ_public.map(&:type_de_champ)
|
|
|
|
revision.association(:types_de_champ_private).target = revision.revision_types_de_champ_private.map(&:type_de_champ)
|
2021-11-19 13:48:52 +01:00
|
|
|
end
|
|
|
|
end
|
2020-08-27 19:55:37 +02:00
|
|
|
end
|
|
|
|
end
|