Re: assert_equal Test - how to test updates

Frederick Cheung
Wed, 03 Feb 2010 08:25:27 -0000

On Feb 3, 4:21 am, vihrao <vih...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:
> assert_equal uses the == method to compare the two objects, and  == on
> activerecord doesn''t compare attributes: it only compares the id
of
> the object (ie do the compared objects represent the same row in the
> database)
>

A small addition: it obviously also compares class and there''s some
fiddly stuff around handling the cases of unsaved
objects
>
> --
> That is why I had this issue. I had two fixtures users.yml and gusers.yml.
> Both had ''bob'' defined with same record ID. Now users.yml
was referred by
> user controller and gusers.yml was referred by gusers controller. However
> when I did assert_equal using gusers it pulled the record from the users
> model instead of gusers model. I could not understand that behavior.
> When I changed the gusers.yml ''bob'' to
''bob1'' it pulled the record from the
> correct gusers model.
>
> This tell me that we have make sure IDs are unique across fixtures from
> different models. That is confusing each model has to have its own space.

if you are using instantiated fixtures, then yes, each fixture needs
its own label, but no one does that any more. If you want the bob
fixture from users write users(:bob) and for the other one gusers
(:bob)

Fred
>
> --
> View this message in
context:http://old.nabble.com/assert_equal-Test---how-to-test-updates-tp27424...
> Sent from the RubyOnRails Users mailing list archive at Nabble.com.