Permalink
Browse files

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.
  • Loading branch information...
1 parent 50b5c68 commit e53f5fe696d692f1985981c34bb311e898fe3c72 @NZKoz NZKoz committed Jul 12, 2008
@@ -63,11 +63,18 @@ def assert_redirected_to(options = {}, message=nil)
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
@@ -227,6 +227,11 @@ def test_redirect_to_record
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

0 comments on commit e53f5fe

Please sign in to comment.