Skip to content

Commit

Permalink
Post sort fix (#2262)
Browse files Browse the repository at this point in the history
* yarn lock file

* Fix post order bug where posts where ordered oldest to newest.
Updated tests to check for every posts prev and next properties.

* gitignore yarn.lock
  • Loading branch information
KernelPanicAUS authored and NoahDragon committed Dec 2, 2016
1 parent 2be8f50 commit e4ab1be
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ node_modules/
tmp/
*.log
.idea/
coverage/
coverage/
yarn.lock
2 changes: 1 addition & 1 deletion lib/plugins/generator/post.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

function postGenerator(locals) {
var posts = locals.posts.sort('-date').toArray();
var posts = locals.posts.sort('date').toArray();
var length = posts.length;

return posts.map(function(post, i) {
Expand Down
15 changes: 10 additions & 5 deletions test/scripts/generators/post.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,19 @@ describe('post', function() {
{source: 'baz', slug: 'baz', date: 1e8 - 1}
]).then(function(posts) {
return generator(locals()).then(function(data) {
should.not.exist(data[0].data.prev);
data[0].data.next._id.should.eql(posts[0]._id);

data[1].data.prev._id.should.eql(posts[1]._id);
data[1].data.next._id.should.eql(posts[2]._id);
// Posts should be sorted by date
data[0].data._id.should.eql(posts[2]._id);
data[1].data._id.should.eql(posts[0]._id);
data[2].data._id.should.eql(posts[1]._id);

data[2].data.prev._id.should.eql(posts[0]._id);
data[0].data.next._id.should.eq(posts[0]._id);
data[1].data.next._id.should.eq(posts[1]._id);
should.not.exist(data[2].data.next);

should.not.exist(data[0].data.prev);
data[1].data.prev._id.should.eq(posts[2]._id);
data[2].data.prev._id.should.eq(posts[0]._id);
}).thenReturn(posts);
}).map(function(post) {
return post.remove();
Expand Down

0 comments on commit e4ab1be

Please sign in to comment.