From a83ac48501aaba12b3d8abc0c6d6fdf0155de74d Mon Sep 17 00:00:00 2001 From: Luke Redpath Date: Thu, 5 Jun 2008 13:20:54 +0100 Subject: [PATCH] Fix url_for with no arguments when default_url_options is not explicitly defined. [#339 state:resolved] Signed-off-by: Pratik Naik --- actionpack/lib/action_controller/base.rb | 4 ++-- actionpack/test/controller/base_test.rb | 18 +++++++++++++++++- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/actionpack/lib/action_controller/base.rb b/actionpack/lib/action_controller/base.rb index a036600c2bbcc..0efc99fdade08 100755 --- a/actionpack/lib/action_controller/base.rb +++ b/actionpack/lib/action_controller/base.rb @@ -613,8 +613,8 @@ def process(request, response, method = :perform_action, *arguments) #:nodoc: # # This takes the current URL as is and only exchanges the action. In contrast, url_for :action => 'print' # would have slashed-off the path components after the changed action. - def url_for(options = nil) #:doc: - case options || {} + def url_for(options = {}) #:doc: + case options when String options when Hash diff --git a/actionpack/test/controller/base_test.rb b/actionpack/test/controller/base_test.rb index b28717597e555..34c0200fe86ed 100644 --- a/actionpack/test/controller/base_test.rb +++ b/actionpack/test/controller/base_test.rb @@ -169,6 +169,22 @@ def test_default_url_options_are_used_if_set end end +class EmptyUrlOptionsTest < Test::Unit::TestCase + def setup + @controller = NonEmptyController.new + + @request = ActionController::TestRequest.new + @response = ActionController::TestResponse.new + + @request.host = 'www.example.com' + end + + def test_ensure_url_for_works_as_expected_when_called_with_no_options_if_default_url_options_is_not_set + get :public_action + assert_equal "http://www.example.com/non_empty/public_action", @controller.url_for + end +end + class EnsureNamedRoutesWorksTicket22BugTest < Test::Unit::TestCase def test_named_routes_still_work ActionController::Routing::Routes.draw do |map| @@ -180,4 +196,4 @@ def test_named_routes_still_work ensure ActionController::Routing::Routes.load! end -end \ No newline at end of file +end