RUBY-173 allow HashWithIndifferentAccess
This commit is contained in:
parent
2eaca6bc8e
commit
5838b9aef7
@ -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));
|
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));
|
rb_hash_foreach(hash, write_function, pack_extra(buffer, check_keys));
|
||||||
} else {
|
} else {
|
||||||
buffer_free(buffer);
|
buffer_free(buffer);
|
||||||
|
@ -6,11 +6,10 @@ require 'rational'
|
|||||||
|
|
||||||
begin
|
begin
|
||||||
require 'active_support/core_ext'
|
require 'active_support/core_ext'
|
||||||
require 'active_support/hash_with_indifferent_access'
|
|
||||||
Time.zone = "Pacific Time (US & Canada)"
|
Time.zone = "Pacific Time (US & Canada)"
|
||||||
Zone = Time.zone.now
|
Zone = Time.zone.now
|
||||||
rescue LoadError
|
rescue LoadError
|
||||||
warn 'Could not test BSON with HashWithIndifferentAccess.'
|
warn 'Mocking time with zone'
|
||||||
module ActiveSupport
|
module ActiveSupport
|
||||||
class TimeWithZone
|
class TimeWithZone
|
||||||
end
|
end
|
||||||
@ -523,20 +522,22 @@ class BSONTest < Test::Unit::TestCase
|
|||||||
BSON::BSON_CODER.serialize(c, false, false).to_s
|
BSON::BSON_CODER.serialize(c, false, false).to_s
|
||||||
end
|
end
|
||||||
|
|
||||||
if defined?(HashWithIndifferentAccess)
|
# Mocking this class for testing
|
||||||
def test_keep_id_with_hash_with_indifferent_access
|
class ::HashWithIndifferentAccess < Hash; end
|
||||||
doc = HashWithIndifferentAccess.new
|
|
||||||
embedded = HashWithIndifferentAccess.new
|
|
||||||
embedded['_id'] = ObjectID.new
|
|
||||||
doc['_id'] = ObjectID.new
|
|
||||||
doc['embedded'] = [embedded]
|
|
||||||
BSON::BSON_CODER.serialize(doc, false, true).to_a
|
|
||||||
assert doc.has_key?("_id")
|
|
||||||
assert doc['embedded'][0].has_key?("_id")
|
|
||||||
|
|
||||||
doc['_id'] = ObjectID.new
|
def test_keep_id_with_hash_with_indifferent_access
|
||||||
BSON::BSON_CODER.serialize(doc, false, true).to_a
|
doc = HashWithIndifferentAccess.new
|
||||||
assert doc.has_key?("_id")
|
embedded = HashWithIndifferentAccess.new
|
||||||
end
|
embedded['_id'] = ObjectID.new
|
||||||
|
doc['_id'] = ObjectID.new
|
||||||
|
doc['embedded'] = [embedded]
|
||||||
|
BSON::BSON_CODER.serialize(doc, false, true).to_a
|
||||||
|
assert doc.has_key?("_id")
|
||||||
|
assert doc['embedded'][0].has_key?("_id")
|
||||||
|
|
||||||
|
doc['_id'] = ObjectID.new
|
||||||
|
BSON::BSON_CODER.serialize(doc, false, true).to_a
|
||||||
|
assert doc.has_key?("_id")
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user