From 4d0a824757ff6df81d80c8143d5434847d1456ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20Bajto=C5=A1?= Date: Fri, 17 Apr 2015 18:02:04 +0200 Subject: [PATCH] Add back loopback properties like modelBuilder The commit b917075 accidentally removed a couple of properties, this commit is bringing them back: - loopback.modelRegistry - loopback.defaultDataSources A unit-test was added to prevent this kind of regressions in the future. --- lib/loopback.js | 29 ++++++++------- test/loopback.test.js | 86 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 102 insertions(+), 13 deletions(-) diff --git a/lib/loopback.js b/lib/loopback.js index 07a2d73e..f6fafddb 100644 --- a/lib/loopback.js +++ b/lib/loopback.js @@ -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; diff --git a/test/loopback.test.js b/test/loopback.test.js index c8e9853f..c406fa3e 100644 --- a/test/loopback.test.js +++ b/test/loopback.test.js @@ -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() {