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.
This commit is contained in:
Miroslav Bajtoš 2015-06-01 12:07:15 +02:00
parent 553a3b2083
commit 0ccc1e2b73
2 changed files with 21 additions and 0 deletions

View File

@ -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;
}

View File

@ -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({