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' }
|
2023-05-12 13:01:12 +02:00
|
|
|
after :create do |user, _evaluator|
|
|
|
|
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
|
2023-05-12 13:01:12 +02:00
|
|
|
after :create do |user, _evaluator|
|
|
|
|
create(:ordergroup, user_ids: [user.id])
|
2018-10-15 16:51:33 +02:00
|
|
|
end
|
|
|
|
end
|
2019-02-05 20:53:02 +01:00
|
|
|
|
2023-05-12 13:01:12 +02:00
|
|
|
%i[ordergroup finance invoices article_meta suppliers pickups orders].each do |role|
|
2019-02-05 20:53:02 +01:00
|
|
|
trait "role_#{role}".to_sym do
|
2023-05-12 13:01:12 +02:00
|
|
|
after :create do |user, _evaluator|
|
|
|
|
create(:workgroup, "role_#{role}" => true, user_ids: [user.id])
|
2019-02-05 20:53:02 +01:00
|
|
|
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
|
2022-05-27 17:06:25 +02:00
|
|
|
type { 'Workgroup' }
|
2013-07-12 20:06:49 +02:00
|
|
|
end
|
|
|
|
|
2023-05-12 13:01:12 +02:00
|
|
|
factory :ordergroup, class: '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
|