diff options
author | Antonio Santos <antonio@santosvelasco.com> | 2013-10-24 09:17:35 +0200 |
---|---|---|
committer | Antonio Santos <antonio@santosvelasco.com> | 2013-10-24 09:17:35 +0200 |
commit | f13fce617deb50c91fbe504af5af726ec8b5654d (patch) | |
tree | b16080abf1e8a3dcec50cf3d350381898f33df0b /activesupport/test/core_ext/hash_ext_test.rb | |
parent | 80e90b0bd0b0cd50a186e314034d68182c045765 (diff) | |
download | rails-f13fce617deb50c91fbe504af5af726ec8b5654d.tar.gz rails-f13fce617deb50c91fbe504af5af726ec8b5654d.tar.bz2 rails-f13fce617deb50c91fbe504af5af726ec8b5654d.zip |
slice! should not remove default hash value/proc
Diffstat (limited to 'activesupport/test/core_ext/hash_ext_test.rb')
-rw-r--r-- | activesupport/test/core_ext/hash_ext_test.rb | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/activesupport/test/core_ext/hash_ext_test.rb b/activesupport/test/core_ext/hash_ext_test.rb index 2d0c56bef5..b059bc3e89 100644 --- a/activesupport/test/core_ext/hash_ext_test.rb +++ b/activesupport/test/core_ext/hash_ext_test.rb @@ -781,6 +781,24 @@ class HashExtTest < ActiveSupport::TestCase assert_equal 'bender', slice['login'] end + def test_slice_bang_does_not_override_default + hash = Hash.new(0) + hash.update(a: 1, b: 2) + + hash.slice!(:a) + + assert_equal 0, hash[:c] + end + + def test_slice_bang_does_not_override_default_proc + hash = Hash.new { |h, k| h[k] = [] } + hash.update(a: 1, b: 2) + + hash.slice!(:a) + + assert_equal [], hash[:c] + end + def test_extract original = {:a => 1, :b => 2, :c => 3, :d => 4} expected = {:a => 1, :b => 2} |