diff options
author | Rick Olson <technoweenie@gmail.com> | 2006-03-19 03:50:14 +0000 |
---|---|---|
committer | Rick Olson <technoweenie@gmail.com> | 2006-03-19 03:50:14 +0000 |
commit | 891a962a192bdd7eb0402b41e11a5e5657fe961c (patch) | |
tree | 2f34ec037e56a8fa6e537adb15faafba0e5dd17d /actionpack | |
parent | 9038303af0a634a3ac9ae8234d121a1815960d2e (diff) | |
download | rails-891a962a192bdd7eb0402b41e11a5e5657fe961c.tar.gz rails-891a962a192bdd7eb0402b41e11a5e5657fe961c.tar.bz2 rails-891a962a192bdd7eb0402b41e11a5e5657fe961c.zip |
Added nicer message for assert_redirected_to (closes #4294) [court3nay, Chris McGrath]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@3969 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'actionpack')
-rw-r--r-- | actionpack/CHANGELOG | 12 | ||||
-rw-r--r-- | actionpack/lib/action_controller/assertions.rb | 5 | ||||
-rwxr-xr-x | actionpack/test/controller/redirect_test.rb | 14 |
3 files changed, 29 insertions, 2 deletions
diff --git a/actionpack/CHANGELOG b/actionpack/CHANGELOG index 8803a1dd34..ec69d07b12 100644 --- a/actionpack/CHANGELOG +++ b/actionpack/CHANGELOG @@ -1,5 +1,17 @@ *SVN* +* Added nicer message for assert_redirected_to (closes #4294) [court3nay] + + assert_redirected_to :action => 'other_host', :only_path => false + + when it was expecting... + + redirected_to :action => 'other_host', :only_path => true, :host => 'other.test.host' + + gives the error message... + + response is not a redirection to all of the options supplied (redirection is <{:only_path=>false, :host=>"other.test.host", :action=>"other_host"}>), difference: <{:only_path=>"true", :host=>"other.test.host"}> + * Change url_for to escape the resulting URLs when called from a view. [Nicholas Seckar, eddiewould@paradise.net.nz] * Added easy support for testing file uploads with fixture_file_upload #4105 [turnip@turnipspatch.com]. Example: diff --git a/actionpack/lib/action_controller/assertions.rb b/actionpack/lib/action_controller/assertions.rb index b3f2c235d6..2402e0941b 100644 --- a/actionpack/lib/action_controller/assertions.rb +++ b/actionpack/lib/action_controller/assertions.rb @@ -85,8 +85,9 @@ module Test #:nodoc: assert_equal(eurl, url, msg) if eurl && url assert_equal(epath, path, msg) if epath && path else - msg = build_message(message, "response is not a redirection to all of the options supplied (redirection is <?>)", - @response.redirected_to || @response.redirect_url) + @response_diff = options.diff(@response.redirected_to) if @response.redirected_to + msg = build_message(message, "response is not a redirection to all of the options supplied (redirection is <?>), difference: <?>", + @response.redirected_to || @response.redirect_url, @response_diff) assert_block(msg) do if options.is_a?(Symbol) diff --git a/actionpack/test/controller/redirect_test.rb b/actionpack/test/controller/redirect_test.rb index 11b32d356b..d9b9042d5a 100755 --- a/actionpack/test/controller/redirect_test.rb +++ b/actionpack/test/controller/redirect_test.rb @@ -58,6 +58,20 @@ class RedirectTest < Test::Unit::TestCase assert_redirected_to :action => "other_host", :only_path => false, :host => 'other.test.host' end + def test_redirect_error_with_pretty_diff + get :host_redirect + begin + assert_redirected_to :action => "other_host", :only_path => true + rescue Test::Unit::AssertionFailedError => err + redirection_msg, diff_msg = err.message.scan(/<\{[^\}]+\}>/).collect { |s| s[2..-3] } + assert_match %r(:only_path=>false), redirection_msg + assert_match %r(:host=>"other.test.host"), redirection_msg + assert_match %r(:action=>"other_host"), redirection_msg + assert_match %r(:only_path=>true), diff_msg + assert_match %r(:host=>"other.test.host"), diff_msg + end + end + def test_module_redirect get :module_redirect assert_redirect_url "http://test.host/module_test/module_redirect/hello_world" |