ruby on rails - Setting a child attribute from parent in FactoryGirl -


how set dependent attribute depends on in factorygirl?

factorygirl.define   factory :line_item     quantity 1     price 30 # want price come product association: self.product.price      cart     order     product   end end 

i tried didn't work:

  factory :line_item |f|     f.quantity 1      f.cart     f.order     f.product     after_build |line_item|       line_item.price = line_item.product.price     end   end 

try this:

factorygirl.define      factory :line_item     quantity 1     price { product.price }      cart     order     product      end  end 

Comments

Popular posts from this blog

php - cannot display multiple markers in google maps v3 from traceroute result -

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -