Unfortunately it fails. I print out “p” in both locations and while
they have all the same data, they have different memory addresses. I
don’t know if this is the explanation for the issue but it’s all I can
find so far.
#participants don’t include the object you created. Rails does a
And then it ought to work.
hth
Pat
r.participants << p didn’t do it, but the “should change” did and I
like that solution best. Court3nay also suggested “r.stub!
(:participants).and_return([p])” which works also.
Thanks for your help, and thanks for the extra destroy_all trick too!
The problem, as you mentioned, is that the objects loaded by #participants don’t include the object you created. Rails does a
“SELECT * FROM participates WHERE room_id=?” and instantiates new
objects.
The first option is to use participants#<< instead of setting the
room. So instead of
p.room = r
you would have
r.partipants << p
And then it ought to work.
Alternatively, since you’re actually hitting the database, you can just
do