Skip to content

Commit

Permalink
Resolving conflict with package manifest.
Browse files Browse the repository at this point in the history
  • Loading branch information
JasonGhent committed May 16, 2014
2 parents 2460993 + a3e1fb3 commit f92f229
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 8 deletions.
9 changes: 8 additions & 1 deletion lib/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,14 @@ Schema.prototype.pre = function(){
*/

Schema.prototype.post = function(method, fn){
return this.queue('on', arguments);
// assuming that all callbacks with arity < 2 are synchronous post hooks
if (fn.length < 2)
return this.queue('on', arguments);
return this.queue('post', [arguments[0], function(next){
// wrap original function so that the callback goes last,
// for compatibility with old code that is using synchronous post hooks
fn.call(this, this, next);
}]);
};

/**
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
, "author": "Guillermo Rauch <[email protected]>"
, "keywords": ["mongodb", "document", "model", "schema", "database", "odm", "data", "datastore", "query", "nosql", "orm", "db"]
, "dependencies": {
"hooks": "0.2.1"
"hooks": "0.3.2"
, "mongodb": "1.4.3"
, "ms": "0.1.0"
, "sliced": "0.0.5"
Expand Down
18 changes: 12 additions & 6 deletions test/model.middleware.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,13 @@ describe('model middleware', function(){
called++;
});

schema.post('save', function (obj) {
assert.equal(obj.title,'Little Green Running Hood');
assert.equal(2, called);
db.close();
done();
schema.post('save', function(obj, next){
setTimeout(function(){
assert.equal(obj.title,'Little Green Running Hood');
assert.equal(2, called);
called++;
next();
}, 0);
});

var db = start()
Expand All @@ -52,8 +54,12 @@ describe('model middleware', function(){

test.save(function(err){
assert.ifError(err);
assert.equal(test.title,'Little Green Running Hood');
assert.equal(3, called);
db.close();
done();
});
})
});

it('works', function(done){
var schema = new Schema({
Expand Down

0 comments on commit f92f229

Please sign in to comment.