From 7cfe45016131627fb7507618113ddebe3002e516 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20Bajto=C5=A1?= Date: Tue, 27 May 2014 14:33:42 +0200 Subject: [PATCH] Make app.datasources unique per app instance This removes a source of confusion in unit-tests. --- lib/loopback.js | 3 +++ test/app.test.js | 10 ++++++++++ 2 files changed, 13 insertions(+) diff --git a/lib/loopback.js b/lib/loopback.js index 95d297ba..81a5c20b 100644 --- a/lib/loopback.js +++ b/lib/loopback.js @@ -76,6 +76,9 @@ function createApplication() { return proto.models.apply(this, arguments); }; + // Create a new instance of datasources registry per each app instance + app.datasources = app.dataSources = {}; + return app; } diff --git a/test/app.test.js b/test/app.test.js index 2dcdb918..09a66c5c 100644 --- a/test/app.test.js +++ b/test/app.test.js @@ -111,6 +111,7 @@ describe('app', function() { describe('app.models', function() { it('is unique per app instance', function() { + app.dataSource('db', { connector: 'memory' }); var Color = app.model('Color', { dataSource: 'db' }); expect(app.models.Color).to.equal(Color); var anotherApp = loopback(); @@ -118,6 +119,15 @@ describe('app', function() { }); }); + describe('app.dataSources', function() { + it('is unique per app instance', function() { + app.dataSource('ds', { connector: 'memory' }); + expect(app.datasources.ds).to.not.equal(undefined); + var anotherApp = loopback(); + expect(anotherApp.datasources.ds).to.equal(undefined); + }); + }); + describe('app.boot([options])', function () { beforeEach(function () { app.boot({