Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion lib/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};

Expand Down
2 changes: 1 addition & 1 deletion test/app.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
16 changes: 15 additions & 1 deletion test/model.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In 2.x, the method disableRemoteMethod is not deprecated. Can we place keep this test unmodified to cover this API?


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');
});
Expand Down