Skip to content
Browse files

Fix OrderedHash#replace

Signed-off-by: Michael Koziarski <michael@koziarski.com>
  • Loading branch information...
1 parent 4ae03b2 commit c3ef028b818779996472e018486446a216657251 @cch1 cch1 committed with NZKoz Nov 4, 2009
Showing with 14 additions and 0 deletions.
  1. +7 −0 activesupport/lib/active_support/ordered_hash.rb
  2. +7 −0 activesupport/test/ordered_hash_test.rb
View
7 activesupport/lib/active_support/ordered_hash.rb
@@ -120,6 +120,13 @@ def merge(other_hash)
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
7 activesupport/test/ordered_hash_test.rb
@@ -191,4 +191,11 @@ def test_alternate_initialization_raises_exception_on_odd_length_args
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

0 comments on commit c3ef028

Please sign in to comment.
Something went wrong with that request. Please try again.