Permalink
Browse files

Fixed assert_redirected_to to handle absolute controller paths properly

#1472 [Rick Olson/Nicholas Seckar]

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1533 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
1 parent de1f231 commit 2269c23699968d31f2f81052ebcf7fcc29e82502 @dhh dhh committed Jun 27, 2005
View
2 actionpack/CHANGELOG
@@ -1,5 +1,7 @@
*SVN*
+* Fixed assert_redirected_to to handle absolute controller paths properly #1472 [Rick Olson/Nicholas Seckar]
+
* Added event-based observations when frequency is not set on observe_field/form #1474 [flash@vanklinkenbergsoftware.nl]
* Added script.aculo.us Javascripts (controls.js, dragdrop.js, effects.js) (NEEDS MORE DESCRIPTION) #1509 [Thomas Fuchs]
View
6 actionpack/lib/action_controller/assertions.rb
@@ -78,8 +78,10 @@ def assert_redirected_to(options = {}, message=nil)
if options.is_a?(Symbol)
@response.redirected_to == options
else
- options.keys.all? do |k|
- options[k] == (@response.redirected_to[k].respond_to?(:to_param) ? @response.redirected_to[k].to_param : @response.redirected_to[k] unless @response.redirected_to[k].nil?)
+ options.keys.all? do |k|
+ if k == :controller then options[k] == ActionController::Routing.controller_relative_to(@response.redirected_to[k], @controller.class.controller_path)
+ else options[k] == (@response.redirected_to[k].respond_to?(:to_param) ? @response.redirected_to[k].to_param : @response.redirected_to[k] unless @response.redirected_to[k].nil?)
+ end
end
end
end
View
27 actionpack/test/controller/action_pack_assertions_test.rb
@@ -79,7 +79,17 @@ def raise_on_post
# 911
def rescue_action(e) raise; end
-
+end
+
+module Admin
+ class InnerModuleController < ActionController::Base
+ def redirect_to_absolute_controller
+ redirect_to :controller => '/content'
+ end
+ def redirect_to_fellow_controller
+ redirect_to :controller => 'user'
+ end
+ end
end
# ---------------------------------------------------------------------------
@@ -392,6 +402,15 @@ def test_redirected_to_url_full_url
process :redirect_to_path
assert_redirected_to 'http://test.host/some/path'
end
+
+ def test_redirected_to_with_nested_controller
+ @controller = Admin::InnerModuleController.new
+ get :redirect_to_absolute_controller
+ assert_redirected_to :controller => 'content'
+
+ get :redirect_to_fellow_controller
+ assert_redirected_to :controller => 'admin/user'
+ end
end
class ActionPackHeaderTest < Test::Unit::TestCase
@@ -404,8 +423,8 @@ def test_rendering_xml_sets_content_type
assert_equal('text/xml', @controller.headers['Content-Type'])
end
def test_rendering_xml_respects_content_type
- @response.headers['Content-Type'] = 'application/pdf'
- process :hello_xml_world
- assert_equal('application/pdf', @controller.headers['Content-Type'])
+ @response.headers['Content-Type'] = 'application/pdf'
+ process :hello_xml_world
+ assert_equal('application/pdf', @controller.headers['Content-Type'])
end
end

0 comments on commit 2269c23

Please sign in to comment.