From 221345ff99f9a352a6a94e24f8dbc5bc4faf2b8c Mon Sep 17 00:00:00 2001 From: Hannah Wolfe Date: Mon, 8 Jul 2013 12:39:11 +0100 Subject: [PATCH] issue #234 - date bug - updated fixtures so that even short-term we have valid data - added methods to the base model that marshall the data in and out of the db so it is always an RFC 2822 date never ISO 8601 - turned off SQL debugging now the bug is resolved - minor change to the date listing template, as we don't need to check for updated_at now that the data is correct - but should use published date anyway --- config.js | 2 +- core/admin/assets/tpl/list-item.hbs | 9 +++++---- core/shared/data/fixtures/001.js | 12 ++++++++---- core/shared/models/base.js | 30 +++++++++++++++++++++++++++++ 4 files changed, 44 insertions(+), 9 deletions(-) diff --git a/config.js b/config.js index 2efb35f99f..4d78613143 100644 --- a/config.js +++ b/config.js @@ -86,7 +86,7 @@ config.env = { connection: { filename: path.join(__dirname, '/core/shared/data/ghost-dev.db') }, - debug: true + debug: false }, url: { host: '127.0.0.1', diff --git a/core/admin/assets/tpl/list-item.hbs b/core/admin/assets/tpl/list-item.hbs index 8b78a33607..1d1dcd37a0 100644 --- a/core/admin/assets/tpl/list-item.hbs +++ b/core/admin/assets/tpl/list-item.hbs @@ -2,10 +2,11 @@

{{title}}

{{!1,934}}
diff --git a/core/shared/data/fixtures/001.js b/core/shared/data/fixtures/001.js index effac94613..91e9fc9c2d 100644 --- a/core/shared/data/fixtures/001.js +++ b/core/shared/data/fixtures/001.js @@ -17,9 +17,11 @@ module.exports = { "status": "published", "featured": true, "author_id": 1, - "created_at": '2012-11-09T15:40:46.776Z', + "created_at": '1352475600601', "created_by": 1, - "published_at": '2012-11-09T15:40:46.776Z', + "updated_at": '1352475600601', + "updated_by": 1, + "published_at": '1352475600601', "published_by": 1 }, { @@ -36,9 +38,11 @@ module.exports = { "status": "published", "featured": true, "author_id": 1, - "created_at": '2012-06-25T01:00:23.776Z', + "created_at": '1340582400102', "created_by": 1, - "published_at": '2012-06-25T01:00:23.776Z', + "updated_at": '1340582400102', + "updated_by": 1, + "published_at": '1340582400102', "published_by": 1 } ], diff --git a/core/shared/models/base.js b/core/shared/models/base.js index 9fc8f843cf..3a0fb51086 100644 --- a/core/shared/models/base.js +++ b/core/shared/models/base.js @@ -1,5 +1,6 @@ var GhostBookshelf, Bookshelf = require('bookshelf'), + _ = require('underscore'), config = require('../../../config'); // Initializes Bookshelf as its own instance, so we can modify the Models and not mess up @@ -11,6 +12,35 @@ GhostBookshelf = Bookshelf.Initialize('ghost', config.env[process.env.NODE_ENV | GhostBookshelf.Model = GhostBookshelf.Model.extend({ // Base prototype properties will go here + // Fix problems with dates + fixDates: function (attrs) { + _.each(attrs, function (value, key) { + if (key.substr(-3) === '_at' && value !== null) { + attrs[key] = new Date(attrs[key]); + } + }); + + return attrs; + }, + + format: function (attrs) { + return this.fixDates(attrs); + }, + + toJSON: function (options) { + var attrs = this.fixDates(_.extend({}, this.attributes)), + relations = this.relations; + + if (options && options.shallow) { + return attrs; + } + + _.each(relations, function (key) { + attrs[key] = relations[key].toJSON(); + }); + + return attrs; + } }, {