Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Test for recognizing routes with http method set

  • Loading branch information...
commit 7c5045452960c03354438377b524730dcda4df75 1 parent 8412886
@strzalek strzalek authored drogus committed
Showing with 40 additions and 1 deletion.
  1. +40 −1 actionpack/test/controller/routing_test.rb
View
41 actionpack/test/controller/routing_test.rb
@@ -921,6 +921,45 @@ def test_recognize_with_encoded_id_and_regex
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
Please sign in to comment.
Something went wrong with that request. Please try again.