spec move functionality into factory

This commit is contained in:
wvengen 2013-07-25 11:16:39 +02:00
parent b302cbde4f
commit 7dafcf714a
4 changed files with 22 additions and 12 deletions

View file

@ -2,12 +2,25 @@ require 'factory_girl'
FactoryGirl.define do
# requires articles from single supplier, or supplier (with all its articles)
factory :order do
starts { Time.now }
supplier { FactoryGirl.create :supplier, article_count: (article_count.nil? ? true : article_count) }
article_ids { supplier.articles.map(&:id) unless supplier.nil? }
ignore do
article_count true
end
# for an order from stock; need to add articles
factory :stock_order do
supplier_id 0
# 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
end
end