Merge pull request #1310 from strongloop/fix/regression-in-loopback-props

Add back loopback properties like modelBuilder
This commit is contained in:
Miroslav Bajtoš 2015-04-17 18:34:55 +02:00
commit 7e99912669
2 changed files with 102 additions and 13 deletions

View File

@ -49,19 +49,21 @@ loopback.version = require('../package.json').version;
loopback.mime = express.mime;
Object.defineProperty(loopback, 'registry', {
get: getGlobalRegistry
});
Object.defineProperty(loopback, 'Model', {
get: function() {
return this.registry.getModel('Model');
}
});
Object.defineProperty(loopback, 'PersistedModel', {
get: function() {
return this.registry.getModel('PersistedModel');
Object.defineProperties(loopback, {
registry: {
get: getGlobalRegistry
},
Model: {
get: function() { return this.registry.getModel('Model'); }
},
PersistedModel: {
get: function() { return this.registry.getModel('PersistedModel'); }
},
defaultDataSources: {
get: function() { return this.registry.defaultDataSources; }
},
modelBuilder: {
get: function() { return this.registry.modelBuilder; }
}
});
@ -399,6 +401,7 @@ loopback.autoAttachModel = function(ModelCtor) {
};
// temporary alias to simplify migration of code based on <=2.0.0-beta3
// TODO(bajtos) Remove this in v3.0
Object.defineProperty(loopback, 'DataModel', {
get: function() {
return this.registry.DataModel;

View File

@ -27,6 +27,92 @@ describe('loopback', function() {
it.onServer('has `getCurrentContext` method', function() {
expect(loopback.getCurrentContext).to.be.a('function');
});
it.onServer('exports all expected properties', function() {
var EXPECTED = [
'ACL',
'AccessToken',
'Application',
'Change',
'Checkpoint',
'Connector',
'DataModel',
'DataSource',
'Email',
'GeoPoint',
'Mail',
'Memory',
'Model',
'PersistedModel',
'Remote',
'Role',
'RoleMapping',
'Route',
'Router',
'Scope',
'User',
'ValidationError',
'application',
'arguments',
'autoAttach',
'autoAttachModel',
'bodyParser',
'caller',
'compress',
'configureModel',
'context',
'cookieParser',
'cookieSession',
'createContext',
'createDataSource',
'createModel',
'csrf',
'defaultDataSources',
'directory',
'errorHandler',
'favicon',
'faviconFile',
'findModel',
'getCurrentContext',
'getDefaultDataSourceForType',
'getModel',
'getModelByType',
'isBrowser',
'isServer',
'json',
'length',
'logger',
'memory',
'methodOverride',
'mime',
'modelBuilder',
'name',
'prototype',
'query',
'registry',
'remoteMethod',
'request',
'response',
'responseTime',
'rest',
'runInContext',
'session',
'setDefaultDataSourceForType',
'static',
'status',
'template',
'timeout',
'token',
'urlNotFound',
'urlencoded',
'version',
'vhost'
];
var actual = Object.getOwnPropertyNames(loopback);
actual.sort();
expect(actual).to.eql(EXPECTED);
});
});
describe('loopback.createDataSource(options)', function() {