Hey guys. I''m having some trouble with a route spec. In routes.rb , I have: map.connect ''foods/search/:name'', :controller => :foods, :action => :search foods_controller_spec.rb has: http://codepad.org/dg3FERKw Unfortunately, that fails: http://codepad.org/lck4r1S0 After reading the rspec-rails 1.2.0 upgrade notes (http://tr.im/K1zx), I haven''t been able to figure out what I''m doing wrong. Any hints? Thanks! Nick PS: I''m using 1.2.9 and Rails 2.3.4 . -- Posted via http://www.ruby-forum.com/.
Nick Hoffman wrote:> Hey guys. I''m having some trouble with a route spec. In routes.rb , I > have: > map.connect ''foods/search/:name'', :controller => :foods, :action => > :search > > foods_controller_spec.rb has: http://codepad.org/dg3FERKw > Unfortunately, that fails: http://codepad.org/lck4r1S0 > > After reading the rspec-rails 1.2.0 upgrade notes (http://tr.im/K1zx), I > haven''t been able to figure out what I''m doing wrong. Any hints? > > Thanks! > Nick > > PS: I''m using 1.2.9 and Rails 2.3.4 .Hi Nick, You need to add quotes while writing in routs.rb file. So your route will be define as : map.connect ''foods/search/:name'', :controller => ''foods'', :action => ''search'' Now try running the code again.You will see it pass. -- Posted via http://www.ruby-forum.com/.
Amit Kulkarni wrote:> Nick Hoffman wrote: >> Hey guys. I''m having some trouble with a route spec. In routes.rb , I >> have: >> map.connect ''foods/search/:name'', :controller => :foods, :action => >> :search >> >> foods_controller_spec.rb has: http://codepad.org/dg3FERKw >> Unfortunately, that fails: http://codepad.org/lck4r1S0 >> >> After reading the rspec-rails 1.2.0 upgrade notes (http://tr.im/K1zx), I >> haven''t been able to figure out what I''m doing wrong. Any hints? >> >> Thanks! >> Nick >> >> PS: I''m using 1.2.9 and Rails 2.3.4 .> Hi Nick, > You need to add quotes while writing in routs.rb file. > So your route will be define as : > map.connect ''foods/search/:name'', :controller => ''foods'', :action => > ''search'' > Now try running the code again.You will see it pass.Thanks for the suggestion, Amit. I changed the symbols to strings. Unfortunately, the same error is still occurring: http://codepad.org/lck4r1S0 -- Posted via http://www.ruby-forum.com/.
On Sun, Jan 10, 2010 at 10:58 PM, Nick Hoffman <lists at ruby-forum.com> wrote:> Hey guys. I''m having some trouble with a route spec. In routes.rb , I > have: > map.connect ''foods/search/:name'', :controller => :foods, :action => > :search > > foods_controller_spec.rb has: http://codepad.org/dg3FERKw > Unfortunately, that fails: http://codepad.org/lck4r1S0 > > After reading the rspec-rails 1.2.0 upgrade notes (http://tr.im/K1zx), I > haven''t been able to figure out what I''m doing wrong. Any hints? >I''d recommend using the route_to matcher that was added in 1.2.9 instead. http://codepad.org/fLcxyA9N http://rspec.rubyforge.org/rspec-rails/1.2.9/classes/Spec/Rails/Matchers.html#M000029 It''s more reliable, and aligns better with the rspec matchers API. Cheers, David> > Thanks! > Nick > > PS: I''m using 1.2.9 and Rails 2.3.4 . > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20100111/f7b5856d/attachment.html>
David Chelimsky wrote:> I''d recommend using the route_to matcher that was added in 1.2.9 > instead. > > http://codepad.org/fLcxyA9N > http://rspec.rubyforge.org/rspec-rails/1.2.9/classes/Spec/Rails/Matchers.html#M000029 > > It''s more reliable, and aligns better with the rspec matchers API. > > Cheers, > DavidThanks for that, David. I updated my spec (http://codepad.org/F828X7Fg). For some reason though, it''s still failing: http://codepad.org/s65Ckubc Just in case, this is what I have in routes.rb: http://codepad.org/rJfIhbM6 There must be some tiny detail that I''m missing here... -- Posted via http://www.ruby-forum.com/.
On 1/11/10 9:22 PM, Nick Hoffman wrote:> David Chelimsky wrote: > >> I''d recommend using the route_to matcher that was added in 1.2.9 >> instead. >> >> http://codepad.org/fLcxyA9N >> http://rspec.rubyforge.org/rspec-rails/1.2.9/classes/Spec/Rails/Matchers.html#M000029 >> >> It''s more reliable, and aligns better with the rspec matchers API. >> >> Cheers, >> David >> > Thanks for that, David. I updated my spec (http://codepad.org/F828X7Fg). > For some reason though, it''s still failing: http://codepad.org/s65Ckubc > > Just in case, this is what I have in routes.rb: > http://codepad.org/rJfIhbM6 > > There must be some tiny detail that I''m missing here... >Yes, there must. I think you''ve tried to twice define the route, and the test shows you which one actually is being used. I''ll suggest commenting out one of those routes at a time, and see whether the new test results are illuminating. Randy
Randy Harmon wrote:> On 1/11/10 9:22 PM, Nick Hoffman wrote: >>> Cheers, >>> David >>> >> Thanks for that, David. I updated my spec (http://codepad.org/F828X7Fg). >> For some reason though, it''s still failing: http://codepad.org/s65Ckubc >> >> Just in case, this is what I have in routes.rb: >> http://codepad.org/rJfIhbM6 >> >> There must be some tiny detail that I''m missing here... >> > Yes, there must. I think you''ve tried to twice define the route, and > the test shows you which one actually is being used. I''ll suggest > commenting out one of those routes at a time, and see whether the new > test results are illuminating. > > RandyI swapped the order of the 2 lines in routes.rb to this: map.connect ''foods/search/:name'', :controller => ''foods'', :action => ''search'' map.resources :foods, :collection => {:search => :get} and the spec passes now. Thanks, guys! -- Posted via http://www.ruby-forum.com/.
By the way, does this spec: {:get => ''/path''}.should route_to(...) make this spec redundant?: params_from(:get, ''/path'').should == {...} They read the same, but it feels like they each check one end of the route''s translation. -- Posted via http://www.ruby-forum.com/.
On Tue, Jan 12, 2010 at 11:35 AM, Nick Hoffman <lists at ruby-forum.com> wrote:> By the way, does this spec: > {:get => ''/path''}.should route_to(...) > make this spec redundant?: > params_from(:get, ''/path'').should == {...} >Yes - route_to checks both sides of the translation.> They read the same, but it feels like they each check one end of the > route''s translation. > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20100113/5158766f/attachment.html>
David Chelimsky wrote:> On Tue, Jan 12, 2010 at 11:35 AM, Nick Hoffman <lists at ruby-forum.com> > wrote: > >> By the way, does this spec: >> {:get => ''/path''}.should route_to(...) >> make this spec redundant?: >> params_from(:get, ''/path'').should == {...} >> > > Yes - route_to checks both sides of the translation.Great, thanks for that, David! And thanks again for all of your sweat and blood with RSpec and RSpec-Rails! -- Posted via http://www.ruby-forum.com/.
On Wed, Jan 13, 2010 at 10:20 AM, Nick Hoffman <lists at ruby-forum.com> wrote:> David Chelimsky wrote: > > On Tue, Jan 12, 2010 at 11:35 AM, Nick Hoffman <lists at ruby-forum.com> > > wrote: > > > >> By the way, does this spec: > >> {:get => ''/path''}.should route_to(...) > >> make this spec redundant?: > >> params_from(:get, ''/path'').should == {...} > >> > > > > Yes - route_to checks both sides of the translation. > > Great, thanks for that, David!Thank Randy Harmon for this one. It was he who recognized and solved the problems with params_from by adding the route_to matcher.> And thanks again for all of your sweat > and blood with RSpec and RSpec-Rails! >It''s a labor of love, but you''re welcome :) -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20100113/b09680ec/attachment.html>
David Chelimsky wrote:> On Wed, Jan 13, 2010 at 10:20 AM, Nick Hoffman <lists at ruby-forum.com> > wrote: > >> > Yes - route_to checks both sides of the translation. >> >> Great, thanks for that, David! > > > Thank Randy Harmon for this one. It was he who recognized and solved > the > problems with params_from by adding the route_to matcher.Whoops, you''re right. Thanks, Randy! -- Posted via http://www.ruby-forum.com/.
Hey guys. I have two different paths that lead to the same controller and action: map.connect ''foods/search/:name'', :controller => ''foods'', :action => ''search'' map.food '':name'', :controller => ''foods'', :action => ''search'' Unfortunately, the spec for the second route fails because #route_to finds and uses the first route when generating the path for :controller => ''foods'', :action => ''search'', :name => ''almonds'' routes.rb: http://codepad.org/CjKRynr5 specs: http://codepad.org/838oV3mW Is there a solution to this problem? Thanks, Nick -- Posted via http://www.ruby-forum.com/.
I guess the distinction is that you generate food_path()''s based on existing food names, and search comes from users - but you don''t have a distinct landing page for each food, hence no need for resource-based routing for foods. You could define a :show action in your controller, which simply calls the ''search'' action. def show search end Then they''ll have different controller-actions and different paths, yet the implementations would be identical. And the specs can describe them distinctly. I''d be curious if there are other ways to do this. Randy On 1/23/10 7:24 PM, Nick Hoffman wrote:> Hey guys. I have two different paths that lead to the same controller > and action: > map.connect ''foods/search/:name'', :controller => ''foods'', :action => > ''search'' > map.food '':name'', :controller => ''foods'', :action => > ''search'' > > Unfortunately, the spec for the second route fails because #route_to > finds and uses the first route when generating the path for > :controller => ''foods'', :action => ''search'', :name => ''almonds'' > > routes.rb: http://codepad.org/CjKRynr5 > specs: http://codepad.org/838oV3mW > > Is there a solution to this problem? > > Thanks, > Nick >