<pclass="important">The content of this post is no longer correct. Please read <ahref="http://ariejan.net/2011/10/09/testing-rails-3-scopes-revisited">this article</a> for details.</p>
Testing scopes has always felt a bit weird to me. Normally I'd do something like this:
This test is okay. It tests if the named scope does what it needs to do. And there's also the problem. Scopes are part of ActiveRecord and are already extensively tested there. All we need to do is check if we _configure_ the scope correctly.
What we need is a way to inspect what `where` and `order` rules are set for a particular scope and make sure those are the correct ones. We can then trust ActiveRecord to keep its promise to execute the proper SQL query for us.
Here's another test that utilizes some Rails 3 methods you may not have heard of before.