From 7c5045452960c03354438377b524730dcda4df75 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Strza=C5=82kowski?= Date: Fri, 6 Aug 2010 09:28:07 +0200 Subject: Test for recognizing routes with http method set --- actionpack/test/controller/routing_test.rb | 41 +++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) (limited to 'actionpack/test/controller') diff --git a/actionpack/test/controller/routing_test.rb b/actionpack/test/controller/routing_test.rb index 164fceeda5..58c584b331 100644 --- a/actionpack/test/controller/routing_test.rb +++ b/actionpack/test/controller/routing_test.rb @@ -921,6 +921,45 @@ class RouteSetTest < ActiveSupport::TestCase assert_equal({:controller => 'pages', :action => 'show', :id => 'hello+world'}, set.recognize_path('/page/hello+world')) end + def test_recognize_with_http_methods + set.draw do + get "/people" => "people#index", :as => "people" + post "/people" => "people#create" + get "/people/:id" => "people#show", :as => "person" + put "/people/:id" => "people#update" + delete "/people/:id" => "people#destroy" + end + + params = set.recognize_path("/people", :method => :get) + assert_equal("index", params[:action]) + + params = set.recognize_path("/people", :method => :post) + assert_equal("create", params[:action]) + + params = set.recognize_path("/people/5", :method => :put) + assert_equal("update", params[:action]) + + assert_raise(ActionController::RoutingError) { + set.recognize_path("/people", :method => :bacon) + } + + params = set.recognize_path("/people/5", :method => :get) + assert_equal("show", params[:action]) + assert_equal("5", params[:id]) + + params = set.recognize_path("/people/5", :method => :put) + assert_equal("update", params[:action]) + assert_equal("5", params[:id]) + + params = set.recognize_path("/people/5", :method => :delete) + assert_equal("destroy", params[:action]) + assert_equal("5", params[:id]) + + assert_raise(ActionController::RoutingError) { + set.recognize_path("/people/5", :method => :post) + } + end + def test_recognize_with_alias_in_conditions set.draw do match "/people" => 'people#index', :as => 'people', @@ -1585,7 +1624,7 @@ class RackMountIntegrationTests < ActiveSupport::TestCase match '', :controller => 'news', :format => nil match 'news(.:format)', :controller => 'news' - match + match 'comment/:id/:action', :controller => 'comments', :action => 'show' match 'ws/:controller/:action/:id', :ws => true match 'account/:action', :controller => :account, :action => :subscription -- cgit v1.2.3