[rspec-users] Spec custom finders
vertebrate at gmail.com
Fri Oct 26 12:46:08 EDT 2007
I have some finders in my models where I write some of the sql myself. I
of course want to test these, but am not sure the best way. Should I just
let them roll through to the db, and verify they return the correct
objects based on the fixtures I load, or should I spec the actual query? I
know that DB access is sort of frowned upon, but is this a situation where
it is more or less acceptable? My spec looks something like this, but just
feels funny because I'm essentially rewriting the query.
describe User, 'when calling find_by_username' do
it 'should convert the username to lowercase' do
uname = 'Joe'
it 'should call find with custom options' do
User.should_receive(:find) do |a, b|
a.should == :first
b[:conditions].should == "lower(username) = :username"
b[:conditions][:username].should == 'joe'
More information about the rspec-users