aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/test/core_ext/hash_ext_test.rb
diff options
context:
space:
mode:
authorlaserlemon <steve.richert@gmail.com>2010-10-11 21:21:40 -0400
committerSantiago Pastorino <santiago@wyeworks.com>2010-11-07 10:19:51 -0200
commit02039e9752bcb214c2ad85859ecf47dcbb892225 (patch)
tree4a796747c8a7d6f637d2c53b5847c63404076995 /activesupport/test/core_ext/hash_ext_test.rb
parent6709078eb1f61a1f8d54fcd82e9a07e96383ec8a (diff)
downloadrails-02039e9752bcb214c2ad85859ecf47dcbb892225.tar.gz
rails-02039e9752bcb214c2ad85859ecf47dcbb892225.tar.bz2
rails-02039e9752bcb214c2ad85859ecf47dcbb892225.zip
Ensure that HashWithIndifferentAccess duplication preserves class (for sublclasses) and default value [#5724 state:resolved]
Signed-off-by: Santiago Pastorino <santiago@wyeworks.com>
Diffstat (limited to 'activesupport/test/core_ext/hash_ext_test.rb')
-rw-r--r--activesupport/test/core_ext/hash_ext_test.rb15
1 files changed, 14 insertions, 1 deletions
diff --git a/activesupport/test/core_ext/hash_ext_test.rb b/activesupport/test/core_ext/hash_ext_test.rb
index cdf27ba35a..03fbee93a2 100644
--- a/activesupport/test/core_ext/hash_ext_test.rb
+++ b/activesupport/test/core_ext/hash_ext_test.rb
@@ -6,6 +6,9 @@ require 'active_support/ordered_hash'
require 'active_support/core_ext/object/conversions'
class HashExtTest < Test::Unit::TestCase
+ class IndifferentHash < HashWithIndifferentAccess
+ end
+
def setup
@strings = { 'a' => 1, 'b' => 2 }
@symbols = { :a => 1, :b => 2 }
@@ -267,7 +270,6 @@ class HashExtTest < Test::Unit::TestCase
assert_equal 1, h['first']
end
-
def test_indifferent_subhashes
h = {'user' => {'id' => 5}}.with_indifferent_access
['user', :user].each {|user| [:id, 'id'].each {|id| assert_equal 5, h[user][id], "h[#{user.inspect}][#{id.inspect}] should be 5"}}
@@ -276,6 +278,17 @@ class HashExtTest < Test::Unit::TestCase
['user', :user].each {|user| [:id, 'id'].each {|id| assert_equal 5, h[user][id], "h[#{user.inspect}][#{id.inspect}] should be 5"}}
end
+ def test_indifferent_duplication
+ # Should preserve default value
+ h = HashWithIndifferentAccess.new
+ h.default = '1234'
+ assert_equal h.default, h.dup.default
+
+ # Should preserve class for subclasses
+ h = IndifferentHash.new
+ assert_equal h.class, h.dup.class
+ end
+
def test_assert_valid_keys
assert_nothing_raised do
{ :failure => "stuff", :funny => "business" }.assert_valid_keys([ :failure, :funny ])