在 FactoryGirl 中如何设置依赖的依赖属性?
FactoryGirl.define do
factory :line_item do
quantity 1
price 30 # I want price to come from the product association: self.product.price
cart
order
product
end
end
我试过了,但没有用:
factory :line_item do |f|
f.quantity 1
f.cart
f.order
f.product
after_build do |line_item|
line_item.price = line_item.product.price
end
end