From 3b355a630db92a68621159769dec8bf3c74f2bf4 Mon Sep 17 00:00:00 2001 From: Louis Chatriot Date: Sat, 26 Jul 2014 12:52:20 +0200 Subject: [PATCH] Added a test --- .gitignore | 3 +++ lib/model.js | 3 +-- test/model.test.js | 1 + 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 08d7879..00ce13c 100644 --- a/.gitignore +++ b/.gitignore @@ -17,3 +17,6 @@ node_modules browser-version/src browser-version/node_modules + +*.swp +*~ diff --git a/lib/model.js b/lib/model.js index 5bbf1f7..18a8023 100644 --- a/lib/model.js +++ b/lib/model.js @@ -72,8 +72,7 @@ function serialize (obj) { if (v === null) { return null; } // Hackish way of checking if object is Date (this way it works between execution contexts in node-webkit). - // We can't use value directly because for dates it is already string in this function (date.toJSON was already called), - // fortunately "this" is bound here to object which is owner of the key. + // We can't use value directly because for dates it is already string in this function (date.toJSON was already called), so we use this if (typeof this[k].getTime === 'function') { return { $$date: this[k].getTime() }; } return v; diff --git a/test/model.test.js b/test/model.test.js index 499bbdf..d1057b8 100644 --- a/test/model.test.js +++ b/test/model.test.js @@ -82,6 +82,7 @@ describe('Model', function () { b = model.serialize(a); c = model.deserialize(b); b.indexOf('\n').should.equal(-1); + b.should.equal('{"test":{"$$date":' + d.getTime() + '}}'); util.isDate(c.test).should.equal(true); c.test.getTime().should.equal(d.getTime()); });