From 0ccc1e2b73452da501f6f2815820f21429fce476 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20Bajto=C5=A1?= Date: Mon, 1 Jun 2015 12:07:15 +0200 Subject: [PATCH] Add loadBuiltinModels flag to loopback(options) When creating an application with a local registry, the default behaviour is to define only two core models Model & PersistedModel. The new flag `loadBuiltinModels` modifies this behaviour and instructs loopback to define all builtin models in the local registry too. --- lib/loopback.js | 3 +++ test/loopback.test.js | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/lib/loopback.js b/lib/loopback.js index e1b162dc..70529fff 100644 --- a/lib/loopback.js +++ b/lib/loopback.js @@ -99,6 +99,9 @@ function createApplication(options) { if (loopback.localRegistry || options && options.localRegistry === true) { // setup the app registry var registry = app.registry = new Registry(); + if (options && options.loadBuiltinModels === true) { + require('./builtin-models')(registry); + } } else { app.registry = loopback.registry; } diff --git a/test/loopback.test.js b/test/loopback.test.js index 9b39709e..ce45aa14 100644 --- a/test/loopback.test.js +++ b/test/loopback.test.js @@ -115,6 +115,24 @@ describe('loopback', function() { }); }); + describe('loopback(options)', function() { + it('supports localRegistry:true', function() { + var app = loopback({ localRegistry: true }); + expect(app.registry).to.not.equal(loopback.registry); + }); + + it('does not load builtin models into the local registry', function() { + var app = loopback({ localRegistry: true }); + expect(app.registry.findModel('User')).to.equal(undefined); + }); + + it('supports loadBuiltinModels:true', function() { + var app = loopback({ localRegistry: true, loadBuiltinModels: true }); + expect(app.registry.findModel('User')) + .to.have.property('modelName', 'User'); + }); + }); + describe('loopback.createDataSource(options)', function() { it('Create a data source with a connector.', function() { var dataSource = loopback.createDataSource({