aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/test/core_ext/hash_ext_test.rb
diff options
context:
space:
mode:
authorMatthewRudy <MatthewRudyJacobs@gmail.com>2008-07-17 13:58:42 +0100
committerPratik Naik <pratiknaik@gmail.com>2008-07-17 15:34:51 +0100
commit7e8aee7e6cbd23c1eb18bec1869465e923915e7a (patch)
tree03a8ae8f0e11c58683ee12491935986d55302674 /activesupport/test/core_ext/hash_ext_test.rb
parentb3a2ee7b87a6b2a4c6ff086644f40a472a676b65 (diff)
downloadrails-7e8aee7e6cbd23c1eb18bec1869465e923915e7a.tar.gz
rails-7e8aee7e6cbd23c1eb18bec1869465e923915e7a.tar.bz2
rails-7e8aee7e6cbd23c1eb18bec1869465e923915e7a.zip
Add extra tests to ensure Hash#slice works with an array as a key. #613
Signed-off-by: Pratik Naik <pratiknaik@gmail.com>
Diffstat (limited to 'activesupport/test/core_ext/hash_ext_test.rb')
-rw-r--r--activesupport/test/core_ext/hash_ext_test.rb21
1 files changed, 21 insertions, 0 deletions
diff --git a/activesupport/test/core_ext/hash_ext_test.rb b/activesupport/test/core_ext/hash_ext_test.rb
index 2ab7681a8a..fc8ed45358 100644
--- a/activesupport/test/core_ext/hash_ext_test.rb
+++ b/activesupport/test/core_ext/hash_ext_test.rb
@@ -292,6 +292,27 @@ class HashExtTest < Test::Unit::TestCase
assert_equal expected, original
end
+ def test_slice_with_an_array_key
+ original = { :a => 'x', :b => 'y', :c => 10, [:a, :b] => "an array key" }
+ expected = { [:a, :b] => "an array key", :c => 10 }
+
+ # Should return a new hash with only the given keys when given an array key.
+ assert_equal expected, original.slice([:a, :b], :c)
+ assert_not_equal expected, original
+
+ # Should replace the hash with only the given keys when given an array key.
+ assert_equal expected, original.slice!([:a, :b], :c)
+ assert_equal expected, original
+ end
+
+ def test_slice_with_splatted_keys
+ original = { :a => 'x', :b => 'y', :c => 10, [:a, :b] => "an array key" }
+ expected = { :a => 'x', :b => "y" }
+
+ # Should grab each of the splatted keys.
+ assert_equal expected, original.slice(*[:a, :b])
+ end
+
def test_indifferent_slice
original = { :a => 'x', :b => 'y', :c => 10 }.with_indifferent_access
expected = { :a => 'x', :b => 'y' }.with_indifferent_access