aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Koziarski <michael@koziarski.com>2008-07-12 11:42:41 +0200
committerMichael Koziarski <michael@koziarski.com>2008-07-12 11:42:41 +0200
commite53f5fe696d692f1985981c34bb311e898fe3c72 (patch)
tree9fb8f244d277cc0bc8555a57866955a5d062639f
parent50b5c6845ed1645cf25613024ef04187385f8dcd (diff)
downloadrails-e53f5fe696d692f1985981c34bb311e898fe3c72.tar.gz
rails-e53f5fe696d692f1985981c34bb311e898fe3c72.tar.bz2
rails-e53f5fe696d692f1985981c34bb311e898fe3c72.zip
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.
-rw-r--r--actionpack/lib/action_controller/assertions/response_assertions.rb11
-rwxr-xr-xactionpack/test/controller/redirect_test.rb5
2 files changed, 14 insertions, 2 deletions
diff --git a/actionpack/lib/action_controller/assertions/response_assertions.rb b/actionpack/lib/action_controller/assertions/response_assertions.rb
index 3ecaee641f..64aaf6211f 100644
--- a/actionpack/lib/action_controller/assertions/response_assertions.rb
+++ b/actionpack/lib/action_controller/assertions/response_assertions.rb
@@ -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
diff --git a/actionpack/test/controller/redirect_test.rb b/actionpack/test/controller/redirect_test.rb
index 8b72426d10..28da5c6163 100755
--- a/actionpack/test/controller/redirect_test.rb
+++ b/actionpack/test/controller/redirect_test.rb
@@ -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