warn if using Date or DateTime instead of Time
This commit is contained in:
parent
77df695bca
commit
42b835243e
@ -369,6 +369,11 @@ static int write_element_allow_id(VALUE key, VALUE value, VALUE extra, int allow
|
|||||||
SAFE_WRITE_AT_POS(buffer, length_location, (const char*)&obj_length, 4);
|
SAFE_WRITE_AT_POS(buffer, length_location, (const char*)&obj_length, 4);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
if (strcmp(cls, "DateTime") == 0 || strcmp(cls, "Date") == 0) {
|
||||||
|
buffer_free(buffer);
|
||||||
|
rb_raise(InvalidDocument, "Trying to use Date or DateTime; the driver currently supports Time objects only.",
|
||||||
|
TYPE(value));
|
||||||
|
}
|
||||||
buffer_free(buffer);
|
buffer_free(buffer);
|
||||||
rb_raise(InvalidDocument, "Unsupported type for BSON (%d)", TYPE(value));
|
rb_raise(InvalidDocument, "Unsupported type for BSON (%d)", TYPE(value));
|
||||||
break;
|
break;
|
||||||
|
@ -39,7 +39,8 @@ module Mongo
|
|||||||
# Raised on failures in connection to the database server.
|
# Raised on failures in connection to the database server.
|
||||||
class ConnectionTimeoutError < MongoRubyError; end
|
class ConnectionTimeoutError < MongoRubyError; end
|
||||||
|
|
||||||
# Raised when trying to insert a document that exceeds the 4MB limit.
|
# Raised when trying to insert a document that exceeds the 4MB limit or
|
||||||
|
# when the document contains objects that can't be serialized as BSON.
|
||||||
class InvalidDocument < MongoDBError; end
|
class InvalidDocument < MongoDBError; end
|
||||||
|
|
||||||
# Raised when a database operation fails.
|
# Raised when a database operation fails.
|
||||||
|
@ -553,6 +553,8 @@ class BSON_RUBY
|
|||||||
OBJECT
|
OBJECT
|
||||||
when Symbol
|
when Symbol
|
||||||
SYMBOL
|
SYMBOL
|
||||||
|
when Date, DateTime
|
||||||
|
raise InvalidDocument, "Trying to use Date or DateTime; the driver currently supports Time objects only."
|
||||||
else
|
else
|
||||||
raise InvalidDocument, "Unknown type of object: #{o.class.name}"
|
raise InvalidDocument, "Unknown type of object: #{o.class.name}"
|
||||||
end
|
end
|
||||||
|
@ -181,6 +181,19 @@ class BSONTest < Test::Unit::TestCase
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_exeption_on_using_date
|
||||||
|
[DateTime.now, Date.today].each do |invalid_date|
|
||||||
|
doc = {:date => invalid_date}
|
||||||
|
begin
|
||||||
|
bson = BSON.serialize(doc)
|
||||||
|
rescue => e
|
||||||
|
ensure
|
||||||
|
assert_equal InvalidDocument, e.class
|
||||||
|
assert_match /Time/, e.message
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def test_dbref
|
def test_dbref
|
||||||
oid = ObjectID.new
|
oid = ObjectID.new
|
||||||
doc = {}
|
doc = {}
|
||||||
|
Loading…
Reference in New Issue
Block a user