ruby - FactoryGirl create_list pass in multiple values -
if have factory:
factory :product, class: product name { faker::commerce.product_name } description { faker::lorem.paragraph } price { faker::number.number(3) } end i can use create_list create 2 products this:
factorygirl.create_list(:product, 2) but want pass in defaults both products, suppose theoretically this?:
prods = [{:name => "product 1"},{:name => "product 2"}] factorygirl.create_list(:product, prods.count, prods) i have searched while , cannot find answer this, possible using elegant solution create_list?
the reason solution because :product 1 of many child associations parent model. configurable way generate parent model factory through single factorygirl.create command , pass in values child associations (through use of factorygirl's traits , ignore blocks). hope makes sense. show bunch of code here believe provides enough context?
you can generate list yourself:
data = [{:name => "product 1"},{:name => "product 2"}] products = data.map { |p| factorygirl.create(:product, p) } which should leave array of products.
Comments
Post a Comment