From d3704f888b4da86d2aa48b8efb777bd38f1e7028 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Thu, 19 May 2005 19:19:58 +0000 Subject: Fixed assert_redirect_to to work with redirect_to_path #869 [Nicholas Seckar] git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1332 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- actionpack/lib/action_controller/assertions.rb | 30 ++++++++++++++++++++------ 1 file changed, 23 insertions(+), 7 deletions(-) (limited to 'actionpack/lib/action_controller') diff --git a/actionpack/lib/action_controller/assertions.rb b/actionpack/lib/action_controller/assertions.rb index 5d1826b72a..a419a65dfa 100644 --- a/actionpack/lib/action_controller/assertions.rb +++ b/actionpack/lib/action_controller/assertions.rb @@ -51,13 +51,29 @@ module Test #:nodoc: 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 -- cgit v1.2.3