aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/test/core_ext
diff options
context:
space:
mode:
authorRafael Mendonça França <rafaelmfranca@gmail.com>2015-07-10 13:32:59 -0300
committerRafael Mendonça França <rafaelmfranca@gmail.com>2015-07-10 13:32:59 -0300
commitebf8961182bdc8134cc4b21dfa46b909624b6126 (patch)
tree468d1e18ca0ac0680e0e4c15fd296de874ff109b /activesupport/test/core_ext
parenteb10496a1c3d9fe58b91aa0ec17d9f218738d5dc (diff)
parent9578d574f3be8da966ee7355dfb1604936a103cb (diff)
downloadrails-ebf8961182bdc8134cc4b21dfa46b909624b6126.tar.gz
rails-ebf8961182bdc8134cc4b21dfa46b909624b6126.tar.bz2
rails-ebf8961182bdc8134cc4b21dfa46b909624b6126.zip
Merge pull request #20828 from Sirupsen/hash-indifferent-dup-default-proc
active_support/indifferent_access: fix not raising when default_proc does
Diffstat (limited to 'activesupport/test/core_ext')
-rw-r--r--activesupport/test/core_ext/hash_ext_test.rb37
1 files changed, 37 insertions, 0 deletions
diff --git a/activesupport/test/core_ext/hash_ext_test.rb b/activesupport/test/core_ext/hash_ext_test.rb
index 5d210c958e..febe41ec4d 100644
--- a/activesupport/test/core_ext/hash_ext_test.rb
+++ b/activesupport/test/core_ext/hash_ext_test.rb
@@ -523,6 +523,12 @@ class HashExtTest < ActiveSupport::TestCase
assert_equal 5, merged[:b]
end
+ def test_reverse_merge
+ hash = HashWithIndifferentAccess.new key: :old_value
+ hash.reverse_merge! key: :new_value
+ assert_equal :old_value, hash[:key]
+ end
+
def test_indifferent_reverse_merging
hash = HashWithIndifferentAccess.new('some' => 'value', 'other' => 'value')
hash.reverse_merge!(:some => 'noclobber', :another => 'clobber')
@@ -999,6 +1005,37 @@ class HashExtTest < ActiveSupport::TestCase
assert hash.key?('a')
assert_equal 1, hash[:a]
end
+
+ def test_dup_with_default_proc
+ hash = HashWithIndifferentAccess.new
+ hash.default_proc = proc { |h, v| raise "walrus" }
+ assert_nothing_raised { hash.dup }
+ end
+
+ def test_dup_with_default_proc_sets_proc
+ hash = HashWithIndifferentAccess.new
+ hash.default_proc = proc { |h, k| k + 1 }
+ new_hash = hash.dup
+
+ assert_equal 3, new_hash[2]
+
+ new_hash.default = 2
+ assert_equal 2, new_hash[:non_existant]
+ end
+
+ def test_to_hash_with_raising_default_proc
+ hash = HashWithIndifferentAccess.new
+ hash.default_proc = proc { |h, k| raise "walrus" }
+
+ assert_nothing_raised { hash.to_hash }
+ end
+
+ def test_new_from_hash_copying_default_should_not_raise_when_default_proc_does
+ hash = Hash.new
+ hash.default_proc = proc { |h, k| raise "walrus" }
+
+ assert_nothing_raised { HashWithIndifferentAccess.new_from_hash_copying_default(hash) }
+ end
end
class IWriteMyOwnXML