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:
parent
553a3b2083
commit
0ccc1e2b73
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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({
|
||||
|
|
Loading…
Reference in New Issue