[rspec-users] Controller spec: testing that scope is set

Tom Stuart tom at experthuman.com
Mon Apr 20 03:59:43 EDT 2009

On 20 Apr 2009, at 02:57, Michael Schuerig wrote:
> I'd rather check that a particular scope is in effect for a call to
> #find. Just as I said. ;-)

As is always the case with spec'ing Rails, I don't know which level of  
abstraction is the right one to check, but it seems like what you're  
asking for is literally:

Person.should_receive(:all) do
   find_scope = Person.send(:scope, :find)
   find_scope[:conditions].should == { name => ["LOWER(firstname || '  
' || lastname) = LOWER(?)", 'Dav%'] }
   find_scope[:order].should == { :name => "lastname ASC, firstname  
ASC" }

However this is obviously getting your hands a bit dirty with Rails  
guts -- I suspect others would suggest that you just set an  
expectation on with_scope and be done with it (or just load some  
fixtures, let the find hit the database, and make sure you get the  
right records back? presumably that's wrong in another way, as is  


More information about the rspec-users mailing list