Topic: Cant make my test to work...
I have this class:
class ForSale < ActiveRecord::Base
def sold!(sold_at = DateTime.now)
self.sold_on = sold_at
user.reload #<-------this doesnt work????
false #add error message
and this unit test:
guy = users(:guy)
assert_equal 0, guy.sales.size
#guy.reload <--- this is the problematic line!!!!
assert_equal 1, guy.sales.size
My last assertion doesnt work unless I reload the variable (commented line). So here are my questions:
- is there a better way to do the sold! function?
- why the user.reload code doesnt seem to work, but if I call reload on the User object (guy) it works.
- logicaly, keeping the User up to date when an item is sold should be the job of the ForSale class. So how can I do this?
Thanks a lot!