aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/test
diff options
context:
space:
mode:
authorJosé Valim <jose.valim@gmail.com>2011-05-08 03:44:27 -0700
committerJosé Valim <jose.valim@gmail.com>2011-05-08 03:44:27 -0700
commitc2b55c4fbfc427e9ca468fce0392de591c87747a (patch)
tree40d6cb605293f78791633ce7a5b8a5279fc4ac41 /activesupport/test
parente5a01224195b289748b3996e6deb0587baf625d8 (diff)
parent099eb2b3fd9526e06c30b9878780f31091e011aa (diff)
downloadrails-c2b55c4fbfc427e9ca468fce0392de591c87747a.tar.gz
rails-c2b55c4fbfc427e9ca468fce0392de591c87747a.tar.bz2
rails-c2b55c4fbfc427e9ca468fce0392de591c87747a.zip
Merge pull request #454 from dlee/nested_indifferent_access
indifferent access should recurse Hash subclasses
Diffstat (limited to 'activesupport/test')
-rw-r--r--activesupport/test/core_ext/hash_ext_test.rb15
-rw-r--r--activesupport/test/ordered_hash_test.rb5
2 files changed, 17 insertions, 3 deletions
diff --git a/activesupport/test/core_ext/hash_ext_test.rb b/activesupport/test/core_ext/hash_ext_test.rb
index 3ef080e1cb..4557a10688 100644
--- a/activesupport/test/core_ext/hash_ext_test.rb
+++ b/activesupport/test/core_ext/hash_ext_test.rb
@@ -16,6 +16,12 @@ class HashExtTest < Test::Unit::TestCase
class SubclassingHash < Hash
end
+ class NonIndifferentHash < Hash
+ def nested_under_indifferent_access
+ self
+ end
+ end
+
def setup
@strings = { 'a' => 1, 'b' => 2 }
@symbols = { :a => 1, :b => 2 }
@@ -109,9 +115,12 @@ class HashExtTest < Test::Unit::TestCase
assert_equal @strings, @mixed.with_indifferent_access.dup.stringify_keys!
end
- def test_hash_subclass
- flash = { "foo" => SubclassingHash.new.tap { |h| h["bar"] = "baz" } }.with_indifferent_access
- assert_kind_of SubclassingHash, flash["foo"]
+ def test_nested_under_indifferent_access
+ foo = { "foo" => SubclassingHash.new.tap { |h| h["bar"] = "baz" } }.with_indifferent_access
+ assert_kind_of ActiveSupport::HashWithIndifferentAccess, foo["foo"]
+
+ foo = { "foo" => NonIndifferentHash.new.tap { |h| h["bar"] = "baz" } }.with_indifferent_access
+ assert_kind_of NonIndifferentHash, foo["foo"]
end
def test_indifferent_assorted
diff --git a/activesupport/test/ordered_hash_test.rb b/activesupport/test/ordered_hash_test.rb
index 50168fa78f..bf99a701a6 100644
--- a/activesupport/test/ordered_hash_test.rb
+++ b/activesupport/test/ordered_hash_test.rb
@@ -243,6 +243,11 @@ class OrderedHashTest < Test::Unit::TestCase
assert_equal @other_ordered_hash.keys, @ordered_hash.keys
end
+ def test_nested_under_indifferent_access
+ flash = {:a => ActiveSupport::OrderedHash[:b, 1, :c, 2]}.with_indifferent_access
+ assert_kind_of ActiveSupport::OrderedHash, flash[:a]
+ end
+
def test_each_after_yaml_serialization
values = []
@deserialized_ordered_hash = YAML.load(YAML.dump(@ordered_hash))