tests + fix for deserializing pre-epoch dates w/ pure Ruby BSON deserializer - thanks chendo
This commit is contained in:
parent
b6901673bb
commit
d95971b20b
@ -248,8 +248,10 @@ class BSON
|
|||||||
end
|
end
|
||||||
|
|
||||||
def deserialize_date_data(buf)
|
def deserialize_date_data(buf)
|
||||||
millisecs = buf.get_long()
|
unsigned = buf.get_long()
|
||||||
Time.at(millisecs.to_f / 1000.0).utc # at() takes fractional seconds
|
# see note for deserialize_number_long_data below
|
||||||
|
milliseconds = unsigned >= 2 ** 64 / 2 ? unsigned - 2**64 : unsigned
|
||||||
|
Time.at(milliseconds.to_f / 1000.0).utc # at() takes fractional seconds
|
||||||
end
|
end
|
||||||
|
|
||||||
def deserialize_boolean_data(buf)
|
def deserialize_boolean_data(buf)
|
||||||
|
@ -124,6 +124,14 @@ class BSONTest < Test::Unit::TestCase
|
|||||||
assert doc2['date'].utc?
|
assert doc2['date'].utc?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_date_before_epoch
|
||||||
|
doc = {'date' => Time.utc(1600)}
|
||||||
|
@b.serialize(doc)
|
||||||
|
doc2 = @b.deserialize
|
||||||
|
# Mongo only stores up to the millisecond
|
||||||
|
assert_in_delta doc['date'], doc2['date'], 0.001
|
||||||
|
end
|
||||||
|
|
||||||
def test_dbref
|
def test_dbref
|
||||||
oid = ObjectID.new
|
oid = ObjectID.new
|
||||||
doc = {}
|
doc = {}
|
||||||
|
@ -182,6 +182,11 @@ class TestCollection < Test::Unit::TestCase
|
|||||||
assert c.closed?
|
assert c.closed?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_saving_dates_pre_epoch
|
||||||
|
@@test.save({'date' => Time.utc(1600)})
|
||||||
|
assert_in_delta Time.utc(1600), @@test.find_one()["date"], 0.001
|
||||||
|
end
|
||||||
|
|
||||||
def test_save_symbol_find_string
|
def test_save_symbol_find_string
|
||||||
@@test.save(:foo => :mike)
|
@@test.save(:foo => :mike)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user