diff --git a/lib/loopback.js b/lib/loopback.js index fd96b8ea..568441d7 100644 --- a/lib/loopback.js +++ b/lib/loopback.js @@ -57,6 +57,11 @@ function createApplication() { utils.merge(app, proto); + // Create a new instance of models registry per each app instance + app.models = function() { + return proto.models.apply(this, arguments); + }; + return app; } diff --git a/test/app.test.js b/test/app.test.js index a806f251..eed3d7aa 100644 --- a/test/app.test.js +++ b/test/app.test.js @@ -76,10 +76,17 @@ describe('app', function() { }); }); + describe('app.models', function() { + it('is unique per app instance', function() { + var Color = app.model('Color', { dataSource: 'db' }); + expect(app.models.Color).to.equal(Color); + var anotherApp = loopback(); + expect(anotherApp.models.Color).to.equal(undefined); + }); + }); + describe('app.boot([options])', function () { beforeEach(function () { - var app = this.app = loopback(); - app.boot({ app: { port: 3000, diff --git a/test/support.js b/test/support.js index 394bc6d4..85aac797 100644 --- a/test/support.js +++ b/test/support.js @@ -17,7 +17,7 @@ request = require('supertest'); loopback.User.settings.saltWorkFactor = 4; beforeEach(function () { - app = loopback(); + this.app = app = loopback(); // setup default data sources loopback.setDefaultDataSourceForType('db', {