demarches-normaliennes/spec/factories/procedure_revision_type_de_champ.rb
Pierre de La Morinerie 970c3e4b2b specs: avoid executing business logic in Procedure factory
Calling business logic in a factory is a code-smell, because it
usually requires the object to be saved into database, and may have
unintended consequences when the business logic is changed.

Also, this allows to just build a published procedure, without saving it
to the database.
2021-11-23 08:07:07 +01:00

16 lines
419 B
Ruby

FactoryBot.define do
factory :procedure_revision_type_de_champ do
transient do
from_original { nil }
end
after(:build) do |revision_type_de_champ, evaluator|
if evaluator.from_original
original = evaluator.from_original
revision_type_de_champ.type_de_champ = original.type_de_champ
revision_type_de_champ.position = original.position
end
end
end
end