0

Given an order object in a webshop that normally updates its total price each time a booking (a product_order jointable object) is made, how would I make this happen in FactoryGirl.

I was simply thinking something like this, where order.sum_all_bookings does the updating of the order object:

FactoryGirl.define do
  factory :booking do
    product_name 'Honeyjar 400 ml'
    product_quantity '1'
    product_price '3,99'
    order

    after(:create) do |booking|
      booking.order.sum_all_bookings
    end
  end
end

Unfortunately nothing changes in the order object.

Code-MonKy
  • 2,026
  • 2
  • 14
  • 27
  • I suggest to try and search on google before posting a question here. Anyhow, I'm assuming the relation between `product` and `order` is `has_many through` and `booking`is the joint table object, you can go through following links. - http://stackoverflow.com/questions/14444878/factory-girl-how-to-setup-a-has-many-through-association - http://nepalonrails.com/blog/2014/09/factory-girl-traits-and-list-for-has-many-through-relation – Pramod Nov 13 '16 at 14:49
  • I have been on this for several days already. The problem is that a booking is a join table object. Non of your links seem to work for that after trying, and seeing it as a has_many object also doesn't work for changing the total column in the order. I even set out a bounty for this: http://stackoverflow.com/questions/40509943/how-to-make-a-factorygirl-create-affect-another-records-attribute – Code-MonKy Nov 14 '16 at 10:34

0 Answers0