diff options
author | Pratik Naik <pratiknaik@gmail.com> | 2008-04-02 11:45:03 +0000 |
---|---|---|
committer | Pratik Naik <pratiknaik@gmail.com> | 2008-04-02 11:45:03 +0000 |
commit | adaed1ebcb4af2a7203d61e70b826f69f880fb2f (patch) | |
tree | 50e4b4299b71241e46a24ce36b0e8a66d67ba277 /activesupport/test | |
parent | f4dc83497612bbd458213fccd161e1a38939ad5f (diff) | |
download | rails-adaed1ebcb4af2a7203d61e70b826f69f880fb2f.tar.gz rails-adaed1ebcb4af2a7203d61e70b826f69f880fb2f.tar.bz2 rails-adaed1ebcb4af2a7203d61e70b826f69f880fb2f.zip |
Adding Hash#without Closes #7369 [eventualbuddha]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@9209 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activesupport/test')
-rw-r--r-- | activesupport/test/core_ext/hash_ext_test.rb | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/activesupport/test/core_ext/hash_ext_test.rb b/activesupport/test/core_ext/hash_ext_test.rb index 706e218abc..9d1d6ec33f 100644 --- a/activesupport/test/core_ext/hash_ext_test.rb +++ b/activesupport/test/core_ext/hash_ext_test.rb @@ -310,6 +310,38 @@ class HashExtTest < Test::Unit::TestCase assert_equal expected, original.except!(:c) assert_equal expected, original end + + def test_without + original = { :a => 'x', :b => 'y', :c => 10 } + expected = { :a => 'x' } + + # Should return a hash without the given keys. + assert_equal expected, original.without(:b, :c) + assert_not_equal expected, original + + # Should ignore non-existant keys. + assert_equal expected, original.without(:b, :c, :d) + + # Should replace the hash with the given keys taken away. + assert_equal expected, original.without!(:b, :c) + assert_equal expected, original + end + + def test_indifferent_without + original = { :a => 'x', :b => 'y', :c => 10 }.with_indifferent_access + expected = { :c => 10 }.with_indifferent_access + + [['a', 'b'], [:a, :b]].each do |keys| + # Should return a new hash without the given keys. + assert_equal expected, original.without(*keys), keys.inspect + assert_not_equal expected, original + + # Should replace the hash without the given keys. + copy = original.dup + assert_equal expected, copy.without!(*keys) + assert_equal expected, copy + end + end end class IWriteMyOwnXML |