Skip to content

Commit

Permalink
Merge pull request #6213 from cobbspur/getPaginationFix
Browse files Browse the repository at this point in the history
Ensure {{get}} helper returns pagination
  • Loading branch information
ErisDS committed Dec 15, 2015
2 parents 9eb065d + 0ce4078 commit 7fea696
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
3 changes: 2 additions & 1 deletion core/server/helpers/get.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,10 @@ get = function get(context, options) {
}

// block params allows the theme developer to name the data using something like
// `{{#get "posts" as |result pagination|}}`
// `{{#get "posts" as |result pageInfo|}}`
blockParams = [result[context]];
if (result.meta && result.meta.pagination) {
result.pagination = result.meta.pagination;
blockParams.push(result.meta.pagination);
}

Expand Down
32 changes: 30 additions & 2 deletions core/test/unit/server_helpers/get_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ describe('{{#get}} helper', function () {
readTagsStub = sandbox.stub(api.tags, 'read').returns(new Promise.resolve({tags: []}));
readUsersStub = sandbox.stub(api.users, 'read').returns(new Promise.resolve({users: []}));

browsePostsStub.returns(new Promise.resolve({posts: testPostsArr}));
browsePostsStub.returns(new Promise.resolve({posts: testPostsArr, meta: meta}));
browsePostsStub.withArgs({limit: '3'}).returns(new Promise.resolve({posts: testPostsArr.slice(0, 3), meta: meta}));
browsePostsStub.withArgs({limit: '1'}).returns(new Promise.resolve({posts: testPostsArr.slice(0, 1)}));
browsePostsStub.withArgs({filter: 'tags:test'}).returns(new Promise.resolve({posts: testPostsArr.slice(2, 3)}));
Expand All @@ -76,6 +76,35 @@ describe('{{#get}} helper', function () {
}).catch(done);
});

it('should return pagination and meta pagination with default browse posts call', function (done) {
helpers.get.call(
{},
'posts',
{hash: {}, fn: fn, inverse: inverse}
).then(function () {
fn.firstCall.args[0].pagination.should.be.an.Object;
fn.firstCall.args[0].meta.should.be.an.Object;
fn.firstCall.args[0].meta.pagination.should.be.an.Object;
inverse.called.should.be.false;

done();
}).catch(done);
});

it('should not return pagination if meta pagination does not exist', function (done) {
helpers.get.call(
{},
'posts',
{hash: {limit: '1'}, fn: fn, inverse: inverse}
).then(function () {
should.not.exist(fn.firstCall.args[0].pagination);
should.not.exist(fn.firstCall.args[0].meta);
inverse.called.should.be.false;

done();
}).catch(done);
});

it('should handle browse posts call with limit 3', function (done) {
helpers.get.call(
{},
Expand Down Expand Up @@ -331,4 +360,3 @@ describe('{{#get}} helper', function () {
});
});
});

0 comments on commit 7fea696

Please sign in to comment.