Bastien
2008-Jul-31 14:06 UTC
[rspec-users] 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
aslak hellesoy
2008-Jul-31 15:21 UTC
[rspec-users] Can''t access actions of a singular nested resource
On Thu, Jul 31, 2008 at 4:06 PM, Bastien <bastien.vaucher at gmail.com> wrote:> 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"Try: get :show, :id=>"34" Aslak> 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 > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >
aslak hellesoy
2008-Jul-31 15:23 UTC
[rspec-users] Can''t access actions of a singular nested resource
On Thu, Jul 31, 2008 at 5:21 PM, aslak hellesoy <aslak.hellesoy at gmail.com> wrote:> On Thu, Jul 31, 2008 at 4:06 PM, Bastien <bastien.vaucher at gmail.com> wrote: >> 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" > > 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> Aslak > >> 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 >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users >> >
Bastien
2008-Aug-01 08:41 UTC
[rspec-users] Can''t access actions of a singular nested resource
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 ?
aslak hellesoy
2008-Aug-01 10:39 UTC
[rspec-users] Can''t access actions of a singular nested resource
On Fri, Aug 1, 2008 at 10:41 AM, Bastien <bastien.vaucher at gmail.com> 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"} > >>> 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 >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> _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >
Pat Maddox
2008-Aug-03 15:44 UTC
[rspec-users] Can''t access actions of a singular nested resource
On Fri, Aug 1, 2008 at 4:41 AM, Bastien <bastien.vaucher at gmail.com> 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
Zach Dennis
2008-Aug-04 14:12 UTC
[rspec-users] Can''t access actions of a singular nested resource
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 <bastien.vaucher at gmail.com> wrote:> 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 > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >-- Zach Dennis http://www.continuousthinking.com http://www.mutuallyhuman.com
J2M
2008-Aug-04 16:59 UTC
[rspec-users] Can''t access actions of a singular nested resource
Zach, Rails 2.1 Rspec 1.1.4 What does your spec look like? Thanks, James On Aug 4, 3:12?pm, "Zach Dennis" <zach.den... at gmail.com> wrote:> 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 <bastien.vauc... at gmail.com> wrote: > > 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 > > _______________________________________________ > > rspec-users mailing list > > rspec-us... at rubyforge.org > >http://rubyforge.org/mailman/listinfo/rspec-users > > -- > Zach Dennishttp://www.continuousthinking.comhttp://www.mutuallyhuman.com > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users
Zach Dennis
2008-Aug-04 17:43 UTC
[rspec-users] Can''t access actions of a singular nested resource
On Mon, Aug 4, 2008 at 12:59 PM, J2M <james2mccarthy at gmail.com> wrote:> Zach, > > Rails 2.1 > Rspec 1.1.4 > > What does your spec look like? >http://gist.github.com/3651 -- Zach Dennis http://www.continuousthinking.com http://www.mutuallyhuman.com