foodsoft/spec/factories/user.rb

49 lines
1.3 KiB
Ruby
Raw Permalink Normal View History

2017-10-27 23:21:31 +02:00
require 'factory_bot'
2013-07-12 20:06:49 +02:00
2017-10-27 23:21:31 +02:00
FactoryBot.define do
2013-07-12 20:06:49 +02:00
factory :user do
sequence(:nick) { |n| "user#{n}" }
first_name { Faker::Name.first_name }
email { Faker::Internet.email }
2013-07-12 20:06:49 +02:00
password { new_random_password }
factory :admin do
sequence(:nick) { |n| "admin#{n}" }
2019-10-28 09:40:43 +01:00
first_name { 'Administrator' }
2013-07-12 20:06:49 +02:00
after :create do |user, evaluator|
2013-09-18 12:44:41 +02:00
create :workgroup, role_admin: true, user_ids: [user.id]
2013-07-12 20:06:49 +02:00
end
end
trait :ordergroup do
after :create do |user, evaluator|
create :ordergroup, user_ids: [user.id]
end
end
[:ordergroup, :finance, :invoices, :article_meta, :suppliers, :pickups, :orders].each do |role|
trait "role_#{role}".to_sym do
after :create do |user, evaluator|
create :workgroup, "role_#{role}" => true, user_ids: [user.id]
end
end
end
2013-07-12 20:06:49 +02:00
end
factory :group do
sequence(:name) { |n| "Group ##{n}" }
2013-07-12 20:06:49 +02:00
factory :workgroup do
type { 'Workgroup' }
2013-07-12 20:06:49 +02:00
end
factory :ordergroup, class: "Ordergroup" do
2019-10-28 09:40:43 +01:00
type { 'Ordergroup' }
sequence(:name) { |n| "Order group ##{n}" }
2013-07-24 12:37:20 +02:00
# workaround to avoid needing to save the ordergroup
# avoids e.g. error after logging in related to applebar
after :create do |group| Ordergroup.find(group.id).update_stats! end
2013-07-12 20:06:49 +02:00
end
end
end