From 4a076f13fd7e9ef6ba399a02bf52733a4084a2f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20Bajto=C5=A1?= Date: Tue, 4 Feb 2014 20:27:14 +0100 Subject: [PATCH 1/2] Fix incorrect usage of `app` in app.test.js The `beforeEach` hook was using a local `var app`, the test was accessing global `app` created by `test/support.js`. --- test/app.test.js | 2 -- test/support.js | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/test/app.test.js b/test/app.test.js index a806f251..d9e6cdc5 100644 --- a/test/app.test.js +++ b/test/app.test.js @@ -78,8 +78,6 @@ describe('app', function() { 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', { 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 2/2] 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({