diff --git a/core/server/helpers/index.js b/core/server/helpers/index.js index a2218b7a4e..6025300397 100644 --- a/core/server/helpers/index.js +++ b/core/server/helpers/index.js @@ -155,14 +155,13 @@ coreHelpers = function (ghost) { return; } if (_.isUndefined(this.pagination.page) || _.isUndefined(this.pagination.pages) - || _.isUndefined(this.pagination.total) || _.isUndefined(this.pagination.limit) - || _.isUndefined(this.pagination.prev) || _.isUndefined(this.pagination.prev)) { - errors.logAndThrowError('All values must be defined for page, pages, limit, total, prev and next'); + || _.isUndefined(this.pagination.total) || _.isUndefined(this.pagination.limit)) { + errors.logAndThrowError('All values must be defined for page, pages, limit and total'); return; } - if ((!_.isNumber(this.pagination.next) && !_.isNull(this.pagination.next)) - || (!_.isNumber(this.pagination.prev) && !_.isNull(this.pagination.prev))) { - errors.logAndThrowError('Invalid value, Next/Prev must be a number or null'); + if ((!_.isUndefined(this.pagination.next) && !_.isNumber(this.pagination.next)) + || (!_.isUndefined(this.pagination.prev) && !_.isNumber(this.pagination.prev))) { + errors.logAndThrowError('Invalid value, Next/Prev must be a number'); return; } if (!_.isNumber(this.pagination.page) || !_.isNumber(this.pagination.pages) diff --git a/core/test/ghost/frontend_helpers_index_spec.js b/core/test/ghost/frontend_helpers_index_spec.js index 61c325366b..61ad98a788 100644 --- a/core/test/ghost/frontend_helpers_index_spec.js +++ b/core/test/ghost/frontend_helpers_index_spec.js @@ -78,7 +78,7 @@ describe('Core Helpers', function () { it('can render single page with no pagination necessary', function (done) { var rendered; helpers.loadCoreHelpers(ghost).then(function () { - rendered = handlebars.helpers.paginate.call({pagination: {page: 1, prev: null, next: null, limit: 15, total: 8, pages: 1}}); + rendered = handlebars.helpers.paginate.call({pagination: {page: 1, prev: undefined, next: undefined, limit: 15, total: 8, pages: 1}}); should.exist(rendered); rendered.string.should.equal('\n'); done(); @@ -88,7 +88,7 @@ describe('Core Helpers', function () { it('can render first page of many with older posts link', function (done) { var rendered; helpers.loadCoreHelpers(ghost).then(function () { - rendered = handlebars.helpers.paginate.call({pagination: {page: 1, prev: null, next: 2, limit: 15, total: 8, pages: 3}}); + rendered = handlebars.helpers.paginate.call({pagination: {page: 1, prev: undefined, next: 2, limit: 15, total: 8, pages: 3}}); should.exist(rendered); rendered.string.should.equal('\n'); done(); @@ -108,7 +108,7 @@ describe('Core Helpers', function () { it('can render last page of many with newer posts link', function (done) { var rendered; helpers.loadCoreHelpers(ghost).then(function () { - rendered = handlebars.helpers.paginate.call({pagination: {page: 3, prev: 2, next: null, limit: 15, total: 8, pages: 3}}); + rendered = handlebars.helpers.paginate.call({pagination: {page: 3, prev: 2, next: undefined, limit: 15, total: 8, pages: 3}}); should.exist(rendered); rendered.string.should.equal('\n'); done(); @@ -123,29 +123,27 @@ describe('Core Helpers', function () { }; }; - runErrorTest({pagination: {page: 3, prev: true, next: null, limit: 15, total: 8, pages: 3}}) - .should.throwError('Invalid value, Next/Prev must be a number or null'); + runErrorTest({pagination: {page: 3, prev: true, next: undefined, limit: 15, total: 8, pages: 3}}) + .should.throwError('Invalid value, Next/Prev must be a number'); runErrorTest({pagination: {page: 3, prev: 2, next: true, limit: 15, total: 8, pages: 3}}) - .should.throwError('Invalid value, Next/Prev must be a number or null'); + .should.throwError('Invalid value, Next/Prev must be a number'); - runErrorTest({pagination: {prev: 2, next: null, limit: 15, total: 8, pages: 3}}) - .should.throwError('All values must be defined for page, pages, limit, total, prev and next'); - runErrorTest({pagination: {page: 3, next: null, limit: 15, total: 8, pages: 3}}) - .should.throwError('All values must be defined for page, pages, limit, total, prev and next'); - runErrorTest({pagination: {page: 3, prev: 2, next: null, total: 8, pages: 3}}) - .should.throwError('All values must be defined for page, pages, limit, total, prev and next'); - runErrorTest({pagination: {page: 3, prev: 2, next: null, limit: 15,pages: 3}}) - .should.throwError('All values must be defined for page, pages, limit, total, prev and next'); - runErrorTest({pagination: {page: 3, prev: 2, next: null, limit: 15, total: 8}}) - .should.throwError('All values must be defined for page, pages, limit, total, prev and next'); + runErrorTest({pagination: {limit: 15, total: 8, pages: 3}}) + .should.throwError('All values must be defined for page, pages, limit and total'); + runErrorTest({pagination: {page: 3, total: 8, pages: 3}}) + .should.throwError('All values must be defined for page, pages, limit and total'); + runErrorTest({pagination: {page: 3, limit: 15, pages: 3}}) + .should.throwError('All values must be defined for page, pages, limit and total'); + runErrorTest({pagination: {page: 3, limit: 15, total: 8}}) + .should.throwError('All values must be defined for page, pages, limit and total'); - runErrorTest({pagination: {page: null, prev: 2, next: null, limit: 15, total: 8, pages: 3}}) + runErrorTest({pagination: {page: null, limit: 15, total: 8, pages: 3}}) .should.throwError('Invalid value, check page, pages, limit and total are numbers'); - runErrorTest({pagination: {page: 1, prev: 2, next: null, limit: null, total: 8, pages: 3}}) + runErrorTest({pagination: {page: 1, limit: null, total: 8, pages: 3}}) .should.throwError('Invalid value, check page, pages, limit and total are numbers'); - runErrorTest({pagination: {page: 1, prev: 2, next: null, limit: 15, total: null, pages: 3}}) + runErrorTest({pagination: {page: 1, limit: 15, total: null, pages: 3}}) .should.throwError('Invalid value, check page, pages, limit and total are numbers'); - runErrorTest({pagination: {page: 1, prev: 2, next: null, limit: 15, total: 8, pages: null}}) + runErrorTest({pagination: {page: 1, limit: 15, total: 8, pages: null}}) .should.throwError('Invalid value, check page, pages, limit and total are numbers'); done();