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);
}

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 @@ -433,6 +433,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 @@ -84,6 +84,7 @@
"loopback-boot": "^2.7.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 @@ -599,6 +599,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
5 changes: 4 additions & 1 deletion test/helpers/loopback-testing-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ module.exports = helpers;

var assert = require('assert');
var request = require('supertest');
var expect = require('chai').expect;
var chai = require('chai');
var expect = chai.expect;
var sinon = require('sinon');
chai.use(require('sinon-chai'));

_beforeEach.withApp = function(app) {
if (app.models.User) {
Expand Down
14 changes: 14 additions & 0 deletions test/model.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -613,6 +613,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