From f7dbc97763f7cadec8a2426844bc1a3a65ca106e Mon Sep 17 00:00:00 2001 From: Richard Pringle Date: Mon, 19 Sep 2016 12:52:34 -0400 Subject: [PATCH] Call new disable remote method from model class. --- lib/model.js | 15 ++++++++++++++- test/app.test.js | 2 +- test/model.test.js | 16 +++++++++++++++- 3 files changed, 30 insertions(+), 3 deletions(-) diff --git a/lib/model.js b/lib/model.js index 61fe5c3f..f3fd0bb7 100644 --- a/lib/model.js +++ b/lib/model.js @@ -441,7 +441,20 @@ module.exports = function(registry) { */ Model.disableRemoteMethod = function(name, isStatic) { - this.sharedClass.disableMethod(name, isStatic || false); + var key = this.sharedClass.getKeyFromMethodNameAndTarget(name, isStatic); + this.sharedClass.disableMethodByName(key); + this.emit('remoteMethodDisabled', this.sharedClass, key); + }; + + /** + * Disable remote invocation for the method with the given name. + * + * @param {String} name The name of the method (include "prototype." if the method is defined on the prototype). + * + */ + + Model.disableRemoteMethodByName = function(name) { + this.sharedClass.disableMethodByName(name); this.emit('remoteMethodDisabled', this.sharedClass, name); }; diff --git a/test/app.test.js b/test/app.test.js index ab1a0923..e2d47212 100644 --- a/test/app.test.js +++ b/test/app.test.js @@ -677,7 +677,7 @@ describe('app', function() { disabledRemoteMethod = methodName; }); app.model(Color); - app.models.Color.disableRemoteMethod('findOne'); + app.models.Color.disableRemoteMethodByName('findOne'); expect(remoteMethodDisabledClass).to.exist; expect(remoteMethodDisabledClass).to.eql(Color.sharedClass); expect(disabledRemoteMethod).to.exist; diff --git a/test/model.test.js b/test/model.test.js index dadfb728..f7c8d079 100644 --- a/test/model.test.js +++ b/test/model.test.js @@ -707,7 +707,21 @@ describe.onServer('Remote Methods', function() { var callbackSpy = require('sinon').spy(); var TestModel = app.models.TestModelForDisablingRemoteMethod; TestModel.on('remoteMethodDisabled', callbackSpy); - TestModel.disableRemoteMethod('findOne'); + TestModel.disableRemoteMethod('findOne', true); + + expect(callbackSpy).to.have.been.calledWith(TestModel.sharedClass, 'findOne'); + }); + + it('emits a `remoteMethodDisabled` event from disableRemoteMethodByName', function() { + var app = loopback(); + var model = PersistedModel.extend('TestModelForDisablingRemoteMethod'); + app.dataSource('db', { connector: 'memory' }); + app.model(model, { dataSource: 'db' }); + + var callbackSpy = require('sinon').spy(); + var TestModel = app.models.TestModelForDisablingRemoteMethod; + TestModel.on('remoteMethodDisabled', callbackSpy); + TestModel.disableRemoteMethodByName('findOne'); expect(callbackSpy).to.have.been.calledWith(TestModel.sharedClass, 'findOne'); });