On Oct 16, 1:31 am, mojo <[email protected]> wrote: > def test_should_have_a_votes_association > assert_equal [ votes(:one), votes(:two) ], stories(:one).votes > end > > $ rake test:units > > The output of assert return failure. So I do trial-and-error fix and > manage to fix it by swap the position of votes(:one) and votes(:two) > order so the test method become: > assert_equal [ votes(:two), votes(:one) ], stories(:one).votes > Can some Rails experts explain to me why the order of vote inside the > array could affect the assert_equal measure? > Thank you so much
because arrays are fundamentally ordered collections so for an array == means same elements and in the same order. Whenever you get something out of the database and there is no order clause (eg if you do Vote.all, or the association you have here) the database is free to return stuff in any order it wants to. Quite often it will be mostly the same order each time but you shouldn't rely on that (more often than not it will something to do with the order things are stored in on disk. Fred --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---

