Skip to content

Commit

Permalink
Restore support for partial matches in assert_redirected_to
Browse files Browse the repository at this point in the history
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
NZKoz committed Jul 12, 2008
1 parent 50b5c68 commit e53f5fe
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
5 changes: 5 additions & 0 deletions actionpack/test/controller/redirect_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit e53f5fe

Please sign in to comment.