demarches-normaliennes/spec/factories/administrateur.rb

35 lines
841 B
Ruby
Raw Normal View History

2018-01-23 17:15:42 +01:00
FactoryBot.define do
2017-06-01 17:44:56 +02:00
sequence(:administrateur_email) { |n| "admin#{n}@admin.com" }
2015-10-26 15:54:20 +01:00
factory :administrateur do
email { generate(:administrateur_email) }
2019-08-08 16:55:51 +02:00
transient do
user { nil }
2019-08-09 10:39:14 +02:00
password { 'mon chien aime les bananes' }
2019-08-08 16:55:51 +02:00
end
2019-08-09 10:39:14 +02:00
after(:create) do |administrateur, evaluator|
2019-08-08 16:55:51 +02:00
if evaluator.user.present?
2019-08-09 10:39:14 +02:00
user = evaluator.user
2019-08-08 16:55:51 +02:00
else
2019-08-09 10:39:14 +02:00
user = create(:user, email: administrateur.email, password: evaluator.password, administrateur: administrateur)
2019-08-08 16:55:51 +02:00
end
2019-08-09 10:39:14 +02:00
create(:instructeur, email: administrateur.email, user: user)
end
end
trait :with_api_token do
after(:create) do |admin|
admin.renew_api_token
end
end
trait :with_procedure do
after(:create) do |admin|
create(:simple_procedure, administrateur: admin)
admin.reload
end
end
2017-04-04 15:27:04 +02:00
end