Skip to content

Commit

Permalink
Improved tests, readme and code
Browse files Browse the repository at this point in the history
  • Loading branch information
Jokero committed Dec 12, 2015
1 parent b4131d0 commit 23ef5c2
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 22 deletions.
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ var Model = mongoose.model('Model', schema); // Model.paginate()

### Model.paginate([query], [options], [callback])

Returns promise

**Parameters**

* `[query]` {Object} - Query criteria. [Documentation](https://docs.mongodb.org/manual/tutorial/query-documents)
Expand Down
16 changes: 8 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,20 +46,20 @@ function paginate(query, options, callback) {
};

if (limit) {
var query = this.find(query)
.select(select)
.sort(sort)
.skip(skip)
.limit(limit)
.lean(lean);
var docsQuery = this.find(query)
.select(select)
.sort(sort)
.skip(skip)
.limit(limit)
.lean(lean);

if (populate) {
[].concat(populate).forEach(function(item) {
query.populate(item);
docsQuery.populate(item);
});
}

promises.docs = query.exec();
promises.docs = docsQuery.exec();

if (lean && leanWithId) {
promises.docs = promises.docs.then(function(docs) {
Expand Down
7 changes: 3 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,9 @@
},

"devDependencies": {
"mongoose": "4.2.8",
"mocha": "2.3.4",
"chai": "3.4.1",
"chai-as-promised": "5.1.0"
"mongoose": "4.2.8",
"mocha": "2.3.4",
"chai": "3.4.1"
},

"scripts": {
Expand Down
14 changes: 6 additions & 8 deletions tests/index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
var mongoosePaginate = require('../index');
var mongoose = require('mongoose');
var expect = require('chai').expect;

var chai = require('chai');
var chaiAsPromised = require('chai-as-promised');
var expect = require('chai').expect;

chai.use(chaiAsPromised);

const MONGO_URI = 'mongodb://127.0.0.1/mongoose_paginate_test';

Expand Down Expand Up @@ -54,6 +50,10 @@ describe('mongoose-paginate', function() {
});
});

afterEach(function() {
delete mongoosePaginate.paginate.options;
});

it('returns promise', function() {
var promise = Book.paginate();
expect(promise.then).to.be.an.instanceof(Function);
Expand Down Expand Up @@ -98,9 +98,7 @@ describe('mongoose-paginate', function() {
expect(result.docs).to.have.length(20);
expect(result.limit).to.equal(20);
expect(result.docs[0]).to.not.be.an.instanceof(mongoose.Document);

delete mongoosePaginate.paginate.options;
})
});
});

it('with offset and limit', function() {
Expand Down

0 comments on commit 23ef5c2

Please sign in to comment.