Simplify instructeur and administrateur factory

This commit is contained in:
simon lehericey 2019-08-16 18:59:46 +02:00
parent c1a622efa1
commit e0e29d741f
2 changed files with 4 additions and 17 deletions

View file

@ -4,18 +4,11 @@ FactoryBot.define do
email { generate(:administrateur_email) }
transient do
user { nil }
password { 'mon chien aime les bananes' }
end
after(:create) do |administrateur, evaluator|
if evaluator.user.present?
user = evaluator.user
else
user = create(:user, email: administrateur.email, password: evaluator.password, administrateur: administrateur)
end
create(:instructeur, email: administrateur.email, user: user)
initialize_with do
User.create_or_promote_to_administrateur(email, password).administrateur
end
end

View file

@ -8,14 +8,8 @@ FactoryBot.define do
password { 'somethingverycomplated!' }
end
after(:create) do |instructeur, evaluator|
if evaluator.user.present?
user = evaluator.user
else
user = create(:user, email: instructeur.email, password: evaluator.password)
end
instructeur.update!(user: user)
initialize_with do
User.create_or_promote_to_instructeur(email, password).instructeur
end
end
end