mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Bring user factory from spree_core and merge with modification
This commit is contained in:
@@ -1,9 +1,19 @@
|
||||
FactoryBot.modify do
|
||||
factory :user do
|
||||
FactoryBot.define do
|
||||
sequence :user_authentication_token do |n|
|
||||
"xxxx#{Time.now.to_i}#{rand(1000)}#{n}xxxxxxxxxxxxx"
|
||||
end
|
||||
|
||||
factory :user, class: Spree.user_class do
|
||||
transient do
|
||||
enterprises []
|
||||
end
|
||||
|
||||
email { generate(:random_email) }
|
||||
login { email }
|
||||
password 'secret'
|
||||
password_confirmation { password }
|
||||
authentication_token { generate(:user_authentication_token) } if Spree.user_class.attribute_method? :authentication_token
|
||||
|
||||
confirmation_sent_at '1970-01-01 00:00:00'
|
||||
confirmed_at '1970-01-01 00:00:01'
|
||||
|
||||
@@ -21,15 +31,14 @@ FactoryBot.modify do
|
||||
user.spree_roles.clear # Remove admin role
|
||||
|
||||
user.enterprises << proxy.enterprises
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
factory :admin_user do
|
||||
confirmation_sent_at '1970-01-01 00:00:00'
|
||||
confirmed_at '1970-01-01 00:00:01'
|
||||
factory :admin_user do
|
||||
spree_roles { [Spree::Role.find_by(name: 'admin') || create(:role, name: 'admin')] }
|
||||
|
||||
after(:create) do |user|
|
||||
user.spree_roles << Spree::Role.find_or_create_by!(name: 'admin')
|
||||
after(:create) do |user|
|
||||
user.spree_roles << Spree::Role.find_or_create_by!(name: 'admin')
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user