minor: fix for 1.8.6 Complex type checking

This commit is contained in:
Kyle Banker 2010-01-21 15:42:59 -05:00
parent 33c848f67a
commit 28227f8ac6
3 changed files with 5 additions and 7 deletions

View File

@ -386,7 +386,7 @@ static int write_element_allow_id(VALUE key, VALUE value, VALUE extra, int allow
} }
if(strcmp(cls, "Complex") == 0 || strcmp(cls, "Rational") == 0 || strcmp(cls, "BigDecimal") == 0) { if(strcmp(cls, "Complex") == 0 || strcmp(cls, "Rational") == 0 || strcmp(cls, "BigDecimal") == 0) {
buffer_free(buffer); buffer_free(buffer);
rb_raise(InvalidDocument, "The Numeric type %s cannot be encoded as BSON; only Bignum, Fixnum, and Float are supported.", cls); rb_raise(InvalidDocument, "Cannot serialize the Numeric type %s as BSON; only Bignum, Fixnum, and Float are supported.", cls);
break; break;
} }
buffer_free(buffer); buffer_free(buffer);
@ -405,7 +405,7 @@ static int write_element_allow_id(VALUE key, VALUE value, VALUE extra, int allow
} }
if(strcmp(cls, "BigDecimal") == 0) { if(strcmp(cls, "BigDecimal") == 0) {
buffer_free(buffer); buffer_free(buffer);
rb_raise(InvalidDocument, "The Numeric type %s cannot be encoded as BSON; only Bignum, Fixnum, and Float are supported.", cls); rb_raise(InvalidDocument, "Cannot serialize the Numeric type %s as BSON; only Bignum, Fixnum, and Float are supported.", cls);
break; break;
} }
buffer_free(buffer); buffer_free(buffer);

View File

@ -578,7 +578,7 @@ class BSON_RUBY
when MinKey when MinKey
MINKEY MINKEY
when Numeric when Numeric
raise InvalidDocument, "The Numeric type #{o.class} cannot be encoded as BSON; only Fixum, Bignum, and Float are supported." raise InvalidDocument, "Cannot serialize the Numeric type #{o.class} as BSON; only Fixum, Bignum, and Float are supported."
when Date, DateTime when Date, DateTime
raise InvalidDocument, "#{o.class} is not currently supported; " + raise InvalidDocument, "#{o.class} is not currently supported; " +
"use a UTC Time instance instead." "use a UTC Time instance instead."
@ -587,7 +587,7 @@ class BSON_RUBY
raise InvalidDocument, "ActiveSupport::TimeWithZone is not currently supported; " + raise InvalidDocument, "ActiveSupport::TimeWithZone is not currently supported; " +
"use a UTC Time instance instead." "use a UTC Time instance instead."
else else
raise InvalidDocument, "#{o.class} isn't supported as a BSON type." raise InvalidDocument, "Cannot serialize #{o.class} as a BSON type; it either isn't supported or won't translate to BSON."
end end
end end
end end

View File

@ -198,7 +198,6 @@ class BSONTest < Test::Unit::TestCase
bson = BSON.serialize(doc) bson = BSON.serialize(doc)
rescue => e rescue => e
ensure ensure
puts e.message
assert_equal InvalidDocument, e.class assert_equal InvalidDocument, e.class
assert_match /UTC Time/, e.message assert_match /UTC Time/, e.message
end end
@ -319,14 +318,13 @@ class BSONTest < Test::Unit::TestCase
def test_invalid_numeric_types def test_invalid_numeric_types
[BigDecimal.new("1.0"), Complex(0, 1), Rational(2, 3)].each do |type| [BigDecimal.new("1.0"), Complex(0, 1), Rational(2, 3)].each do |type|
print type.class
doc = {"x" => type} doc = {"x" => type}
begin begin
BSON.serialize(doc) BSON.serialize(doc)
rescue => e rescue => e
ensure ensure
assert_equal InvalidDocument, e.class assert_equal InvalidDocument, e.class
assert_match /Numeric type #{type.class}/, e.message assert_match /Cannot serialize/, e.message
end end
end end
end end