When I learned about proxy_options I started using it to test all my named scopes. But then I found myself simply copying the conditions hash straight from the model, so it wasn't really testing the correctness of the results:
po = {:conditions => "foo.created_at <= '#{Time.now.beginning_of_week}'"}
assert_equal po, Foo.created_this_week
Another approach is to come up with positive and negative examples and see if they are included in the results or not:
this_week = Foo.make(:created_at => Time.now)
last_week = Foo.make(:created_at => 1.week.ago)
assert Foo.created_this_week.include?(this_week)
assert !Foo.created_this_week.include?(last_week)
But this doesn't do a good job of checking the boundaries and when things get more complicated you'll have a whole long list of assert includes?. It seems it would be nicer to come up with an expected set of results and then just check to make sure it matches:
Foo.make(:created_at => 1.week.ago)
results = [Foo.make(:created_at => Time.now)]
assert_equal results, Foo.created_this_week
But then the test might fail if the results are returned in a different order than you supplied. I guess you could implement <=> in your model so you could sort both arrays. But it seems like that shouldn't really be neccessary. Is there a better way to test these kinds of search methods? Or at least a generally accepted right way?