Merge pull request #193 from globocom/clear-handler-cache2

Clear handler cache
This commit is contained in:
Ritchie Martori 2014-02-18 14:24:23 -08:00
commit edd16b9ce8
2 changed files with 17 additions and 4 deletions

View File

@ -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.
* *

View File

@ -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;