diff options
author | Xavier Noria <fxn@hashref.com> | 2010-06-13 05:53:42 +0200 |
---|---|---|
committer | Xavier Noria <fxn@hashref.com> | 2010-06-13 05:53:42 +0200 |
commit | 3359af63a518798ccc9c7f1c71e5507f6fe0d378 (patch) | |
tree | fe88b7c20142f7ecb8ed21ea5127241287e92e37 /activesupport/test | |
parent | 72f9fec607c4a72b2e88995d0cb32b16b96e9068 (diff) | |
download | rails-3359af63a518798ccc9c7f1c71e5507f6fe0d378.tar.gz rails-3359af63a518798ccc9c7f1c71e5507f6fe0d378.tar.bz2 rails-3359af63a518798ccc9c7f1c71e5507f6fe0d378.zip |
Revert "hash merging with a block ignores non-existing keys altogether"
This reverts commit 72f9fec607c4a72b2e88995d0cb32b16b96e9068.
It is wrong, this feature is a little undocumented, doing some research.
Diffstat (limited to 'activesupport/test')
-rw-r--r-- | activesupport/test/ordered_hash_test.rb | 33 |
1 files changed, 17 insertions, 16 deletions
diff --git a/activesupport/test/ordered_hash_test.rb b/activesupport/test/ordered_hash_test.rb index e19484fb82..56369585ec 100644 --- a/activesupport/test/ordered_hash_test.rb +++ b/activesupport/test/ordered_hash_test.rb @@ -144,27 +144,28 @@ class OrderedHashTest < Test::Unit::TestCase end def test_merge_with_block - hash = ActiveSupport::OrderedHash.new - hash[:a] = 0 - hash[:b] = 0 - merged = hash.merge(:b => 1, :c => 2) do |key, old_value, new_value| - new_value + 1 + other_hash = ActiveSupport::OrderedHash.new + other_hash['white'] = 'ff' + other_hash['black'] = '00' + merged = @ordered_hash.merge(other_hash) do |key, old_value, new_value| + new_value * 3 end - assert_equal 0, merged[:a] - assert_equal 2, merged[:b] - assert !merged.key?(:c) + assert_equal 'ffffff', merged['white'] + assert_equal '000000', merged['black'] + + assert_nil @ordered_hash['white'] + assert_nil @ordered_hash['black'] end def test_merge_bang_with_block - hash = ActiveSupport::OrderedHash.new - hash[:a] = 0 - hash[:b] = 0 - hash.merge!(:a => 1, :c => 2) do |key, old_value, new_value| - new_value + 3 + other_hash = ActiveSupport::OrderedHash.new + other_hash['white'] = 'ff' + other_hash['black'] = '00' + @ordered_hash.merge!(other_hash) do |key, old_value, new_value| + new_value * 3 end - assert_equal 4, hash[:a] - assert_equal 0, hash[:b] - assert !hash.key?(:c) + assert_equal 'ffffff', @ordered_hash['white'] + assert_equal '000000', @ordered_hash['black'] end def test_shift |