From b13ff35697ff798f26467a98ddd19cf4a206d15f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20Bajto=C5=A1?= Date: Tue, 4 Feb 2014 20:28:19 +0100 Subject: [PATCH] Make app.models unique per app instance Remove a source of confusion in unit-tests. --- lib/loopback.js | 5 +++++ test/app.test.js | 9 +++++++++ 2 files changed, 14 insertions(+) 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 d9e6cdc5..eed3d7aa 100644 --- a/test/app.test.js +++ b/test/app.test.js @@ -76,6 +76,15 @@ 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 () { app.boot({