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
5 changes: 5 additions & 0 deletions lib/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,11 @@ app.model = function(Model, config) {
this.emit('modelRemoted', Model.sharedClass);
}

var self = this;
Model.on('remoteMethodDisabled', function(model, methodName) {
self.emit('remoteMethodDisabled', model, methodName);
});

Model.shared = isPublic;
Model.app = this;
Model.emit('attached', this);
Expand Down
1 change: 1 addition & 0 deletions lib/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,7 @@ module.exports = function(registry) {

Model.disableRemoteMethod = function(name, isStatic) {
this.sharedClass.disableMethod(name, isStatic || false);
this.emit('remoteMethodDisabled', this.sharedClass, name);
};

Model.belongsToRemoting = function(relationName, relation, define) {
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
"loopback-testing": "~1.1.0",
"mocha": "^2.1.0",
"sinon": "^1.13.0",
"sinon-chai": "^2.8.0",
"strong-task-emitter": "^0.0.6",
"supertest": "^0.15.0"
},
Expand Down
16 changes: 16 additions & 0 deletions test/app.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -606,6 +606,22 @@ describe('app', function() {
expect(remotedClass).to.eql(Color.sharedClass);
});

it('emits a `remoteMethodDisabled` event', function() {
var Color = PersistedModel.extend('color', { name: String });
Color.shared = true;
var remoteMethodDisabledClass, disabledRemoteMethod;
app.on('remoteMethodDisabled', function(sharedClass, methodName) {
remoteMethodDisabledClass = sharedClass;
disabledRemoteMethod = methodName;
});
app.model(Color);
app.models.Color.disableRemoteMethod('findOne');
expect(remoteMethodDisabledClass).to.exist;
expect(remoteMethodDisabledClass).to.eql(Color.sharedClass);
expect(disabledRemoteMethod).to.exist;
expect(disabledRemoteMethod).to.eql('findOne');
});

it.onServer('updates REST API when a new model is added', function(done) {
app.use(loopback.rest());
request(app).get('/colors').expect(404, function(err, res) {
Expand Down
18 changes: 18 additions & 0 deletions test/model.test.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
var async = require('async');
var chai = require('chai');
var expect = chai.expect;
var loopback = require('../');
var ACL = loopback.ACL;
var Change = loopback.Change;
var defineModelTestsWithDataSource = require('./util/model-tests');
var PersistedModel = loopback.PersistedModel;
var sinonChai = require('sinon-chai');
chai.use(sinonChai);

var describe = require('./util/describe');

Expand Down Expand Up @@ -618,6 +622,20 @@ describe.onServer('Remote Methods', function() {
'createChangeStream'
]);
});

it('emits a `remoteMethodDisabled` event', 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.disableRemoteMethod('findOne');

expect(callbackSpy).to.have.been.calledWith(TestModel.sharedClass, 'findOne');
});
});

describe('Model.getApp(cb)', function() {
Expand Down