Merge pull request #389 from strongloop/feature/drop-compat

Remove `loopback.compat.usePluralNamesForRemoting`
This commit is contained in:
Miroslav Bajtoš 2014-07-21 17:11:47 +02:00
commit 57e58ab75d
7 changed files with 3 additions and 120 deletions

View File

@ -4,7 +4,6 @@
var DataSource = require('loopback-datasource-juggler').DataSource
, registry = require('./registry')
, compat = require('./compat')
, assert = require('assert')
, fs = require('fs')
, extend = require('util')._extend

View File

@ -1,56 +0,0 @@
var assert = require('assert');
/**
* Compatibility layer allowing applications based on an older LoopBack version
* to work with newer versions with minimum changes involved.
*
* You should not use it unless migrating from an older version of LoopBack.
*/
var compat = exports;
/**
* LoopBack versions pre-1.6 use plural model names when registering shared
* classes with strong-remoting. As the result, strong-remoting use method names
* like `Users.create` for the javascript methods like `User.create`.
* This has been fixed in v1.6, LoopBack consistently uses the singular
* form now.
*
* Turn this option on to enable the old behaviour.
*
* - `app.remotes()` and `app.remoteObjects()` will be indexed using
* plural names (Users instead of User).
*
* - Remote hooks must use plural names for the class name, i.e
* `Users.create` instead of `User.create`. This is transparently
* handled by `Model.beforeRemote()` and `Model.afterRemote()`.
*
* @type {boolean}
* @deprecated Your application should not depend on the way how loopback models
* and strong-remoting are wired together. It if does, you should update
* it to use singular model names.
*/
compat.usePluralNamesForRemoting = false;
/**
* Get the class name to use with strong-remoting.
* @param {function} Ctor Model class (constructor), e.g. `User`
* @return {string} Singular or plural name, depending on the value
* of `compat.usePluralNamesForRemoting`
* @internal
*/
compat.getClassNameForRemoting = function(Ctor) {
assert(
typeof(Ctor) === 'function',
'compat.getClassNameForRemoting expects a constructor as the argument');
if (compat.usePluralNamesForRemoting) {
assert(Ctor.pluralModelName,
'Model must have a "pluralModelName" property in compat mode');
return Ctor.pluralModelName;
}
return Ctor.modelName;
};

View File

@ -4,7 +4,6 @@
var assert = require('assert');
var remoting = require('strong-remoting');
var compat = require('../compat');
var DataAccessObject = require('loopback-datasource-juggler/lib/dao');
/**

View File

@ -38,11 +38,6 @@ loopback.version = require('../package.json').version;
loopback.mime = express.mime;
/*!
* Compatibility layer, intentionally left undocumented.
*/
loopback.compat = require('./compat');
/*!
* Create an loopback application.
*

View File

@ -2,7 +2,6 @@
* Module Dependencies.
*/
var registry = require('../registry');
var compat = require('../compat');
var assert = require('assert');
var SharedClass = require('strong-remoting').SharedClass;
@ -87,7 +86,7 @@ Model.setup = function () {
// create a sharedClass
var sharedClass = ModelCtor.sharedClass = new SharedClass(
compat.getClassNameForRemoting(ModelCtor),
ModelCtor.modelName,
ModelCtor,
options.remoting
);
@ -152,7 +151,7 @@ Model.setup = function () {
var self = this;
if(this.app) {
var remotes = this.app.remotes();
var className = compat.getClassNameForRemoting(self);
var className = self.modelName;
remotes.before(className + '.' + name, function (ctx, next) {
fn(ctx, ctx.result, next);
});
@ -169,7 +168,7 @@ Model.setup = function () {
var self = this;
if(this.app) {
var remotes = this.app.remotes();
var className = compat.getClassNameForRemoting(self);
var className = self.modelName;
remotes.after(className + '.' + name, function (ctx, next) {
fn(ctx, ctx.result, next);
});

View File

@ -57,28 +57,6 @@ describe('app', function() {
request(app).get('/colors').expect(200, done);
});
});
describe('in compat mode', function() {
before(function() {
loopback.compat.usePluralNamesForRemoting = true;
});
after(function() {
loopback.compat.usePluralNamesForRemoting = false;
});
it('uses plural name as shared class name', function() {
var Color = db.createModel('color', {name: String});
app.model(Color);
var classes = app.remotes().classes().map(function(c) {return c.name});
expect(classes).to.contain('colors');
});
it('uses plural name as app.remoteObjects() key', function() {
var Color = db.createModel('color', {name: String});
app.model(Color);
expect(app.remoteObjects()).to.eql({ colors: Color });
});
});
});
describe('app.model(name, config)', function () {

View File

@ -270,37 +270,6 @@ describe.onServer('Remote Methods', function(){
});
})
describe('in compat mode', function() {
before(function() {
loopback.compat.usePluralNamesForRemoting = true;
});
after(function() {
loopback.compat.usePluralNamesForRemoting = false;
});
it('correctly install before/after hooks', function(done) {
var hooksCalled = [];
User.beforeRemote('**', function(ctx, user, next) {
hooksCalled.push('beforeRemote');
next();
});
User.afterRemote('**', function(ctx, user, next) {
hooksCalled.push('afterRemote');
next();
});
request(app).get('/users')
.expect(200, function(err, res) {
if (err) return done(err);
expect(hooksCalled, 'hooks called')
.to.eql(['beforeRemote', 'afterRemote']);
done();
});
});
});
describe('Model.hasMany(Model)', function() {
it("Define a one to many relationship", function(done) {
var Book = dataSource.createModel('book', {title: String, author: String});