Skip to content

Commit

Permalink
fix: prev next posts
Browse files Browse the repository at this point in the history
  • Loading branch information
kirrg001 authored and geekhuyang committed Nov 20, 2016
1 parent 6c55a30 commit ebd59bf
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 4 deletions.
2 changes: 1 addition & 1 deletion core/server/models/post.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
32 changes: 29 additions & 3 deletions core/test/integration/api/api_posts_spec.js
Original file line number Diff line number Diff line change
@@ -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];
Expand Down

0 comments on commit ebd59bf

Please # to comment.