mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-03-11 02:12:21 -05:00
🐛 Fixed ordering of unpublished draft posts
closes #8495 - Fixes ordering of posts when one of the drafts was previously published - Adds test coverage for ordering of unpublished drafts
This commit is contained in:
parent
2aaf4d6054
commit
9241a77935
2 changed files with 46 additions and 1 deletions
|
@ -504,7 +504,7 @@ Post = ghostBookshelf.Model.extend({
|
|||
'CASE WHEN posts.status = \'scheduled\' THEN 1 ' +
|
||||
'WHEN posts.status = \'draft\' THEN 2 ' +
|
||||
'ELSE 3 END ASC,' +
|
||||
'posts.published_at DESC,' +
|
||||
'CASE WHEN posts.status != \'draft\' THEN posts.published_at END DESC,' +
|
||||
'posts.updated_at DESC,' +
|
||||
'posts.id DESC';
|
||||
},
|
||||
|
|
|
@ -2,6 +2,7 @@ var should = require('should'),
|
|||
sinon = require('sinon'),
|
||||
testUtils = require('../../utils'),
|
||||
_ = require('lodash'),
|
||||
moment = require('moment'),
|
||||
ObjectId = require('bson-objectid'),
|
||||
Promise = require('bluebird'),
|
||||
configUtils = require('../../utils/configUtils'),
|
||||
|
@ -546,6 +547,50 @@ describe('Post API', function () {
|
|||
done();
|
||||
}).catch(done);
|
||||
});
|
||||
|
||||
it('can fetch all posts with correct order when unpublished draft is present', function (done) {
|
||||
testUtils.fixtures.insertPosts([{
|
||||
id: ObjectId.generate(),
|
||||
title: 'Not published draft post',
|
||||
slug: 'not-published-draft-post',
|
||||
status: 'draft',
|
||||
updated_at: moment().add(3, 'minutes').toDate(),
|
||||
published_at: null
|
||||
},
|
||||
{
|
||||
id: ObjectId.generate(),
|
||||
title: 'Unpublished post',
|
||||
slug: 'unpublished-post',
|
||||
status: 'draft',
|
||||
updated_at: moment().add(2, 'minutes').toDate(),
|
||||
published_at: moment().add(1, 'minutes').toDate()
|
||||
}])
|
||||
.then(function () {
|
||||
return PostAPI.browse({context: {internal: true}});
|
||||
})
|
||||
.then(function (results) {
|
||||
should.exist(results.posts);
|
||||
results.posts.length.should.eql(10);
|
||||
|
||||
results.posts[1].slug.should.eql('not-published-draft-post');
|
||||
results.posts[2].slug.should.eql('unpublished-post');
|
||||
|
||||
results.posts[0].status.should.eql('scheduled');
|
||||
|
||||
results.posts[1].status.should.eql('draft');
|
||||
results.posts[2].status.should.eql('draft');
|
||||
results.posts[3].status.should.eql('draft');
|
||||
results.posts[4].status.should.eql('draft');
|
||||
|
||||
results.posts[5].status.should.eql('published');
|
||||
results.posts[6].status.should.eql('published');
|
||||
results.posts[7].status.should.eql('published');
|
||||
results.posts[8].status.should.eql('published');
|
||||
results.posts[9].status.should.eql('published');
|
||||
|
||||
done();
|
||||
}).catch(done);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Read', function () {
|
||||
|
|
Loading…
Add table
Reference in a new issue