I think it comes down to where your test boundaries are.

If you're just testing your interaction with ActiveRecord's API, and relying on 
its test suites to cover the rest, then checking `relation.order_values` sounds 
like the way to go.

If you feel it's important to test the end-to-end behaviour, then you'll need 
to create objects in the database and query them, verifying the returned order.

I avoid coupling my tests to Rails and/or the database as much as possible, but 
I'd take the latter option if this ordering is a core part of a feature you're 
testing. This is mainly because I find ActiveRecord's API completely 
incoherent, and unsuitable as a test boundary.

— Paul




On 14/08/2012, at 2:10 PM, Dmytrii Nagirniak <[email protected]> wrote:

> 
> On 14 August 2012 14:04, Ryan Bigg <[email protected]> wrote:
> You can do it without dropping back down to SQL. Just check `order_values` on 
> the ActiveRecord::Relation object returned. 
> 
> Good idea, thanks. But that would be pretty close to the option 1.
> I would just do `query.order_values.should ...` instead of ugly 
> `query.to_sql.should match ....`
> 
> It'll work for simple things though.
> 

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
or Rails Oceania" 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/rails-oceania?hl=en.

Reply via email to