diff --git a/actionpack/CHANGELOG b/actionpack/CHANGELOG index aca576feb71f050a2be459edf8774fd23aad19c0..fb79d417c79e3fa02b3c2008fe95f5f9f1338439 100644 --- a/actionpack/CHANGELOG +++ b/actionpack/CHANGELOG @@ -1,5 +1,7 @@ *SVN* +* Fixed assert_redirect_to to work with redirect_to_path #869 [Nicholas Seckar] + * Fixed escaping of :method option in remote_form_tag #1218 [Rick Olson] * Added Serbia and Montenegro to the country_select #1239 [todd@robotcoop.com] diff --git a/actionpack/lib/action_controller/assertions.rb b/actionpack/lib/action_controller/assertions.rb index 5d1826b72af395fc6798e699823c2d30d8f490b7..a419a65dfab11c15a22e23a249e83c1d67d5000c 100644 --- a/actionpack/lib/action_controller/assertions.rb +++ b/actionpack/lib/action_controller/assertions.rb @@ -51,13 +51,29 @@ def assert_response(type, message = nil) def assert_redirected_to(options = {}, message=nil) assert_redirect(message) - msg = build_message(message, "response is not a redirection to all of the options supplied (redirection is )", @response.redirected_to) - assert_block(msg) do - 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?) + if options.is_a?(String) + msg = build_message(message, "expected a redirect to , found one to ", options, @response.redirect_url) + + url_regexp = %r{^(\w+://.*?(/|$|\?))(.*)$} + eurl, epath, url, path = [options, @response.redirect_url].collect do |url| + u, p = (url_regexp =~ url) ? [$1, $3] : [nil, url] + [u, (p[0..0] == '/') ? p : '/' + p] + end.flatten + + if eurl && url then assert_equal(eurl, url, msg) + else assert_equal(epath, path, msg) + end + else + msg = build_message(message, "response is not a redirection to all of the options supplied (redirection is )", + @response.redirected_to || @response.redirect_url) + + assert_block(msg) do + 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?) + end end end end diff --git a/actionpack/test/controller/action_pack_assertions_test.rb b/actionpack/test/controller/action_pack_assertions_test.rb index 4823983165d60b3f645ed491343c9e3da2990549..3fc8a2c99a35c231858b8aa69f7b801aadf212ef 100644 --- a/actionpack/test/controller/action_pack_assertions_test.rb +++ b/actionpack/test/controller/action_pack_assertions_test.rb @@ -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_path() redirect_to '/some/path' end + # a redirect to an external location def redirect_external() redirect_to_url "http://www.rubyonrails.org"; end @@ -368,6 +370,19 @@ def test_follow_redirect_outside_current_action assert_raises(RuntimeError, "Can't follow redirects outside of current controller (elsewhere)") { follow_redirect } end + + def test_redirected_to_url_leadling_slash + process :redirect_to_path + assert_redirected_to '/some/path' + end + def test_redirected_to_url_no_leadling_slash + process :redirect_to_path + assert_redirected_to 'some/path' + end + def test_redirected_to_url_full_url + process :redirect_to_path + assert_redirected_to 'http://test.host/some/path' + end end class ActionPackHeaderTest < Test::Unit::TestCase @@ -384,4 +399,4 @@ def test_rendering_xml_respects_content_type process :hello_xml_world assert_equal('application/pdf', @controller.headers['Content-Type']) end -end \ No newline at end of file +end