The simplest possible solution for clearing the handler cache when registering a model.
This commit is contained in:
parent
e56574fd13
commit
b466bb96c8
|
@ -102,6 +102,7 @@ app.model = function (Model, config) {
|
||||||
var remotingClassName = compat.getClassNameForRemoting(Model);
|
var remotingClassName = compat.getClassNameForRemoting(Model);
|
||||||
this.remotes().exports[remotingClassName] = Model;
|
this.remotes().exports[remotingClassName] = Model;
|
||||||
this.models().push(Model);
|
this.models().push(Model);
|
||||||
|
clearHandlerCache(this);
|
||||||
Model.shared = true;
|
Model.shared = true;
|
||||||
Model.app = this;
|
Model.app = this;
|
||||||
Model.emit('attached', this);
|
Model.emit('attached', this);
|
||||||
|
@ -639,6 +640,10 @@ function tryReadConfig(cwd, fileName) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function clearHandlerCache(app) {
|
||||||
|
app._handlers = undefined;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Install all express middleware required by LoopBack.
|
* Install all express middleware required by LoopBack.
|
||||||
*
|
*
|
||||||
|
|
|
@ -29,6 +29,14 @@ describe('app', function() {
|
||||||
expect(app.remotes().exports).to.eql({ color: Color });
|
expect(app.remotes().exports).to.eql({ color: Color });
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('clears handler cache', function() {
|
||||||
|
var originalRestHandler = app.handler('rest');
|
||||||
|
var Color = db.createModel('color', {name: String});
|
||||||
|
app.model(Color);
|
||||||
|
var newRestHandler = app.handler('rest');
|
||||||
|
expect(originalRestHandler).to.not.equal(newRestHandler);
|
||||||
|
});
|
||||||
|
|
||||||
describe('in compat mode', function() {
|
describe('in compat mode', function() {
|
||||||
before(function() {
|
before(function() {
|
||||||
loopback.compat.usePluralNamesForRemoting = true;
|
loopback.compat.usePluralNamesForRemoting = true;
|
||||||
|
@ -89,7 +97,7 @@ describe('app', function() {
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
app.boot({
|
app.boot({
|
||||||
app: {
|
app: {
|
||||||
port: 3000,
|
port: 3000,
|
||||||
host: '127.0.0.1',
|
host: '127.0.0.1',
|
||||||
restApiRoot: '/rest-api',
|
restApiRoot: '/rest-api',
|
||||||
foo: {bar: 'bat'},
|
foo: {bar: 'bat'},
|
||||||
|
@ -106,7 +114,7 @@ describe('app', function() {
|
||||||
dataSources: {
|
dataSources: {
|
||||||
'the-db': {
|
'the-db': {
|
||||||
connector: 'memory'
|
connector: 'memory'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -153,14 +161,14 @@ describe('app', function() {
|
||||||
var app = loopback();
|
var app = loopback();
|
||||||
app.boot({
|
app.boot({
|
||||||
app: {
|
app: {
|
||||||
port: undefined,
|
port: undefined,
|
||||||
host: undefined
|
host: undefined
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return app;
|
return app;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should be honored', function() {
|
it('should be honored', function() {
|
||||||
var assertHonored = function (portKey, hostKey) {
|
var assertHonored = function (portKey, hostKey) {
|
||||||
process.env[hostKey] = randomPort();
|
process.env[hostKey] = randomPort();
|
||||||
|
|
Loading…
Reference in New Issue