0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-01-20 22:42:53 -05:00

Merge pull request #6721 from ErisDS/page-url-fix

Fixing undefined page case for page_url helper
This commit is contained in:
Kevin Ansfield 2016-04-14 12:06:25 +01:00
commit 75f48b87b7
2 changed files with 14 additions and 0 deletions

View file

@ -15,6 +15,10 @@ var errors = require('../errors'),
pageUrl;
page_url = function (page, options) {
if (!options) {
options = page;
page = 1;
}
return getPaginatedUrl(page, options.data.root);
};

View file

@ -45,6 +45,14 @@ describe('{{page_url}} helper', function () {
helpers.page_url('next', options).should.eql('/tag/pumpkin/page/10/');
helpers.page_url('prev', options).should.eql('/tag/pumpkin/page/2/');
});
it('should assume 1 if page is undefined', function () {
options.data.root.relativeUrl = '/tag/pumpkin/';
options.data.root.pagination.next = 10;
options.data.root.pagination.prev = 2;
helpers.page_url(options).should.equal(helpers.page_url(1, options));
});
});
describe('{{pageUrl}} helper [DEPRECATED]', function () {
@ -63,6 +71,7 @@ describe('{{pageUrl}} helper [DEPRECATED]', function () {
options.data.root.pagination.next = 5;
options.data.root.pagination.prev = 7;
helpers.pageUrl(options).should.eql(helpers.page_url(options));
helpers.pageUrl(1, options).should.eql(helpers.page_url(1, options));
helpers.pageUrl(20, options).should.eql(helpers.page_url(20, options));
helpers.pageUrl('next', options).should.eql(helpers.page_url('next', options));
@ -74,6 +83,7 @@ describe('{{pageUrl}} helper [DEPRECATED]', function () {
options.data.root.pagination.next = 12;
options.data.root.pagination.prev = 9;
helpers.pageUrl(options).should.eql(helpers.page_url(options));
helpers.pageUrl(1, options).should.eql(helpers.page_url(1, options));
helpers.pageUrl(20, options).should.eql(helpers.page_url(20, options));
helpers.pageUrl('next', options).should.eql(helpers.page_url('next', options));