Merge pull request #2271 from strongloop/backport-emit-disable-remote-method-event
BACKPORT Add new feature to emit a `remoteMethodDisabled` event when disabling
This commit is contained in:
commit
091c71df23
|
@ -153,6 +153,11 @@ app.model = function(Model, config) {
|
||||||
this.emit('modelRemoted', Model.sharedClass);
|
this.emit('modelRemoted', Model.sharedClass);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var self = this;
|
||||||
|
Model.on('remoteMethodDisabled', function(model, methodName) {
|
||||||
|
self.emit('remoteMethodDisabled', model, methodName);
|
||||||
|
});
|
||||||
|
|
||||||
Model.shared = isPublic;
|
Model.shared = isPublic;
|
||||||
Model.app = this;
|
Model.app = this;
|
||||||
Model.emit('attached', this);
|
Model.emit('attached', this);
|
||||||
|
|
|
@ -431,6 +431,7 @@ module.exports = function(registry) {
|
||||||
|
|
||||||
Model.disableRemoteMethod = function(name, isStatic) {
|
Model.disableRemoteMethod = function(name, isStatic) {
|
||||||
this.sharedClass.disableMethod(name, isStatic || false);
|
this.sharedClass.disableMethod(name, isStatic || false);
|
||||||
|
this.emit('remoteMethodDisabled', this.sharedClass, name);
|
||||||
};
|
};
|
||||||
|
|
||||||
Model.belongsToRemoting = function(relationName, relation, define) {
|
Model.belongsToRemoting = function(relationName, relation, define) {
|
||||||
|
|
|
@ -85,6 +85,7 @@
|
||||||
"loopback-testing": "~1.1.0",
|
"loopback-testing": "~1.1.0",
|
||||||
"mocha": "^2.1.0",
|
"mocha": "^2.1.0",
|
||||||
"sinon": "^1.13.0",
|
"sinon": "^1.13.0",
|
||||||
|
"sinon-chai": "^2.8.0",
|
||||||
"strong-task-emitter": "^0.0.6",
|
"strong-task-emitter": "^0.0.6",
|
||||||
"supertest": "^0.15.0"
|
"supertest": "^0.15.0"
|
||||||
},
|
},
|
||||||
|
|
|
@ -606,6 +606,22 @@ describe('app', function() {
|
||||||
expect(remotedClass).to.eql(Color.sharedClass);
|
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) {
|
it.onServer('updates REST API when a new model is added', function(done) {
|
||||||
app.use(loopback.rest());
|
app.use(loopback.rest());
|
||||||
request(app).get('/colors').expect(404, function(err, res) {
|
request(app).get('/colors').expect(404, function(err, res) {
|
||||||
|
|
|
@ -1,9 +1,13 @@
|
||||||
var async = require('async');
|
var async = require('async');
|
||||||
|
var chai = require('chai');
|
||||||
|
var expect = chai.expect;
|
||||||
var loopback = require('../');
|
var loopback = require('../');
|
||||||
var ACL = loopback.ACL;
|
var ACL = loopback.ACL;
|
||||||
var Change = loopback.Change;
|
var Change = loopback.Change;
|
||||||
var defineModelTestsWithDataSource = require('./util/model-tests');
|
var defineModelTestsWithDataSource = require('./util/model-tests');
|
||||||
var PersistedModel = loopback.PersistedModel;
|
var PersistedModel = loopback.PersistedModel;
|
||||||
|
var sinonChai = require('sinon-chai');
|
||||||
|
chai.use(sinonChai);
|
||||||
|
|
||||||
var describe = require('./util/describe');
|
var describe = require('./util/describe');
|
||||||
|
|
||||||
|
@ -618,6 +622,20 @@ describe.onServer('Remote Methods', function() {
|
||||||
'createChangeStream'
|
'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() {
|
describe('Model.getApp(cb)', function() {
|
||||||
|
|
Loading…
Reference in New Issue