Skip to content
Browse files

Added nicer message for assert_redirected_to (closes #4294) [court3na…

…y, Chris McGrath]

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@3969 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
1 parent 9038303 commit 891a962a192bdd7eb0402b41e11a5e5657fe961c @technoweenie technoweenie committed Mar 19, 2006
View
12 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:
View
5 actionpack/lib/action_controller/assertions.rb
@@ -85,8 +85,9 @@ def assert_redirected_to(options = {}, message=nil)
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)
View
14 actionpack/test/controller/redirect_test.rb
@@ -58,6 +58,20 @@ def test_simple_redirect_using_options
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"
View
2 activesupport/CHANGELOG
@@ -1,5 +1,7 @@
*SVN*
+* Added Hash#diff to show the difference between two hashes [Chris McGrath]
+
* Fixed HashWithIndifferentAccess#delete to work with both symbols and strings #2176 [Caio Chassot]
* Added Time#advance to do precise time time calculations for cases where a month being approximated to 30 days won't do #1860 [Rick Olson]
View
2 activesupport/lib/active_support/core_ext/hash.rb
@@ -2,10 +2,12 @@
require File.dirname(__FILE__) + '/hash/indifferent_access'
require File.dirname(__FILE__) + '/hash/reverse_merge'
require File.dirname(__FILE__) + '/hash/conversions'
+require File.dirname(__FILE__) + '/hash/diff'
class Hash #:nodoc:
include ActiveSupport::CoreExtensions::Hash::Keys
include ActiveSupport::CoreExtensions::Hash::IndifferentAccess
include ActiveSupport::CoreExtensions::Hash::ReverseMerge
include ActiveSupport::CoreExtensions::Hash::Conversions
+ include ActiveSupport::CoreExtensions::Hash::Diff
end
View
11 activesupport/lib/active_support/core_ext/hash/diff.rb
@@ -0,0 +1,11 @@
+module ActiveSupport #:nodoc:
+ module CoreExtensions #:nodoc:
+ module Hash #:nodoc:
+ module Diff
+ def diff(h2)
+ self.dup.delete_if { |k, v| h2[k] == v }.merge(h2.dup.delete_if { |k, v| self.has_key?(k) })
+ end
+ end
+ end
+ end
+end
View
6 activesupport/test/core_ext/hash_ext_test.rb
@@ -174,6 +174,10 @@ def test_assorted_keys_not_stringified
def test_reverse_merge
assert_equal({ :a => 1, :b => 2, :c => 10 }, { :a => 1, :b => 2 }.reverse_merge({:a => "x", :b => "y", :c => 10}) )
end
+
+ def test_diff
+ assert_equal({ :a => 2 }, { :a => 2, :b => 5 }.diff({ :a => 1, :b => 5 }))
+ end
end
class HashToXmlTest < Test::Unit::TestCase
@@ -234,4 +238,4 @@ def test_three_levels_with_array
xml = { :name => "David", :addresses => [{ :streets => [ { :name => "Paulina" }, { :name => "Paulina" } ] } ] }.to_xml(@xml_options)
assert xml.include?(%(<addresses><address><streets><street><name>))
end
-end
+end

0 comments on commit 891a962

Please sign in to comment.
Something went wrong with that request. Please try again.