specs: improve avis factory

The instructeur, dossier and claimant where created regardless of
wether they already existed or not.

With this commit:

- Associations are declarated in a more idiomatic way
- They are correctly not created if they are provided when creating the
object.
This commit is contained in:
Pierre de La Morinerie 2019-10-21 09:45:03 +00:00
parent a56dc0f653
commit ec6ec6f4aa
2 changed files with 11 additions and 20 deletions

View file

@ -1,27 +1,16 @@
FactoryBot.define do
sequence(:expert_email) { |n| "expert#{n}@expert.com" }
factory :avis do
email { generate(:expert_email) }
introduction { 'Bonjour, merci de me donner votre avis sur ce dossier' }
confidentiel { false }
before(:create) do |avis, _evaluator|
if !avis.instructeur
avis.instructeur = create :instructeur
end
end
before(:create) do |avis, _evaluator|
if !avis.dossier
avis.dossier = create :dossier
end
end
before(:create) do |avis, _evaluator|
if !avis.claimant
avis.claimant = create :instructeur
end
end
association :dossier
association :claimant, factory: :instructeur
trait :with_answer do
answer { "Mon avis se décompose en deux points :\n- La demande semble pertinente\n- Le demandeur remplit les conditions." }
answer { "Mon avis se décompose en deux points :\n- La demande semble pertinente\n- Le demandeur remplit les conditions." }
end
end
end