2017-10-27 23:21:31 +02:00
|
|
|
require 'factory_bot'
|
2013-07-14 02:49:40 +02:00
|
|
|
|
2017-10-27 23:21:31 +02:00
|
|
|
FactoryBot.define do
|
2013-07-14 02:49:40 +02:00
|
|
|
factory :supplier do
|
2013-07-15 17:57:20 +02:00
|
|
|
name { Faker::Company.name.truncate(30) }
|
2013-07-14 02:49:40 +02:00
|
|
|
phone { Faker::PhoneNumber.phone_number }
|
|
|
|
address { Faker::Address.street_address }
|
|
|
|
|
2014-11-21 14:37:56 +01:00
|
|
|
transient do
|
2019-10-28 09:40:43 +01:00
|
|
|
article_count { 0 }
|
2013-07-14 02:49:40 +02:00
|
|
|
end
|
|
|
|
|
2023-05-12 13:01:12 +02:00
|
|
|
before :create do |supplier, _evaluator|
|
|
|
|
next if supplier.instance_of?(SharedSupplier)
|
2020-08-01 02:49:15 +02:00
|
|
|
next if supplier.supplier_category_id?
|
2021-03-01 15:27:26 +01:00
|
|
|
|
2020-08-01 02:49:15 +02:00
|
|
|
supplier.supplier_category = create :supplier_category
|
|
|
|
end
|
|
|
|
|
2013-07-14 02:49:40 +02:00
|
|
|
after :create do |supplier, evaluator|
|
2013-07-15 00:17:07 +02:00
|
|
|
article_count = evaluator.article_count
|
2013-07-25 13:21:24 +02:00
|
|
|
article_count = rand(1..99) if article_count == true
|
2023-05-12 13:01:12 +02:00
|
|
|
create_list(:article, article_count, supplier: supplier)
|
2013-07-14 02:49:40 +02:00
|
|
|
end
|
2014-11-21 14:37:56 +01:00
|
|
|
|
2022-02-20 16:15:22 +01:00
|
|
|
factory :shared_supplier, class: 'SharedSupplier'
|
2013-07-14 02:49:40 +02:00
|
|
|
end
|
|
|
|
|
2020-08-01 02:49:15 +02:00
|
|
|
factory :supplier_category do
|
|
|
|
sequence(:name) { |n| Faker::Lorem.characters(number: rand(2..12)) + " ##{n}" }
|
|
|
|
financial_transaction_class
|
|
|
|
end
|
2013-07-14 02:49:40 +02:00
|
|
|
end
|