Permalink
Browse files

Make post('remove') middleware provide the model that was removed.

  • Loading branch information...
1 parent 09a6c6d commit 107194f1cd0ac6082b0b0288dc14cd0be12f0207 @timoxley timoxley committed with aheckmann Feb 10, 2012
Showing with 8 additions and 6 deletions.
  1. +1 −1 lib/model.js
  2. +7 −5 test/model.test.js
View
@@ -476,7 +476,7 @@ Model.prototype.remove = function remove (fn) {
return promise.error(err);
}
promise.complete();
- self.emit('remove');
+ self.emit('remove', self);
}));
return this;
View
@@ -3287,17 +3287,20 @@ module.exports = {
})
, save = false
, remove = false
- , init = false;
+ , init = false
+ , post = undefined;
- schema.post('save', function () {
+ schema.post('save', function (arg) {
+ arg._id.should.equal(post._id)
save = true;
});
schema.post('init', function () {
init = true;
});
- schema.post('remove', function () {
+ schema.post('remove', function (arg) {
+ arg._id.should.eql(post._id)
remove = true;
});
@@ -3306,13 +3309,12 @@ module.exports = {
var db = start()
, BlogPost = db.model('PostHookTest');
- var post = new BlogPost();
+ post = new BlogPost();
post.save(function (err) {
process.nextTick(function () {
should.strictEqual(err, null);
save.should.be.true;
-
BlogPost.findById(post._id, function (err, doc) {
process.nextTick(function () {
should.strictEqual(err, null);

0 comments on commit 107194f

Please sign in to comment.