From f8ba12481d6c84dd0798f4fdc3325c2bbfea6a10 Mon Sep 17 00:00:00 2001 From: kirrg001 Date: Mon, 20 Jun 2016 15:38:29 +0200 Subject: [PATCH] fix: prev next posts closes #7015 --- core/server/models/post.js | 2 +- core/test/integration/api/api_posts_spec.js | 32 +++++++++++++++++++-- 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/core/server/models/post.js b/core/server/models/post.js index 026e01af0b..f819ba80af 100644 --- a/core/server/models/post.js +++ b/core/server/models/post.js @@ -551,7 +551,7 @@ Post = ghostBookshelf.Model.extend({ return ghostBookshelf.Model.findOne.call(this, data, options).then(function then(post) { if ((withNext || withPrev) && post && !post.page) { - var publishedAt = post.get('published_at'), + var publishedAt = moment(post.get('published_at')).format('YYYY-MM-DD HH:mm:ss'), prev, next; diff --git a/core/test/integration/api/api_posts_spec.js b/core/test/integration/api/api_posts_spec.js index f63098452b..3d74b1ff8a 100644 --- a/core/test/integration/api/api_posts_spec.js +++ b/core/test/integration/api/api_posts_spec.js @@ -1,14 +1,40 @@ -var testUtils = require('../../utils'), +var Promise = require('bluebird'), should = require('should'), _ = require('lodash'), + testUtils = require('../../utils'), errors = require('../../../server/errors'), + db = require('../../../server/data/db'), + models = require('../../../server/models'), PostAPI = require('../../../server/api/posts'); describe('Post API', function () { - // Keep the DB clean before(testUtils.teardown); afterEach(testUtils.teardown); - beforeEach(testUtils.setup('users:roles', 'perms:post', 'posts', 'perms:init')); + beforeEach(testUtils.setup('users:roles', 'perms:post', 'perms:init')); + + // @TODO: remove when https://github.com/TryGhost/Ghost/issues/6930 is fixed + // we insert the posts via the model layer, because right now the test utils insert dates wrong + beforeEach(function (done) { + Promise.mapSeries(testUtils.DataGenerator.forKnex.posts, function (post) { + return models.Post.add(post, {context: {internal:true}}); + }).then(function () { + done(); + }).catch(done); + }); + beforeEach(function (done) { + Promise.mapSeries(testUtils.DataGenerator.forKnex.tags, function (tag) { + return models.Tag.add(tag, {context: {internal:true}}); + }).then(function () { + done(); + }).catch(done); + }); + beforeEach(function (done) { + db.knex('posts_tags').insert(testUtils.DataGenerator.forKnex.posts_tags) + .then(function () { + done(); + }) + .catch(done); + }); function extractFirstPost(posts) { return _.filter(posts, {id: 1})[0];