I can’t figure out what I do wrong there, I have a nested controller
which is defined as a singular resource, the routing works properly,
but inside my specs the request never goes through the show action.
I keep on getting this error :
Spec::Mocks::MockExpectationError in ‘Surveys::ReportController should
return the survey corresponding to the report’
Mock ‘Class’ expected :find with (any args) once, but received it 0
times
In my specs :
require File.expand_path(File.dirname(FILE) + ‘/…/…/
spec_helper’)
describe Surveys::ReportController do
it “should return the survey corresponding to the report” do
Survey.should_receive(:find)
get :show, :survey_id=>“34”
end
end
In route.rb :
map.resources :surveys do |survey|
survey.resource :report, :controller =>‘surveys/report’
end
In controller/surveys/report_controller.rb :
class Surveys::ReportController < ApplicationController
def show @survey = Survey.find(params[:survey_id])
On Thu, Jul 31, 2008 at 5:21 PM, aslak hellesoy [email protected] wrote:
times
Try:
get :show, :id=>“34”
Sorry, I was too quick. It sounds like your params don’t match the
routes you want.
Try rake routes, and also try to spec the routing in the associated
routing_spec.rb.
Thanks for your help Aslak, but I still didn’t manage to make it pass
get :show, :id=>“34”
it sends me this error then : No route matches
{:action=>“show”, :controller=>“surveys/report”, :id=>“34”}
Try rake routes, and also try to spec the routing in the associated
routing_spec.rb.
and this test passes :
it “should map { :controller => ‘report’, :action =>
‘show’, :survey_id => 1} to /survey/1/report” do
route_for(:controller => “surveys/report”, :action =>
“show”, :survey_id => 1).should == “/surveys/1/report”
end
also if I try to remove my condition the test passes so the routes
must be correct
it “should return the survey corresponding to the report” do #Survey.should_receive(:find)
get :show, :survey_id=>“34”, :controller =>“surveys/report”
end
Thanks for your help Aslak, but I still didn’t manage to make it pass
get :show, :id=>“34”
it sends me this error then : No route matches
{:action=>“show”, :controller=>“surveys/report”, :id=>“34”}
What’s your controller’s name? In Rails, all resource controller
names are plural, even singleton resources. So your controller should
be Surveys::ReportsController.
and this test passes : #Survey.should_receive(:find)
get :show, :survey_id=>“34”, :controller =>“surveys/report”
end
Actually, that’s a sign that you’re not hitting the desired #show
method. Survey.find(“34”) will fail with RecordNotFound unless you
have a survey with id=34 in your test db (unlikely).
Any other idea ?
Maybe you have a filter in your controller that prevents show from
being called? I’d resort to some good old puts debugging…