diff options
Diffstat (limited to 'actionpack/test/controller/url_rewriter_test.rb')
-rw-r--r-- | actionpack/test/controller/url_rewriter_test.rb | 41 |
1 files changed, 38 insertions, 3 deletions
diff --git a/actionpack/test/controller/url_rewriter_test.rb b/actionpack/test/controller/url_rewriter_test.rb index 64e9a085ca..e9d372544e 100644 --- a/actionpack/test/controller/url_rewriter_test.rb +++ b/actionpack/test/controller/url_rewriter_test.rb @@ -2,7 +2,7 @@ require 'abstract_unit' ActionController::UrlRewriter -class UrlRewriterTests < Test::Unit::TestCase +class UrlRewriterTests < ActionController::TestCase def setup @request = ActionController::TestRequest.new @params = {} @@ -85,8 +85,7 @@ class UrlRewriterTests < Test::Unit::TestCase end end -class UrlWriterTests < Test::Unit::TestCase - +class UrlWriterTests < ActionController::TestCase class W include ActionController::UrlWriter end @@ -302,6 +301,42 @@ class UrlWriterTests < Test::Unit::TestCase assert_generates("/image", :controller=> :image) end + def test_named_routes_with_nil_keys + ActionController::Routing::Routes.clear! + add_host! + ActionController::Routing::Routes.draw do |map| + map.main '', :controller => 'posts' + map.resources :posts + map.connect ':controller/:action/:id' + end + # We need to create a new class in order to install the new named route. + kls = Class.new { include ActionController::UrlWriter } + controller = kls.new + params = {:action => :index, :controller => :posts, :format => :xml} + assert_equal("http://www.basecamphq.com/posts.xml", controller.send(:url_for, params)) + params[:format] = nil + assert_equal("http://www.basecamphq.com/", controller.send(:url_for, params)) + ensure + ActionController::Routing::Routes.load! + end + + def test_formatted_url_methods_are_deprecated + ActionController::Routing::Routes.draw do |map| + map.resources :posts + end + # We need to create a new class in order to install the new named route. + kls = Class.new { include ActionController::UrlWriter } + controller = kls.new + params = {:id => 1, :format => :xml} + assert_deprecated do + assert_equal("/posts/1.xml", controller.send(:formatted_post_path, params)) + end + assert_deprecated do + assert_equal("/posts/1.xml", controller.send(:formatted_post_path, 1, :xml)) + end + ensure + ActionController::Routing::Routes.load! + end private def extract_params(url) url.split('?', 2).last.split('&') |