aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport
diff options
context:
space:
mode:
authorMikhail Dieterle <MikDiet@gmail.com>2012-09-21 11:43:59 +0300
committerMikhail Dieterle <MikDiet@gmail.com>2012-10-08 01:20:37 +0300
commita4b11961630febd556c962b788b11c0ed5bedb45 (patch)
tree4e0e8fd0575e898d6ce54fcd77284030220086d4 /activesupport
parent5d27338ab08496b41ef71c789e5ae4de0b3b8df7 (diff)
downloadrails-a4b11961630febd556c962b788b11c0ed5bedb45.tar.gz
rails-a4b11961630febd556c962b788b11c0ed5bedb45.tar.bz2
rails-a4b11961630febd556c962b788b11c0ed5bedb45.zip
add more testcases and doc about Hash#extract!
Diffstat (limited to 'activesupport')
-rw-r--r--activesupport/CHANGELOG.md4
-rw-r--r--activesupport/test/core_ext/hash_ext_test.rb11
2 files changed, 11 insertions, 4 deletions
diff --git a/activesupport/CHANGELOG.md b/activesupport/CHANGELOG.md
index 82752b6776..23e2ce0b03 100644
--- a/activesupport/CHANGELOG.md
+++ b/activesupport/CHANGELOG.md
@@ -1,12 +1,12 @@
## Rails 4.0.0 (unreleased) ##
-* Hash#extract! returns only those keys that present in the reciever.
+* Hash#extract! returns only those keys that present in the receiver.
{:a => 1, :b => 2}.extract!(:a, :x) # => {:a => 1}
*Mikhail Dieterle*
-* Hash#extract! returns the same subclass, that the reciever is. I.e.
+* Hash#extract! returns the same subclass, that the receiver is. I.e.
HashWithIndifferentAccess#extract! returns HashWithIndifferentAccess instance.
*Mikhail Dieterle*
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