From a4b11961630febd556c962b788b11c0ed5bedb45 Mon Sep 17 00:00:00 2001 From: Mikhail Dieterle Date: Fri, 21 Sep 2012 11:43:59 +0300 Subject: add more testcases and doc about Hash#extract! --- activesupport/test/core_ext/hash_ext_test.rb | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'activesupport/test/core_ext/hash_ext_test.rb') diff --git a/activesupport/test/core_ext/hash_ext_test.rb b/activesupport/test/core_ext/hash_ext_test.rb index 5ba8e822b3..7cfe7b0ea7 100644 --- a/activesupport/test/core_ext/hash_ext_test.rb +++ b/activesupport/test/core_ext/hash_ext_test.rb @@ -724,8 +724,10 @@ class HashExtTest < ActiveSupport::TestCase def test_extract original = {:a => 1, :b => 2, :c => 3, :d => 4} expected = {:a => 1, :b => 2} + remaining = {:c => 3, :d => 4} assert_equal expected, original.extract!(:a, :b, :x) + assert_equal remaining, original end def test_extract_nils @@ -739,10 +741,15 @@ class HashExtTest < ActiveSupport::TestCase end def test_indifferent_extract - original = {:a => 1, :b => 2, :c => 3, :d => 4}.with_indifferent_access + original = {:a => 1, 'b' => 2, :c => 3, 'd' => 4}.with_indifferent_access expected = {:a => 1, :b => 2}.with_indifferent_access + remaining = {:c => 3, :d => 4}.with_indifferent_access - assert_equal expected, original.extract!(:a, :b) + [['a', 'b'], [:a, :b]].each do |keys| + copy = original.dup + assert_equal expected, copy.extract!(*keys) + assert_equal remaining, copy + end end def test_except -- cgit v1.2.3