minor: fix for 1.8.6 Complex type checking
This commit is contained in:
parent
33c848f67a
commit
28227f8ac6
@ -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);
|
||||||
|
@ -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
|
||||||
|
@ -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
|
||||||
|
Loading…
Reference in New Issue
Block a user