From 870d6af066a2cbd9bcd94c71797aa2c0d93b22ed Mon Sep 17 00:00:00 2001 From: cobbspur Date: Wed, 29 Jul 2015 02:23:04 +0100 Subject: [PATCH] Fix API query for featured posts No Issue - fixes bug where featured: false was not being built into query - adds tests --- core/server/models/post.js | 2 +- core/test/integration/api/api_posts_spec.js | 19 +++++++++++++++++++ core/test/utils/fixtures/data-generator.js | 3 ++- 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/core/server/models/post.js b/core/server/models/post.js index 4e66b99874..53a3e871af 100644 --- a/core/server/models/post.js +++ b/core/server/models/post.js @@ -314,7 +314,7 @@ Post = ghostBookshelf.Model.extend({ options.where.page = options.staticPages; } - if (options.featured) { + if (_.has(options, 'featured')) { // convert string true/false to boolean if (!_.isBoolean(options.featured)) { options.featured = _.contains(['true', '1'], options.featured); diff --git a/core/test/integration/api/api_posts_spec.js b/core/test/integration/api/api_posts_spec.js index 9fab4da78c..51205459e6 100644 --- a/core/test/integration/api/api_posts_spec.js +++ b/core/test/integration/api/api_posts_spec.js @@ -19,6 +19,25 @@ describe('Post API', function () { should.exist(PostAPI); + it('browse can fetch featured posts', function (done) { + PostAPI.browse({context: {user: 1}, featured: true}).then(function (results) { + should.exist(results.posts); + results.posts.length.should.eql(4); + results.posts[0].featured.should.eql(true); + + done(); + }).catch(done); + }); + + it('browse can exclude featured posts', function (done) { + PostAPI.browse({context: {user: 1}, status: 'all', featured: false}).then(function (results) { + should.exist(results.posts); + results.posts.length.should.eql(1); + + done(); + }).catch(done); + }); + it('can browse', function (done) { PostAPI.browse().then(function (results) { should.exist(results); diff --git a/core/test/utils/fixtures/data-generator.js b/core/test/utils/fixtures/data-generator.js index 2b7af20436..6e2774bdec 100644 --- a/core/test/utils/fixtures/data-generator.js +++ b/core/test/utils/fixtures/data-generator.js @@ -33,7 +33,8 @@ DataGenerator.Content = { slug: "unfinished", markdown: "

HTML Ipsum Presents

Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo. Quisque sit amet est et sapien ullamcorper pharetra. Vestibulum erat wisi, condimentum sed, commodo vitae, ornare sit amet, wisi. Aenean fermentum, elit eget tincidunt condimentum, eros ipsum rutrum orci, sagittis tempus lacus enim ac dui. Donec non enim in turpis pulvinar facilisis. Ut felis.

Header Level 2

  1. Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
  2. Aliquam tincidunt mauris eu risus.

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus magna. Cras in mi at felis aliquet congue. Ut a est eget ligula molestie gravida. Curabitur massa. Donec eleifend, libero at sagittis mollis, tellus est malesuada tellus, at luctus turpis elit sit amet quam. Vivamus pretium ornare est.

Header Level 3

#header h1 a{display: block;width: 300px;height: 80px;}
", status: "draft", - uuid: "d52c42ae-2755-455c-80ec-70b2ec55c903" + uuid: "d52c42ae-2755-455c-80ec-70b2ec55c903", + featured: false }, { title: "Not so short, bit complex",