diff --git a/lib/model.js b/lib/model.js index 035ba6d2..53e90794 100644 --- a/lib/model.js +++ b/lib/model.js @@ -197,7 +197,7 @@ module.exports = function(registry) { this._runWhenAttachedToApp(function(app) { var remotes = app.remotes(); remotes.before(className + '.' + name, function(ctx, next) { - fn(ctx, ctx.result, next); + return fn(ctx, ctx.result, next); }); }); }; @@ -208,7 +208,7 @@ module.exports = function(registry) { this._runWhenAttachedToApp(function(app) { var remotes = app.remotes(); remotes.after(className + '.' + name, function(ctx, next) { - fn(ctx, ctx.result, next); + return fn(ctx, ctx.result, next); }); }); }; diff --git a/test/model.test.js b/test/model.test.js index f429a1d8..f4975f6f 100644 --- a/test/model.test.js +++ b/test/model.test.js @@ -301,6 +301,32 @@ describe.onServer('Remote Methods', function() { done(); }); }); + + it('Does not stop the hook chain after returning a promise', function(done) { + var hooksCalled = []; + + User.beforeRemote('create', function() { + hooksCalled.push('first'); + return Promise.resolve(); + }); + + User.beforeRemote('create', function(ctx, user, next) { + hooksCalled.push('second'); + next(); + }); + + // invoke save + request(app) + .post('/users') + .send({ data: { first: 'foo', last: 'bar' }}) + .expect('Content-Type', /json/) + .expect(200) + .end(function(err, res) { + if (err) return done(err); + expect(hooksCalled).to.eql(['first', 'second']); + done(); + }); + }); }); describe('Model.afterRemote(name, fn)', function() {