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
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?
know that DB access is sort of frowned upon, but is this a situation
it is more or less acceptable? My spec looks something like this, but
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’