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
|
2021-03-01 15:27:26 +01:00
|
|
|
sequence(:nick) { |n| "user#{n}" }
|
2013-07-14 02:49:40 +02:00
|
|
|
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
|
2018-10-15 16:51:33 +02:00
|
|
|
|
|
|
|
trait :ordergroup do
|
|
|
|
after :create do |user, evaluator|
|
|
|
|
create :ordergroup, user_ids: [user.id]
|
|
|
|
end
|
|
|
|
end
|
2019-02-05 20:53:02 +01:00
|
|
|
|
|
|
|
[: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
|
2021-03-01 15:27:26 +01:00
|
|
|
sequence(:name) { |n| "Group ##{n}" }
|
2013-07-12 20:06:49 +02:00
|
|
|
|
|
|
|
factory :workgroup do
|
2019-10-28 09:40:43 +01:00
|
|
|
type { '' }
|
2013-07-12 20:06:49 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
factory :ordergroup do
|
2019-10-28 09:40:43 +01:00
|
|
|
type { 'Ordergroup' }
|
2021-03-01 15:27:26 +01:00
|
|
|
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
|