Permalink
Browse files

Adds typecasting to parameters

  • Loading branch information...
1 parent c992dc9 commit 01842383e5d30c56d3aeec45c6f275cf06278e95 @cgarvis cgarvis committed Oct 11, 2012
Showing with 8 additions and 2 deletions.
  1. +2 −2 lib/pagination.js
  2. +6 −0 test/paginate.coffee
View
@@ -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;
View
@@ -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.