Skip to content

Commit

Permalink
Adds typecasting to parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
cgarvis committed Oct 11, 2012
1 parent c992dc9 commit 0184238
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/pagination.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
var mongoose = require('mongoose');

mongoose.Query.prototype.paginate = function paginate (page, limit, cb) {
page = page || 1;
limit = limit || 10;
page = parseInt(page, 10) || 1;
limit = parseInt(limit, 10) || 10;

var query = this;
var model = this.model;
Expand Down
6 changes: 6 additions & 0 deletions test/paginate.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,9 @@ describe 'Mongoose Pagination', ->
query.options.should.include.keys 'skip', 'limit'
query.options.skip.should.be.eq 30
query.options.limit.should.be.eq 15

it 'should skip 30 when page is "3" and limit is "15"', ->
query.paginate "3", "15"
query.options.should.include.keys 'skip', 'limit'
query.options.skip.should.be.eq 30
query.options.limit.should.be.eq 15

0 comments on commit 0184238

Please sign in to comment.