Fix OrderedHash#replace

Signed-off-by: Michael Koziarski <michael@koziarski.com>
This commit is contained in:
Chris Hapgood 2009-11-04 10:13:59 -05:00 committed by Michael Koziarski
parent a8ed10546d
commit 6c59e5a558
2 changed files with 14 additions and 0 deletions

View File

@ -120,6 +120,13 @@ module ActiveSupport
dup.merge!(other_hash)
end
# When replacing with another hash, the initial order of our keys must come from the other hash -ordered or not.
def replace(other)
super
@keys = other.keys
self
end
def inspect
"#<OrderedHash #{super}>"
end

View File

@ -191,4 +191,11 @@ class OrderedHashTest < Test::Unit::TestCase
assert_equal "odd number of arguments for Hash", $!.message
end
end
def test_replace_updates_keys
@other_ordered_hash = ActiveSupport::OrderedHash[:black, '000000', :white, '000000']
original = @ordered_hash.replace(@other_ordered_hash)
assert_same original, @ordered_hash
assert_equal @other_ordered_hash.keys, @ordered_hash.keys
end
end