Это не интуитивно понятно, но в документации factory_girl говорится, как, когда вы ищете 'has_many':
https://github.com/thoughtbot/factory_girl/blob/master/GETTING_STARTED.md
В основном, сначала сделайте еще одну фабрику:
FactoryGirl.define do
factory :item do
name "Macbook"
quantity 1
price 1000
payment_object
end
end
Затем используйте это в своем коде, например:
FactoryGirl.define do
factory :payment_object do
company_id 1
user_id 1
delivery_date (Date.today + 1)
payment_terms 'CBD'
vendor 'Apple'
currency 'USD'
# This is how you reference the list with your items
ignore do
items_count 5 # the number items that should be in the list
end
after(:create) do |payment_object, evaluator|
FactoryGirl.create_list(:item, evaluator.items_count, payment_object: payment_object)
end
end