refactor(spec): raise if old style factory is used

This commit is contained in:
Paul Chavard 2022-08-04 11:39:30 +02:00
parent 2d7803cd48
commit 65e96002b1

View file

@ -29,18 +29,24 @@ FactoryBot.define do
end
after(:build) do |procedure, evaluator|
if evaluator.types_de_champ.present?
raise "use types_de_champ_public instead of types_de_champ"
end
initial_revision = build(:procedure_revision, procedure: procedure, attestation_template: evaluator.attestation_template, dossier_submitted_message: evaluator.dossier_submitted_message)
if evaluator.types_de_champ_public.present?
if !evaluator.types_de_champ_public.first.is_a?(Hash)
raise "types_de_champ_public must be an array of hashes"
end
build_types_de_champ(evaluator.types_de_champ_public, revision: initial_revision, scope: :public)
end
add_types_de_champs(evaluator.types_de_champ, to: initial_revision, scope: :public)
if evaluator.types_de_champ_private.present?
if evaluator.types_de_champ_private.first.is_a?(Hash)
build_types_de_champ(evaluator.types_de_champ_private, revision: initial_revision, scope: :private)
else
add_types_de_champs(evaluator.types_de_champ_private, to: initial_revision, scope: :private)
if !evaluator.types_de_champ_private.first.is_a?(Hash)
raise "types_de_champ_private must be an array of hashes"
end
build_types_de_champ(evaluator.types_de_champ_private, revision: initial_revision, scope: :private)
end
if procedure.brouillon?
@ -436,17 +442,3 @@ def build_types_de_champ(types_de_champ, revision:, scope: :public, parent: nil)
revision.association(:types_de_champ_private).target = revision.revision_types_de_champ_private.map(&:type_de_champ)
end
end
def add_types_de_champs(types_de_champ, to: nil, scope: :public)
revision = to
association_name = scope == :private ? :revision_types_de_champ_private : :revision_types_de_champ_public
types_de_champ.each.with_index do |type_de_champ, i|
type_de_champ.private = (scope == :private)
revision.public_send(association_name) << build(:procedure_revision_type_de_champ,
revision: revision,
position: i,
type_de_champ: type_de_champ)
end
end