RUBY-139 Use BSON binary subtype 0 by default

This commit is contained in:
Kyle Banker 2011-03-29 12:25:48 -04:00
parent 3509926071
commit db1213fc5d
2 changed files with 17 additions and 3 deletions

View File

@ -43,7 +43,7 @@ module BSON
# SUBTYPE_BYTES, SUBTYPE_UUID, SUBTYPE_MD5, and SUBTYPE_USER_DEFINED.
#
# @see http://www.mongodb.org/display/DOCS/BSON#BSON-noteondatabinary BSON binary subtypes.
def initialize(data=[], subtype=SUBTYPE_BYTES)
def initialize(data=[], subtype=SUBTYPE_SIMPLE)
super(data)
@subtype = subtype
end

View File

@ -329,6 +329,20 @@ class BSONTest < Test::Unit::TestCase
bin = Binary.new
'binstring'.each_byte { |b| bin.put(b) }
doc = {'bin' => bin}
bson = @encoder.serialize(doc)
doc2 = @encoder.deserialize(bson)
bin2 = doc2['bin']
assert_kind_of Binary, bin2
assert_equal 'binstring', bin2.to_s
assert_equal Binary::SUBTYPE_SIMPLE, bin2.subtype
end
def test_binary_with_deprecated_subtype
bin = Binary.new
'binstring'.each_byte { |b| bin.put(b) }
bin.subtype = Binary::SUBTYPE_BYTES
doc = {'bin' => bin}
bson = @encoder.serialize(doc)
doc2 = @encoder.deserialize(bson)
@ -346,7 +360,7 @@ class BSONTest < Test::Unit::TestCase
bin2 = doc2['bin']
assert_kind_of Binary, bin2
assert_equal 'somebinarystring', bin2.to_s
assert_equal Binary::SUBTYPE_BYTES, bin2.subtype
assert_equal Binary::SUBTYPE_SIMPLE, bin2.subtype
end
def test_binary_type
@ -386,7 +400,7 @@ class BSONTest < Test::Unit::TestCase
bin2 = doc2['bin']
assert_kind_of Binary, bin2
assert_equal [1, 2, 3, 4, 5], bin2.to_a
assert_equal Binary::SUBTYPE_BYTES, bin2.subtype
assert_equal Binary::SUBTYPE_SIMPLE, bin2.subtype
end
def test_put_id_first