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
This commit is contained in:
parent
4a7225a1bd
commit
d3704f888b
|
@ -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]
|
||||
|
|
|
@ -51,7 +51,22 @@ 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)
|
||||
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
|
||||
|
@ -62,6 +77,7 @@ module Test #:nodoc:
|
|||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# Asserts that the request was rendered with the appropriate template file.
|
||||
def assert_template(expected = nil, message=nil)
|
||||
|
|
|
@ -19,6 +19,8 @@ class ActionPackAssertionsController < ActionController::Base
|
|||
|
||||
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 @@ class ActionPackAssertionsControllerTest < Test::Unit::TestCase
|
|||
|
||||
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
|
||||
|
|
Loading…
Reference in New Issue