1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Restore support for partial matches in assert_redirected_to

If both the actual redirection and the asserted redirection are hashes, succeed if the asserted redirection is a strict subset of the actual redirection.
This commit is contained in:
Michael Koziarski 2008-07-12 11:42:41 +02:00
parent 50b5c6845e
commit e53f5fe696
2 changed files with 14 additions and 2 deletions

View file

@ -63,11 +63,18 @@ module ActionController
clean_backtrace do
assert_response(:redirect, message)
return true if options == @response.redirected_to
# Support partial arguments for hash redirections
if options.is_a?(Hash) && @response.redirected_to.is_a?(Hash)
return true if options.all? {|(key, value)| @response.redirected_to[key] == value}
end
redirected_to_after_normalisation = normalize_argument_to_redirection(@response.redirected_to)
options_after_normalisation = normalize_argument_to_redirection(options)
assert_equal redirected_to_after_normalisation, options_after_normalisation,
"Expected response to be a redirect to <#{options_after_normalisation}> but was a redirect to <#{redirected_to_after_normalisation}>"
if redirected_to_after_normalisation != options_after_normalisation
flunk "Expected response to be a redirect to <#{options_after_normalisation}> but was a redirect to <#{redirected_to_after_normalisation}>"
end
end
end

View file

@ -227,6 +227,11 @@ class RedirectTest < Test::Unit::TestCase
assert_redirected_to Workshop.new(5, true)
end
def test_redirect_with_partial_params
get :module_redirect
assert_redirected_to :action => 'hello_world'
end
def test_redirect_to_nil
assert_raises(ActionController::ActionControllerError) do
get :redirect_to_nil