2017-10-27 23:21:31 +02:00
|
|
|
require 'factory_bot'
|
2013-07-15 00:17:07 +02:00
|
|
|
|
2017-10-27 23:21:31 +02:00
|
|
|
FactoryBot.define do
|
2013-07-15 00:17:07 +02:00
|
|
|
factory :order do
|
|
|
|
starts { Time.now }
|
2023-05-12 13:01:12 +02:00
|
|
|
supplier { create(:supplier, article_count: (article_count.nil? ? true : article_count)) }
|
2013-07-25 11:16:39 +02:00
|
|
|
article_ids { supplier.articles.map(&:id) unless supplier.nil? }
|
2023-05-12 13:01:12 +02:00
|
|
|
created_by { create(:user) }
|
|
|
|
updated_by { create(:user) }
|
2013-07-15 00:17:07 +02:00
|
|
|
|
2014-11-21 14:37:56 +01:00
|
|
|
transient do
|
2019-10-28 09:40:43 +01:00
|
|
|
article_count { true }
|
2013-07-25 11:16:39 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
# for an order from stock; need to add articles
|
2013-07-15 00:17:07 +02:00
|
|
|
factory :stock_order do
|
2019-10-28 09:40:43 +01:00
|
|
|
supplier_id { 0 }
|
2013-07-25 11:16:39 +02:00
|
|
|
# article_ids needs to be supplied
|
|
|
|
end
|
|
|
|
|
|
|
|
# In the order's after_save callback order articles are created, so
|
|
|
|
# until the order is saved, these articles do not yet exist.
|
|
|
|
after :create do |order|
|
|
|
|
order.reload
|
2013-07-15 00:17:07 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|