Topic: Testing a find through association
Guys,
I've got a controller action that does a find for all for all of the solutions owned by a user in the following way, which I have tested with RSpec.
def index
@solutions = Solution.find(:all, :conditions => {:user_id => @user.id})
endwith the corresponding RSpec test:
it "should find all of the solutions owned by a user" do
Solution.should_receive(:find).with(:all, :conditions => {:user_id => @user.id}).and_return(@solutions)
get :index, :user_id => @user.id
endHowever, I'd really like to use a find through association in my index action like this:
def index
@solutions = @user.solutions.find(:all)
endso that its easier to read and more elegant, except I can't for the life of me figure out how I can write a spec that will test that correctly.
Can anybody point me in the right direction?
Joe
Synantus Designs