Brandon Olivares
2009-Apr-10 05:08 UTC
[rspec-users] route_for testing multiple request methods
Hi, I''m trying to use route_for to test my routes. I have two routes that have the same path, but different request methods. map.with_options :controller => ''contact'' do |c| c.contact ''contact.html'', :action => ''index'', :conditions => {:method => :get} c.process_contact_form ''contact.html'', :action => ''process_form'', :conditions => {:method => :post} End My test is: it "should map {:controller => ''contact'', :action => ''process_form''} to /contact.html" do route_for(:controller => ''contact'', :action => ''process_form'').should = ''/contact.html'' end # it should map {:controller => ''contact'', :action => ''process_form''} to /contact.html The error: Test::Unit::AssertionFailedError in ''ContactController route generation should map {:controller => ''contact'', :action => ''process_form''} to /contact.html'' The recognized options <{"action"=>"index", "controller"=>"contact"}> did not match <{"action"=>"process_form", "controller"=>"contact"}>, difference: <{"action"=>"process_form"}> Is this a bug, or am I doing something wrong? It works when I use assert_generates, so I think the routes are correct. Brandon
David Chelimsky
2009-Apr-10 06:49 UTC
[rspec-users] route_for testing multiple request methods
On Fri, Apr 10, 2009 at 2:08 AM, Brandon Olivares <programmer2188 at gmail.com> wrote:> Hi, > > I''m trying to use route_for to test my routes. I have two routes that have > the same path, but different request methods. > > map.with_options :controller => ''contact'' do |c| > ?c.contact ''contact.html'', :action => ''index'', > ?:conditions => {:method => :get} > ?c.process_contact_form ''contact.html'', :action => ''process_form'', > ?:conditions => {:method => :post} > End > > My test is: > > ? ?it "should map ?{:controller => ''contact'', :action => ''process_form''} to > /contact.html" do > ? ? ?route_for(:controller => ''contact'', :action => ''process_form'').should > => ? ? ?''/contact.html'' > ? ?end # it should map ?{:controller => ''contact'', :action => > ''process_form''} to /contact.html > > The error: > > Test::Unit::AssertionFailedError in ''ContactController route generation > should map ?{:controller => ''contact'', :action => ''process_form''} to > /contact.html'' > The recognized options <{"action"=>"index", "controller"=>"contact"}> did > not match <{"action"=>"process_form", "controller"=>"contact"}>, difference: > <{"action"=>"process_form"}> > > Is this a bug, or am I doing something wrong? It works when I use > assert_generates, so I think the routes are correct.assert_recognizes, however, will fail in the same way :) Try: route_for(:controller => ''contact'', :action => ''index'') .should == {:path => ''/contact.html'', :method => :get} route_for(:controller => ''contact'', :action => ''process_form'') .should == {:path => ''/contact.html'', :method => :post} The default is :method => :get, so the first doesn''t require the :method in the hash: route_for(:controller => ''contact'', :action => ''index'') .should == :method => :get> > Brandon > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >