On 1 December 2010 20:15, Marnen Laibow-Koser <[email protected]> wrote: > Colin Law wrote in post #965435: >> Hi >> I have a named scope that sets a sort order. In my unit test I can >> run the query on a set of records (using Factory or fixtures) and >> check the sort order is correct. I believe though that a find without >> an explicit sort order may return the records in any order, so how can >> I be sure that it is not just accidental that they are in the correct >> order? > > Try creating the factories in a weird order. If they still are returned > in the correct order, then your sorting is correct.
Probably. I may be wrong but I believe that postgreSQL does not even guarantee that an unordered query will produce the same results if the same query is run twice. Conceivably therefore I could test without the order clause and check it fails, then, thinking I had added the order clause re-run the test and find it pass. I think though as I said in an earlier post that I can use common sense and assume the probability of this is so small as to be insignificant. > > ...or... > > Write the test so that it checks that the appropriate :order clause is > set. This is probably too invasive and implementation-dependent for my > taste, though I might do it occasionally. I agree this seems like overkill and would likely be fragile. Colin -- 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.

