From d9f3c435f907b8097669a7f2c923f731837fb045 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Sun, 7 Oct 2007 19:12:02 +0000 Subject: Fix url_for, redirect_to, etc. with :controller => :symbol instead of 'string'. Closes #8562, #9525. git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@7776 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- actionpack/CHANGELOG | 2 ++ .../lib/action_controller/assertions/response_assertions.rb | 3 ++- actionpack/lib/action_controller/routing.rb | 3 +++ actionpack/test/controller/action_pack_assertions_test.rb | 13 +++++++++++++ actionpack/test/controller/url_rewriter_test.rb | 4 ++++ 5 files changed, 24 insertions(+), 1 deletion(-) (limited to 'actionpack') diff --git a/actionpack/CHANGELOG b/actionpack/CHANGELOG index 6e0832cfdb..01e560f79d 100644 --- a/actionpack/CHANGELOG +++ b/actionpack/CHANGELOG @@ -1,5 +1,7 @@ *SVN* +* Fix url_for, redirect_to, etc. with :controller => :symbol instead of 'string'. #8562, #9525 [Justin Lynn, Tarmo Tänav, shoe] + * Use #require_library_or_gem to load the memcache library for the MemCache session and fragment cache stores. Closes #8662. [Rick] * Move ActionController::Routing.optimise_named_routes to ActionController::Base.optimise_named_routes. Now you can set it in the config. [Rick] diff --git a/actionpack/lib/action_controller/assertions/response_assertions.rb b/actionpack/lib/action_controller/assertions/response_assertions.rb index f45727f508..4108695f07 100644 --- a/actionpack/lib/action_controller/assertions/response_assertions.rb +++ b/actionpack/lib/action_controller/assertions/response_assertions.rb @@ -69,6 +69,7 @@ module ActionController end if value.respond_to?(:[]) && value['controller'] + value['controller'] = value['controller'].to_s if key == :actual && value['controller'].first != '/' && !value['controller'].include?('/') new_controller_path = ActionController::Routing.controller_relative_to(value['controller'], @controller.class.controller_path) value['controller'] = new_controller_path if value['controller'] != new_controller_path && ActionController::Routing.possible_controllers.include?(new_controller_path) @@ -138,4 +139,4 @@ module ActionController end end end -end \ No newline at end of file +end diff --git a/actionpack/lib/action_controller/routing.rb b/actionpack/lib/action_controller/routing.rb index 7442adbb39..3a4d2aafe3 100644 --- a/actionpack/lib/action_controller/routing.rb +++ b/actionpack/lib/action_controller/routing.rb @@ -1325,6 +1325,9 @@ module ActionController options = options_as_params(options) expire_on = build_expiry(options, recall) + if options[:controller] + options[:controller] = options[:controller].to_s + end # if the controller has changed, make sure it changes relative to the # current controller module, if any. In other words, if we're currently # on admin/get, and the new controller is 'set', the new controller diff --git a/actionpack/test/controller/action_pack_assertions_test.rb b/actionpack/test/controller/action_pack_assertions_test.rb index 75d0e17f61..1eb9610d04 100644 --- a/actionpack/test/controller/action_pack_assertions_test.rb +++ b/actionpack/test/controller/action_pack_assertions_test.rb @@ -19,6 +19,8 @@ class ActionPackAssertionsController < ActionController::Base def redirect_to_controller() redirect_to :controller => "elsewhere", :action => "flash_me"; end + def redirect_to_controller_with_symbol() redirect_to :controller => :elsewhere, :action => :flash_me; end + def redirect_to_path() redirect_to '/some/path' end def redirect_to_named_route() redirect_to route_one_url end @@ -429,6 +431,17 @@ class ActionPackAssertionsControllerTest < Test::Unit::TestCase assert_redirected_to 'http://test.host/some/path' end + def test_assert_redirection_with_symbol + process :redirect_to_controller_with_symbol + assert_nothing_raised { + assert_redirected_to :controller => "elsewhere", :action => "flash_me" + } + process :redirect_to_controller_with_symbol + assert_nothing_raised { + assert_redirected_to :controller => :elsewhere, :action => :flash_me + } + end + def test_redirected_to_with_nested_controller @controller = Admin::InnerModuleController.new get :redirect_to_absolute_controller diff --git a/actionpack/test/controller/url_rewriter_test.rb b/actionpack/test/controller/url_rewriter_test.rb index 3c1d584d89..75497c832c 100644 --- a/actionpack/test/controller/url_rewriter_test.rb +++ b/actionpack/test/controller/url_rewriter_test.rb @@ -234,6 +234,10 @@ class UrlWriterTests < Test::Unit::TestCase assert_equal params[3], { 'query[person][position][]' => 'art director' }.to_query end + def test_path_generation_for_symbol_parameter_keys + assert_generates("/image", :controller=> :image) + end + private def extract_params(url) url.split('?', 2).last.split('&') -- cgit v1.2.3