From b8215bd40fe1fd45325388cd76367e57da65fe58 Mon Sep 17 00:00:00 2001 From: Louis Chatriot Date: Sat, 4 May 2013 13:42:55 +0200 Subject: [PATCH] Able to persist complex objects too --- test/db.test.js | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/test/db.test.js b/test/db.test.js index d45fa9b..92f3b31 100644 --- a/test/db.test.js +++ b/test/db.test.js @@ -82,6 +82,30 @@ describe('Database', function () { }); }); + it('Can insert and get back from DB complex objects with all primitive and secondary types', function (done) { + var da = new Date() + , obj = { a: ['ee', 'ff', 42], date: da, subobj: { a: 'b', b: 'c' } } + , d = new Datastore(testDb) + ; + + d.loadDatabase(function () { + d.insert(obj, function (err) { + d.findOne({}, function (err, res) { + assert.isNull(err); + res.a.length.should.equal(3); + res.a[0].should.equal('ee'); + res.a[1].should.equal('ff'); + res.a[2].should.equal(42); + res.date.getTime().should.equal(da.getTime()); + res.subobj.a.should.equal('b'); + res.subobj.b.should.equal('c'); + + done(); + }); + }); + }); + }); + }); // ==== End of 'Insert' ==== //