Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Backport fix to allow :controller=>:some_symbol [norbert]
git-svn-id: http://svn-commit.rubyonrails.org/rails/branches/1-2-stable@7838 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information
NZKoz committed Oct 11, 2007
1 parent 88f2284 commit f70b74a
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 0 deletions.
Expand Up @@ -69,6 +69,7 @@ def assert_redirected_to(options = {}, message=nil)
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)
Expand Down
3 changes: 3 additions & 0 deletions actionpack/lib/action_controller/routing.rb
Expand Up @@ -1254,6 +1254,9 @@ def generate(options, recall = {}, method=:generate)
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
Expand Down
13 changes: 13 additions & 0 deletions actionpack/test/controller/action_pack_assertions_test.rb
Expand Up @@ -19,6 +19,8 @@ def redirect_to_action() redirect_to :action => "flash_me", :id => 1, :params =>

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
Expand Down Expand Up @@ -555,6 +557,17 @@ def test_redirected_to_url_full_url
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
Expand Down
4 changes: 4 additions & 0 deletions actionpack/test/controller/url_rewriter_test.rb
Expand Up @@ -160,6 +160,10 @@ def test_hash_recursive_and_array_parameters
assert_equal params[3], { 'query[person][position][]' => 'prof' }.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('&')
Expand Down

0 comments on commit f70b74a

Please sign in to comment.