Permalink
Browse files

more tests, new formula

  • Loading branch information...
1 parent 4f4e0e6 commit e79f4bf76e2ebd060907877fd16f0d387fdc858f Edward Hotchkiss committed Dec 16, 2011
Showing with 7 additions and 5 deletions.
  1. +2 −1 lib/mongoose-paginate.js
  2. +1 −1 package.json
  3. +4 −3 test/index.test.js
View
@@ -15,7 +15,8 @@ var mongoose = require('mongoose');
mongoose.Model.paginate = function(q, pageNumber, resultsPerPage, callback){
callback = callback || function(){};
- var skipFrom = pageNumber * resultsPerPage;
+ // formula 1, hah.
+ var skipFrom = (pageNumber * resultsPerPage) - resultsPerPage;
var query = this.find(q).skip(skipFrom).limit(resultsPerPage);
query.exec(function(error, results) {
if (error) {
View
@@ -2,7 +2,7 @@
"author":"Edward Hotchkiss <e@ingk.com>",
"name":"mongoose-paginate",
"description":"Mongoose ORM (NodeJS) Document Query Pagination",
- "version":"0.0.2",
+ "version":"0.0.3",
"repository":{
"type":"git",
"url":"git://github.com/edwardhotchkiss/mongoose-paginate.git"
View
@@ -107,13 +107,14 @@ vows.describe('pagination module basic test')
})
.addBatch({
- 'when paginating BlogEntry querying for all documents, with page 1, 10 per page':{
+ 'when paginating BlogEntry querying for all documents, with page 2, 10 per page':{
topic:function(){
- BlogEntry.paginate({}, 1, 10, this.callback);
+ BlogEntry.paginate({}, 2, 10, this.callback);
},
- 'there should be no errors and results.length should be 10':function(error, results){
+ 'there should be no errors and results.length should be 10, and the first result should contain the correct # (11)':function(error, results){
assert.equal(error, null);
assert.equal(results.length, 10);
+ assert.equal(/#11/.test(results[0].title), true);
}
}
})

0 comments on commit e79f4bf

Please sign in to comment.