Skip to content

Commit b7eaebe

Browse files
authored
Merge pull request rails#46133 from nvasilevski/keep-backwards-compatibility-for-assert-redirected-to
Keep backwards compatibility for `assert_redirected_to`
2 parents b8b796c + e7a1740 commit b7eaebe

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

actionpack/lib/action_dispatch/testing/assertions/response.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def assert_response(type, message = nil)
5555
# # Permanently).
5656
# assert_redirected_to "/some/path", status: :moved_permanently
5757
def assert_redirected_to(url_options = {}, options = {}, message = nil)
58-
options, message = message, nil if message.is_a?(Hash) && options.empty?
58+
options, message = {}, options unless options.is_a?(Hash)
5959

6060
status = options[:status] || :redirect
6161
assert_response(status, message)

actionpack/test/controller/action_pack_assertions_test.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,14 @@ def test_assert_redirection_with_symbol
442442
}
443443
end
444444

445+
def test_assert_redirection_with_custom_message
446+
error = assert_raise(ActiveSupport::TestCase::Assertion) do
447+
assert_redirected_to "http://test.host/some/path", "wrong redirect"
448+
end
449+
450+
assert_equal("wrong redirect", error.message)
451+
end
452+
445453
def test_assert_redirection_with_status
446454
process :redirect_to_path
447455
assert_redirected_to "http://test.host/some/path", status: :found

0 commit comments

Comments
 (0)