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

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

jquery - javascript onscroll fade same class but with different div -