fb2b4d8a8a
chore: fix api test conventions chore: rubocop -A spec/ chore: more rubocop -A fix failing test rubocop fixes removes helper methods that are in my opinion dead code more rubocop fixes rubocop -a --auto-gen-config
48 lines
1.3 KiB
Ruby
48 lines
1.3 KiB
Ruby
require 'factory_bot'
|
|
|
|
FactoryBot.define do
|
|
factory :user do
|
|
sequence(:nick) { |n| "user#{n}" }
|
|
first_name { Faker::Name.first_name }
|
|
email { Faker::Internet.email }
|
|
password { new_random_password }
|
|
|
|
factory :admin do
|
|
sequence(:nick) { |n| "admin#{n}" }
|
|
first_name { 'Administrator' }
|
|
after :create do |user, _evaluator|
|
|
create(:workgroup, role_admin: true, user_ids: [user.id])
|
|
end
|
|
end
|
|
|
|
trait :ordergroup do
|
|
after :create do |user, _evaluator|
|
|
create(:ordergroup, user_ids: [user.id])
|
|
end
|
|
end
|
|
|
|
%i[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
|
|
end
|
|
|
|
factory :group do
|
|
sequence(:name) { |n| "Group ##{n}" }
|
|
|
|
factory :workgroup do
|
|
type { 'Workgroup' }
|
|
end
|
|
|
|
factory :ordergroup, class: 'Ordergroup' do
|
|
type { 'Ordergroup' }
|
|
sequence(:name) { |n| "Order group ##{n}" }
|
|
# 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
|
|
end
|
|
end
|
|
end
|