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) {
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;
}
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) {
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;
}
buffer_free(buffer);

View File

@ -578,7 +578,7 @@ class BSON_RUBY
when MinKey
MINKEY
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
raise InvalidDocument, "#{o.class} is not currently supported; " +
"use a UTC Time instance instead."
@ -587,7 +587,7 @@ class BSON_RUBY
raise InvalidDocument, "ActiveSupport::TimeWithZone is not currently supported; " +
"use a UTC Time instance instead."
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

View File

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