RUBY-173 allow HashWithIndifferentAccess

This commit is contained in:
Kyle Banker 2010-08-28 12:19:26 -04:00
parent 2eaca6bc8e
commit 5838b9aef7
2 changed files with 18 additions and 17 deletions

View File

@ -561,7 +561,7 @@ static void write_doc(buffer_t buffer, VALUE hash, VALUE check_keys, VALUE move_
write_function(key, value, pack_extra(buffer, check_keys));
}
} else if (strcmp(rb_obj_classname(hash), "Hash") == 0) {
} else if (strncmp(rb_obj_classname(hash), "Hash", 4) == 0) {
rb_hash_foreach(hash, write_function, pack_extra(buffer, check_keys));
} else {
buffer_free(buffer);

View File

@ -6,11 +6,10 @@ require 'rational'
begin
require 'active_support/core_ext'
require 'active_support/hash_with_indifferent_access'
Time.zone = "Pacific Time (US & Canada)"
Zone = Time.zone.now
rescue LoadError
warn 'Could not test BSON with HashWithIndifferentAccess.'
warn 'Mocking time with zone'
module ActiveSupport
class TimeWithZone
end
@ -523,7 +522,9 @@ class BSONTest < Test::Unit::TestCase
BSON::BSON_CODER.serialize(c, false, false).to_s
end
if defined?(HashWithIndifferentAccess)
# Mocking this class for testing
class ::HashWithIndifferentAccess < Hash; end
def test_keep_id_with_hash_with_indifferent_access
doc = HashWithIndifferentAccess.new
embedded = HashWithIndifferentAccess.new
@ -538,5 +539,5 @@ class BSONTest < Test::Unit::TestCase
BSON::BSON_CODER.serialize(doc, false, true).to_a
assert doc.has_key?("_id")
end
end
end