Can't access actions of a singular nested resource

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])

respond_to do |format|
  format.html
  format.xml
end

end

end

On Thu, Jul 31, 2008 at 4:06 PM, Bastien [email protected]
wrote:

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”

Try:

get :show, :id=>“34”

Aslak

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.

Aslak

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

Any other idea ?

On Fri, Aug 1, 2008 at 4:41 AM, Bastien [email protected]
wrote:

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.

Pat

On Fri, Aug 1, 2008 at 10:41 AM, Bastien [email protected]
wrote:

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…

BTW, I just committed some specs based on your code, and they pass:
http://github.com/dchelimsky/rspec-dev/commit/9a7ce9ce371b1136380e97e34d33397966734b0f

Aslak

Zach,

Rails 2.1
Rspec 1.1.4

What does your spec look like?

Thanks,
James

On Mon, Aug 4, 2008 at 12:59 PM, J2M removed_emai[email protected] wrote:

Zach,

Rails 2.1
Rspec 1.1.4

What does your spec look like?

http://gist.github.com/3651


Zach D.
http://www.continuousthinking.com
http://www.mutuallyhuman.com

Bastien,

What version of Rails and rspec are you using? Using a singular
resource like you presented works just fine for me,

Zach

On Thu, Jul 31, 2008 at 10:06 AM, Bastien [email protected]
wrote:

end
@survey = Survey.find(params[:survey_id])
[email protected]
http://rubyforge.org/mailman/listinfo/rspec-users


Zach D.
http://www.continuousthinking.com
http://www.mutuallyhuman.com

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs