BSON::OrderedHash#delete_if modifies the hash while iterating using each, causing incorrect behavior in Ruby 1.8.7. This was causing a number of tests to fail while integrating MongoDB with another product. I was able to resolve the issue with this monkey patch:
module BSON
class OrderedHash
if RUBY_VERSION < '1.9'
#BSON::OrderedHash bug
def delete_if
keys.each do |k|
if yield k, self[k]
delete(k)
end
end
self
end
end
end
end