make BSON::OrderedHash equal to other types of hashes in both directions

This commit is contained in:
Ryan Angilly 2010-06-16 22:18:35 -04:00 committed by Kyle Banker
parent 6e3cc639f6
commit a7de4f2eed
2 changed files with 16 additions and 3 deletions

View File

@ -27,9 +27,12 @@ module BSON
def ==(other)
begin
!other.nil? &&
keys == other.keys &&
values == other.values
case other
when BSON::OrderedHash
keys == other.keys && values == other.values
else
!other.nil? && keys.size == other.keys.size && keys.all? {|x| self[x] == other[x] }
end
rescue
false
end

View File

@ -140,6 +140,16 @@ class OrderedHashTest < Test::Unit::TestCase
assert_equal ['crab', 'apple', 3, 'foo'], @oh.values
end
def test_equality_with_hash
o = BSON::OrderedHash.new
o[:a] = 1
o[:b] = 2
o[:c] = 3
r = {:a => 1, :b => 2, :c => 3}
assert r == o
assert o == r
end
def test_update
other = BSON::OrderedHash.new
other['f'] = 'foo'