Fix OrderedHash#replace
Signed-off-by: Michael Koziarski <michael@koziarski.com>
This commit is contained in:
parent
a8ed10546d
commit
6c59e5a558
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue