Backport ESLint from master

This commit is contained in:
Simon Ho 2016-05-10 14:25:33 -07:00 committed by Miroslav Bajtoš
parent ee6c0ad461
commit 65d6d6a508
48 changed files with 526 additions and 531 deletions

2
.eslintignore Normal file
View File

@ -0,0 +1,2 @@
coverage
support

13
.eslintrc Normal file
View File

@ -0,0 +1,13 @@
{
"extends": "loopback",
"rules": {
"max-len": ["error", 110, 4, {
"ignoreComments": true,
"ignoreUrls": true,
"ignorePattern": "^\\s*var\\s.+=\\s*(require\\s*\\()|(/)"
}],
// NOTE(bajtos) we should eventuall remove this override
// and fix all of those 100+ violations
"one-var": "off"
}
}

View File

@ -9,7 +9,6 @@ var User, Post, Passport, City, Street, Building;
var nbSchemaRequests = 0;
setup(function() {
Passport.find({ include: 'owner' }, function(err, passports) {
console.log('passports.owner', passports);
});
@ -31,7 +30,6 @@ setup(function() {
User.find({ include: ['posts', 'passports'] }, function(err, users) {
console.log('users.passports && users.posts', users);
});
});
function setup(done) {
@ -108,7 +106,6 @@ function setup(done) {
}
);
}
});
}

View File

@ -22,7 +22,6 @@ function loadSchemasSync(schemaFile, dataSource) {
var schemas = JSON.parse(fs.readFileSync(schemaFile));
return dataSource.buildModels(schemas);
}
var models = loadSchemasSync(path.join(__dirname, 'jdb-schemas.json'));

View File

@ -29,7 +29,14 @@ var User = modelBuilder.define('User', {
friends: [String],
});
var user = new User({ name: 'Joe', age: 20, address: { street: '123 Main St', 'city': 'San Jose', state: 'CA' },
var user = new User({
name: 'Joe',
age: 20,
address: {
street: '123 Main St',
city: 'San Jose',
state: 'CA',
},
emails: [
{ label: 'work', email: 'xyz@sample.com' },
],

View File

@ -33,7 +33,6 @@ Customer.create({ name: 'John' }, function(err, customer) {
});
Order.create({ orderDate: new Date(), items: ['Phone'] }, function(err, order) {
order.customer.create({ name: 'Smith' }, function(err, customer2) {
console.log(order, customer2);
order.save(function(err, order) {
@ -90,26 +89,41 @@ Physician.create({ name: 'Dr John' }, function(err, physician1) {
Physician.create({ name: 'Dr Smith' }, function(err, physician2) {
Patient.create({ name: 'Mary' }, function(err, patient1) {
Patient.create({ name: 'Ben' }, function(err, patient2) {
Appointment.create({ appointmentDate: new Date(), physicianId: physician1.id, patientId: patient1.id },
function(err, appt1) {
Appointment.create({ appointmentDate: new Date(), physicianId: physician1.id, patientId: patient2.id },
function(err, appt2) {
physician1.patients(console.log);
physician1.patients({ where: { name: 'Mary' }}, console.log);
patient1.physicians(console.log);
Appointment.create({
appointmentDate: new Date(),
physicianId: physician1.id,
patientId: patient1.id,
}, function(err, appt1) {
Appointment.create({
appointmentDate: new Date(),
physicianId: physician1.id,
patientId: patient2.id,
}, function(err, appt2) {
physician1.patients(console.log);
physician1.patients({ where: { name: 'Mary' }}, console.log);
patient1.physicians(console.log);
// Build an appointment?
var patient3 = patient1.physicians.build({ name: 'Dr X' });
console.log('Physician 3: ', patient3, patient3.constructor.modelName);
// Build an appointment?
var patient3 = patient1.physicians.build({ name: 'Dr X' });
console.log(
'Physician 3: ',
patient3,
patient3.constructor.modelName
);
// Create a physician?
patient1.physicians.create({ name: 'Dr X' }, function(err, patient4) {
console.log('Physician 4: ', patient4, patient4.constructor.modelName);
});
});
// Create a physician?
patient1.physicians.create(
{ name: 'Dr X' },
function(err, patient4) {
console.log(
'Physician 4: ',
patient4,
patient4.constructor.modelName
);
}
);
});
});
});
});
});
@ -146,7 +160,6 @@ Assembly.create({ name: 'car' }, function(err, assembly) {
});
});
});
});
});

View File

@ -67,9 +67,9 @@ function convertSubsetOfPropertiesByType(inst, data) {
for (var key in data) {
// Convert the properties by type
typedData[key] = inst[key];
if (typeof typedData[key] === 'object'
&& typedData[key] !== null
&& typeof typedData[key].toObject === 'function') {
if (typeof typedData[key] === 'object' &&
typedData[key] !== null &&
typeof typedData[key].toObject === 'function') {
typedData[key] = typedData[key].toObject();
}
}
@ -907,7 +907,6 @@ DataAccessObject.findOrCreate = function findOrCreate(query, data, options, cb)
}
if (!err) Model.emit('changed', obj);
});
} else {
if (cb.promise) {
cb(err, [obj, created]);
@ -924,7 +923,7 @@ DataAccessObject.findOrCreate = function findOrCreate(query, data, options, cb)
where: query.where,
data: data,
isNewInstance: true,
currentInstance : currentInstance,
currentInstance: currentInstance,
hookState: hookState,
options: options,
};
@ -1748,8 +1747,7 @@ DataAccessObject.find = function find(query, options, cb) {
cb(err, results);
});
}
else {
} else {
cb(err, data || []);
}
};
@ -1834,7 +1832,9 @@ DataAccessObject.findOne = function findOne(query, options, cb) {
* @param {Object) [options] Options
* @param {Function} [cb] Callback called with (err, info)
*/
DataAccessObject.remove = DataAccessObject.deleteAll = DataAccessObject.destroyAll = function destroyAll(where, options, cb) {
DataAccessObject.remove =
DataAccessObject.deleteAll =
DataAccessObject.destroyAll = function destroyAll(where, options, cb) {
var connectionPromise = stillConnecting(this.getDataSource(), this, arguments);
if (connectionPromise) {
return connectionPromise;
@ -1927,7 +1927,6 @@ DataAccessObject.remove = DataAccessObject.deleteAll = DataAccessObject.destroyA
} else {
connector.destroyAll(Model.modelName, where, done);
}
}
function done(err, info) {
@ -1968,8 +1967,14 @@ function whereIsEmpty(where) {
// [FIXME] rfeng: This is a hack to set up 'deleteById' first so that
// 'deleteById' will be used as the name for strong-remoting to keep it backward
// compatible for angular SDK
DataAccessObject.removeById = DataAccessObject.destroyById = DataAccessObject.deleteById = function deleteById(id, options, cb) {
var connectionPromise = stillConnecting(this.getDataSource(), this, arguments);
DataAccessObject.removeById =
DataAccessObject.destroyById =
DataAccessObject.deleteById = function deleteById(id, options, cb) {
var connectionPromise = stillConnecting(
this.getDataSource(),
this,
arguments
);
if (connectionPromise) {
return connectionPromise;
}
@ -2246,7 +2251,6 @@ DataAccessObject.prototype.save = function(options, cb) {
connector.save(modelName, inst.constructor._forDB(data), saveCallback);
}
});
}, data, cb);
}, data, cb);
}
@ -2291,7 +2295,6 @@ DataAccessObject.updateAll = function(where, data, options, cb) {
data = where;
where = {};
}
} else if (cb === undefined) {
// One of:
// updateAll(where, data, options) -> Promise
@ -2714,7 +2717,7 @@ DataAccessObject.replaceById = function(id, data, options, cb) {
Model: Model,
hookState: hookState,
data: context.data,
isNewInstance:false,
isNewInstance: false,
options: options,
};
Model.notifyObserversOf('loaded', ctx, function(err) {
@ -2742,7 +2745,7 @@ DataAccessObject.replaceById = function(id, data, options, cb) {
Model: Model,
where: byIdQuery(Model, id).where,
data: context.data,
isNewInstance:false,
isNewInstance: false,
currentInstance: inst,
hookState: hookState,
options: options,
@ -2807,8 +2810,8 @@ function(data, options, cb) {
if (isPKMissing(Model, cb))
return cb.promise;
var allowExtendedOperators = connector.settings
&& connector.settings.allowExtendedOperators;
var allowExtendedOperators = connector.settings &&
connector.settings.allowExtendedOperators;
var strict = this.__strict;
var model = Model.modelName;

View File

@ -156,7 +156,6 @@ function DataSource(name, settings, modelBuilder) {
});
}
}.bind(this));
}
util.inherits(DataSource, EventEmitter);
@ -314,22 +313,22 @@ DataSource.prototype.setup = function(name, settings) {
if (connector) {
var postInit = function postInit(err, result) {
this._setupConnector();
// we have an connector now?
if (!this.connector) {
throw new Error('Connector is not defined correctly: it should create `connector` member of dataSource');
throw new Error('Connector is not defined correctly: it should ' +
'create `connector` member of dataSource');
}
this.connected = !err; // Connected now
if (this.connected) {
this.emit('connected');
} else {
// The connection fails, let's report it and hope it will be recovered in the next call
console.error('Connection fails: ', err, '\nIt will be retried for the next request.');
console.error('Connection fails: ', err, '\nIt will be retried for ' +
'the next request.');
this.emit('error', err);
this.connecting = false;
}
}.bind(this);
try {
@ -434,7 +433,6 @@ DataSource.prototype.defineRelations = function(modelClass, relations) {
modelClass[relation.type].call(modelClass, name, params);
}
});
}
if (throughModel && !isModelDataSourceAttached(throughModel)) {
// Set up a listener to the through model
@ -480,8 +478,8 @@ DataSource.prototype.defineRelations = function(modelClass, relations) {
throughModel = isModelClass(r.through) ? r.through : self.getModel(r.through, true);
}
if ((targetModel && !isModelDataSourceAttached(targetModel))
|| (throughModel && !isModelDataSourceAttached(throughModel))) {
if ((targetModel && !isModelDataSourceAttached(targetModel)) ||
(throughModel && !isModelDataSourceAttached(throughModel))) {
// Create a listener to defer the relation set up
createListener(rn, r, targetModel, throughModel);
} else {
@ -542,7 +540,6 @@ DataSource.prototype.setupDataAccess = function(modelClass, settings) {
// define scopes from LDL (options.relations)
var scopes = settings.scopes || {};
this.defineScopes(modelClass, scopes);
};
/**
@ -594,7 +591,9 @@ DataSource.prototype.setupDataAccess = function(modelClass, settings) {
*
*/
DataSource.prototype.createModel = DataSource.prototype.define = function defineClass(className, properties, settings) {
DataSource.prototype.createModel =
DataSource.prototype.define = function defineClass(className, properties,
settings) {
var args = slice.call(arguments);
if (!className) {
@ -752,7 +751,6 @@ DataSource.prototype.attach = function(modelClass) {
this.setupDataAccess(modelClass, modelClass.settings);
modelClass.emit('dataSourceAttached', modelClass);
return modelClass;
};
/**
@ -1311,7 +1309,6 @@ DataSource.prototype.discoverSchemas = function(modelName, options, cb) {
}
async.parallel(tasks, function(err, results) {
if (err) {
cb(err);
return cb.promise;
@ -1353,8 +1350,8 @@ DataSource.prototype.discoverSchemas = function(modelName, options, cb) {
var propName = nameMapper('column', item.columnName);
schema.properties[propName] = {
type: item.type,
required: (item.nullable === 'N' || item.nullable === 'NO'
|| item.nullable === 0 || item.nullable === false),
required: (item.nullable === 'N' || item.nullable === 'NO' ||
item.nullable === 0 || item.nullable === false),
length: item.dataLength,
precision: item.dataPrecision,
scale: item.dataScale,
@ -1589,7 +1586,6 @@ DataSource.prototype.discoverSchemasSync = function(modelName, options) {
self.discoverSchemasSync(otherTables[t].tableName, newOptions);
}
return options.visited;
}
};
@ -1671,7 +1667,6 @@ DataSource.prototype.discoverAndBuildModelsSync = function(modelName, options) {
* @returns {*}
*/
DataSource.prototype.buildModelFromInstance = function(name, json, options) {
// Introspect the JSON document to generate a schema
var schema = ModelBuilder.introspect(json);
@ -1859,7 +1854,6 @@ DataSource.prototype.defineForeignKey = function defineForeignKey(className, key
// Add the foreign key property to the data source _models
this.defineProperty(className, key, fkDef);
}
};
/**
@ -1905,10 +1899,13 @@ DataSource.prototype.copyModel = function copyModel(Master) {
hiddenProperty(Slave, 'relations', Master.relations);
if (!(className in dataSource.modelBuilder.models)) {
// store class in model pool
dataSource.modelBuilder.models[className] = Slave;
dataSource.modelBuilder.definitions[className] = new ModelDefinition(dataSource.modelBuilder, md.name, md.properties, md.settings);
dataSource.modelBuilder.definitions[className] = new ModelDefinition(
dataSource.modelBuilder,
md.name,
md.properties,
md.settings);
if ((!dataSource.isTransaction) && dataSource.connector && dataSource.connector.define) {
dataSource.connector.define({
@ -1917,7 +1914,6 @@ DataSource.prototype.copyModel = function copyModel(Master) {
settings: md.settings,
});
}
}
return Slave;

View File

@ -138,11 +138,17 @@ function GeoPoint(data) {
};
}
assert(Array.isArray(data) || typeof data === 'object' || typeof data === 'string', 'must provide valid geo-coordinates array [lat, lng] or object or a "lat, lng" string');
assert(
Array.isArray(data) ||
typeof data === 'object' ||
typeof data === 'string',
'must provide valid geo-coordinates array [lat, lng] or object or a ' +
'"lat, lng" string');
if (typeof data === 'string') {
data = data.split(/,\s*/);
assert(data.length === 2, 'must provide a string "lat,lng" creating a GeoPoint with a string');
assert(data.length === 2, 'must provide a string "lat,lng" creating a ' +
'GeoPoint with a string');
}
if (Array.isArray(data)) {
data = {
@ -259,7 +265,6 @@ var EARTH_RADIUS = {
};
function geoDistance(x1, y1, x2, y2, options) {
var type = (options && options.type) || 'miles';
// Convert to radians

View File

@ -36,10 +36,10 @@ Hookable.afterDestroy = null;
// TODO: Evaluate https://github.com/bnoguchi/hooks-js/
Hookable.prototype.trigger = function trigger(actionName, work, data, callback) {
var capitalizedName = capitalize(actionName);
var beforeHook = this.constructor['before' + capitalizedName]
|| this.constructor['pre' + capitalizedName];
var afterHook = this.constructor['after' + capitalizedName]
|| this.constructor['post' + capitalizedName];
var beforeHook = this.constructor['before' + capitalizedName] ||
this.constructor['pre' + capitalizedName];
var afterHook = this.constructor['after' + capitalizedName] ||
this.constructor['post' + capitalizedName];
if (actionName === 'validate') {
beforeHook = beforeHook || this.constructor.beforeValidation;
afterHook = afterHook || this.constructor.afterValidation;

View File

@ -198,16 +198,15 @@ Inclusion.include = function(objects, include, options, cb) {
subInclude = null;
}
}
}
else {
} else {
relationName = include;
subInclude = null;
}
var relation = relations[relationName];
if (!relation) {
cb(new Error('Relation "' + relationName + '" is not defined for '
+ self.modelName + ' model'));
cb(new Error('Relation "' + relationName + '" is not defined for ' +
self.modelName + ' model'));
return;
}
var polymorphic = relation.polymorphic;
@ -251,8 +250,7 @@ Inclusion.include = function(objects, include, options, cb) {
var fields = filter.fields;
if (Array.isArray(fields) && fields.indexOf(relation.keyTo) === -1) {
fields.push(relation.keyTo);
}
else if (isPlainObject(fields) && !fields[relation.keyTo]) {
} else if (isPlainObject(fields) && !fields[relation.keyTo]) {
fields[relation.keyTo] = true;
}
@ -281,8 +279,7 @@ Inclusion.include = function(objects, include, options, cb) {
}
//assuming all other relations with multiple=true as hasMany
return includeHasMany(cb);
}
else {
} else {
if (polymorphic) {
if (relation.type === 'hasOne') {
return includePolymorphicHasOne(cb);
@ -373,8 +370,7 @@ Inclusion.include = function(objects, include, options, cb) {
//make sure that the modelToIdName is included if fields are specified
if (Array.isArray(fields) && fields.indexOf(modelToIdName) === -1) {
fields.push(modelToIdName);
}
else if (isPlainObject(fields) && !fields[modelToIdName]) {
} else if (isPlainObject(fields) && !fields[modelToIdName]) {
fields[modelToIdName] = true;
}
@ -486,7 +482,6 @@ Inclusion.include = function(objects, include, options, cb) {
obj.__cachedRelations[relationName].push(target);
processTargetObj(obj, next);
}, next);
}
}
@ -848,7 +843,6 @@ Inclusion.include = function(objects, include, options, cb) {
* @returns {*}
*/
function processTargetObj(obj, callback) {
var isInst = obj instanceof self;
// Calling the relation method on the instance
@ -923,7 +917,6 @@ Inclusion.include = function(objects, include, options, cb) {
if (err) {
return callback(err);
} else {
defineCachedRelations(obj);
obj.__cachedRelations[relationName] = result;
@ -931,7 +924,6 @@ Inclusion.include = function(objects, include, options, cb) {
}
});
}
}
};

View File

@ -4,9 +4,7 @@
// License text available at https://opensource.org/licenses/MIT
module.exports = function getIntrospector(ModelBuilder) {
function introspectType(value) {
// Unknown type, using Any
if (value === null || value === undefined) {
return ModelBuilder.Any;

View File

@ -20,8 +20,8 @@ exports.inherits = function(newClass, baseClass, options) {
if (options.staticProperties) {
Object.keys(baseClass).forEach(function(classProp) {
if (classProp !== 'super_' && (!newClass.hasOwnProperty(classProp)
|| options.override)) {
if (classProp !== 'super_' && (!newClass.hasOwnProperty(classProp) ||
options.override)) {
var pd = Object.getOwnPropertyDescriptor(baseClass, classProp);
Object.defineProperty(newClass, classProp, pd);
}

View File

@ -526,7 +526,6 @@ ModelBuilder.prototype.define = function defineClass(className, properties, sett
ModelClass.emit('defined', ModelClass);
return ModelClass;
};
// DataType for Date
@ -633,7 +632,6 @@ ModelBuilder.prototype.copyModel = function copyModel(Master) {
hiddenProperty(Slave, 'relations', Master.relations);
if (!(className in modelBuilder.models)) {
// store class in model pool
modelBuilder.models[className] = Slave;
modelBuilder.definitions[className] = {
@ -686,8 +684,7 @@ ModelBuilder.prototype.resolveType = function(type) {
var itemType = this.resolveType(type[0]);
if (typeof itemType === 'function') {
return [itemType];
}
else {
} else {
return itemType; // Not resolved, return the type string
}
}
@ -782,13 +779,9 @@ ModelBuilder.prototype.buildModels = function(schemas, createModel) {
* @returns {}
*/
ModelBuilder.prototype.buildModelFromInstance = function(name, json, options) {
// Introspect the JSON document to generate a schema
var schema = introspect(json);
// Create a model for the generated schema
return this.define(name, schema, options);
};

View File

@ -212,7 +212,11 @@ ModelBaseClass.prototype._initProperties = function(data, options) {
if (!~fields.indexOf(ctor.relations[p].keyTo)) {
fields.push(ctor.relations[p].keyTo);
}
self.__data[p] = new modelTo(propVal, { fields: fields, applySetters: false, persisted: options.persisted });
self.__data[p] = new modelTo(propVal, {
fields: fields,
applySetters: false,
persisted: options.persisted,
});
}
}
@ -308,7 +312,6 @@ ModelBaseClass.prototype._initProperties = function(data, options) {
// Handle complex types (JSON/Object)
if (!BASE_TYPES[type.name]) {
if (typeof self.__data[p] !== 'object' && self.__data[p]) {
try {
self.__data[p] = JSON.parse(self.__data[p] + '');
@ -318,15 +321,15 @@ ModelBaseClass.prototype._initProperties = function(data, options) {
}
if (type.prototype instanceof ModelBaseClass) {
if (!(self.__data[p] instanceof type)
&& typeof self.__data[p] === 'object'
&& self.__data[p] !== null) {
if (!(self.__data[p] instanceof type) &&
typeof self.__data[p] === 'object' &&
self.__data[p] !== null) {
self.__data[p] = new type(self.__data[p]);
}
} else if (type.name === 'Array' || Array.isArray(type)) {
if (!(self.__data[p] instanceof List)
&& self.__data[p] !== undefined
&& self.__data[p] !== null) {
if (!(self.__data[p] instanceof List) &&
self.__data[p] !== undefined &&
self.__data[p] !== null) {
self.__data[p] = List(self.__data[p], type, self);
}
}

View File

@ -203,8 +203,8 @@ RelationDefinition.prototype.defineMethod = function(name, fn) {
RelationDefinition.prototype.applyScope = function(modelInstance, filter) {
filter = filter || {};
filter.where = filter.where || {};
if ((this.type !== 'belongsTo' || this.type === 'hasOne')
&& typeof this.polymorphic === 'object') { // polymorphic
if ((this.type !== 'belongsTo' || this.type === 'hasOne') &&
typeof this.polymorphic === 'object') { // polymorphic
var discriminator = this.polymorphic.discriminator;
if (this.polymorphic.invert) {
filter.where[discriminator] = this.modelTo.modelName;
@ -255,8 +255,8 @@ RelationDefinition.prototype.applyProperties = function(modelInstance, obj) {
target[key] = source[k];
}
}
if ((this.type !== 'belongsTo' || this.type === 'hasOne')
&& typeof this.polymorphic === 'object') { // polymorphic
if ((this.type !== 'belongsTo' || this.type === 'hasOne') &&
typeof this.polymorphic === 'object') { // polymorphic
var discriminator = this.polymorphic.discriminator;
if (this.polymorphic.invert) {
target[discriminator] = this.modelTo.modelName;
@ -792,9 +792,9 @@ HasMany.prototype.findById = function(fkId, options, cb) {
if (inst[fk] != null && idEquals(inst[fk], modelInstance[pk])) {
cb(null, inst);
} else {
err = new Error('Key mismatch: ' + modelFrom.modelName + '.' + pk
+ ': ' + modelInstance[pk]
+ ', ' + modelTo.modelName + '.' + fk + ': ' + inst[fk]);
err = new Error('Key mismatch: ' + modelFrom.modelName + '.' + pk + ': ' +
modelInstance[pk] + ', ' + modelTo.modelName + '.' + fk + ': ' +
inst[fk]);
err.statusCode = 400;
cb(err);
}
@ -929,9 +929,9 @@ HasManyThrough.prototype.findById = function(fkId, options, cb) {
self.exists(fkId, options, function(err, exists) {
if (err || !exists) {
if (!err) {
err = new Error('No relation found in ' + modelThrough.modelName
+ ' for (' + self.definition.modelFrom.modelName + '.' + modelInstance[pk]
+ ',' + modelTo.modelName + '.' + fkId + ')');
err = new Error('No relation found in ' + modelThrough.modelName +
' for (' + self.definition.modelFrom.modelName + '.' +
modelInstance[pk] + ',' + modelTo.modelName + '.' + fkId + ')');
err.statusCode = 404;
}
return cb(err);
@ -973,9 +973,9 @@ HasManyThrough.prototype.destroyById = function(fkId, options, cb) {
self.exists(fkId, options, function(err, exists) {
if (err || !exists) {
if (!err) {
err = new Error('No record found in ' + modelThrough.modelName
+ ' for (' + self.definition.modelFrom.modelName + '.' + modelInstance[pk]
+ ' ,' + modelTo.modelName + '.' + fkId + ')');
err = new Error('No record found in ' + modelThrough.modelName +
' for (' + self.definition.modelFrom.modelName + '.' +
modelInstance[pk] + ' ,' + modelTo.modelName + '.' + fkId + ')');
err.statusCode = 404;
}
return cb(err);
@ -1022,7 +1022,7 @@ HasManyThrough.prototype.create = function create(data, options, cb) {
var fk2 = keys[1];
function createRelation(to, next) {
var d = {}, q = {}, filter = { where:q };
var d = {}, q = {}, filter = { where: q };
d[fk1] = q[fk1] = modelInstance[definition.keyFrom];
d[fk2] = q[fk2] = to[pk2];
definition.applyProperties(modelInstance, d);
@ -1353,8 +1353,7 @@ BelongsTo.prototype.update = function(targetModelData, options, cb) {
if (inst instanceof ModelBaseClass) {
inst.updateAttributes(targetModelData, options, cb);
} else {
cb(new Error('BelongsTo relation ' + definition.name
+ ' is empty'));
cb(new Error('BelongsTo relation ' + definition.name + ' is empty'));
}
});
return cb.promise;
@ -1379,8 +1378,7 @@ BelongsTo.prototype.destroy = function(options, cb) {
cb && cb(err, targetModel);
});
} else {
cb(new Error('BelongsTo relation ' + definition.name
+ ' is empty'));
cb(new Error('BelongsTo relation ' + definition.name + ' is empty'));
}
});
return cb.promise;
@ -1446,7 +1444,6 @@ BelongsTo.prototype.related = function(condOrRefresh, options, cb) {
self.resetCache(newValue);
} else if (typeof cb === 'function') { // acts as async getter
if (discriminator) {
var modelToName = modelInstance[discriminator];
if (typeof modelToName !== 'string') {
@ -1463,8 +1460,7 @@ BelongsTo.prototype.related = function(condOrRefresh, options, cb) {
var query = { where: {}};
query.where[pk] = modelInstance[fk];
if (query.where[pk] === undefined
|| query.where[pk] === null) {
if (query.where[pk] === undefined || query.where[pk] === null) {
// Foreign key is undefined
return process.nextTick(cb);
}
@ -1485,14 +1481,15 @@ BelongsTo.prototype.related = function(condOrRefresh, options, cb) {
return cb(null, null);
}
// Check if the foreign key matches the primary key
if (inst[pk] != null && modelInstance[fk] != null
&& inst[pk].toString() === modelInstance[fk].toString()) {
if (inst[pk] != null && modelInstance[fk] != null &&
inst[pk].toString() === modelInstance[fk].toString()) {
self.resetCache(inst);
cb(null, inst);
} else {
err = new Error('Key mismatch: ' + self.definition.modelFrom.modelName + '.' + fk
+ ': ' + modelInstance[fk]
+ ', ' + modelTo.modelName + '.' + pk + ': ' + inst[pk]);
err = new Error(
'Key mismatch: ' + self.definition.modelFrom.modelName + '.' + fk +
': ' + modelInstance[fk] +
', ' + modelTo.modelName + '.' + pk + ': ' + inst[pk]);
err.statusCode = 400;
cb(err);
}
@ -1718,8 +1715,9 @@ HasOne.prototype.create = function(targetModelData, options, cb) {
self.resetCache(targetModel);
cb && cb(err, targetModel);
} else {
cb && cb(new Error('HasOne relation cannot create more than one instance of '
+ modelTo.modelName));
cb && cb(new Error(
'HasOne relation cannot create more than one instance of ' +
modelTo.modelName));
}
});
return cb.promise;
@ -1739,8 +1737,7 @@ HasOne.prototype.update = function(targetModelData, options, cb) {
delete targetModelData[fk];
targetModel.updateAttributes(targetModelData, cb);
} else {
cb(new Error('HasOne relation ' + definition.name
+ ' is empty'));
cb(new Error('HasOne relation ' + definition.name + ' is empty'));
}
});
return cb.promise;
@ -1758,8 +1755,7 @@ HasOne.prototype.destroy = function(options, cb) {
if (targetModel instanceof ModelBaseClass) {
targetModel.destroy(options, cb);
} else {
cb(new Error('HasOne relation ' + definition.name
+ ' is empty'));
cb(new Error('HasOne relation ' + definition.name + ' is empty'));
}
});
return cb.promise;
@ -1891,14 +1887,16 @@ HasOne.prototype.related = function(condOrRefresh, options, cb) {
return cb(null, null);
}
// Check if the foreign key matches the primary key
if (inst[fk] != null && modelInstance[pk] != null
&& inst[fk].toString() === modelInstance[pk].toString()) {
if (inst[fk] != null && modelInstance[pk] != null &&
inst[fk].toString() === modelInstance[pk].toString()) {
self.resetCache(inst);
cb(null, inst);
} else {
err = new Error('Key mismatch: ' + self.definition.modelFrom.modelName + '.' + pk
+ ': ' + modelInstance[pk]
+ ', ' + modelTo.modelName + '.' + fk + ': ' + inst[fk]);
err = new Error(
'Key mismatch: ' + self.definition.modelFrom.modelName + '.' + pk +
': ' + modelInstance[pk] +
', ' + modelTo.modelName + '.' + fk + ': ' + inst[fk]
);
err.statusCode = 400;
cb(err);
}
@ -3127,9 +3125,9 @@ ReferencesMany.prototype.findById = function(fkId, options, cb) {
if (utils.findIndexOf(ids, inst[pk], idEquals) > -1) {
cb(null, inst);
} else {
err = new Error('Key mismatch: ' + modelFrom.modelName + '.' + fk
+ ': ' + modelInstance[fk]
+ ', ' + modelTo.modelName + '.' + pk + ': ' + inst[pk]);
err = new Error('Key mismatch: ' + modelFrom.modelName + '.' + fk +
': ' + modelInstance[fk] +
', ' + modelTo.modelName + '.' + pk + ': ' + inst[pk]);
err.statusCode = 400;
cb(err);
}

View File

@ -3,6 +3,8 @@
// This file is licensed under the MIT License.
// License text available at https://opensource.org/licenses/MIT
/*eslint-disable camelcase*/
var i8n = require('inflection');
var utils = require('./utils');
var defineCachedRelations = utils.defineCachedRelations;
@ -80,8 +82,8 @@ ScopeDefinition.prototype.related = function(receiver, scopeParams, condOrRefres
}
cb = cb || utils.createPromiseCallback();
if (!self.__cachedRelations || self.__cachedRelations[name] === undefined
|| actualRefresh) {
if (!self.__cachedRelations || self.__cachedRelations[name] === undefined ||
actualRefresh) {
// It either doesn't hit the cache or refresh is required
var params = mergeQuery(actualCond, scopeParams, { nestedInclude: true });
var targetModel = this.targetModel(receiver);
@ -181,8 +183,8 @@ function defineScope(cls, targetClass, name, params, methods, options) {
return self.__cachedRelations[name];
}
} else {
if (typeof condOrRefresh === 'function'
&& options === undefined && cb === undefined) {
if (typeof condOrRefresh === 'function' &&
options === undefined && cb === undefined) {
// customer.orders(cb)
cb = condOrRefresh;
options = {};
@ -226,8 +228,8 @@ function defineScope(cls, targetClass, name, params, methods, options) {
}
f.getAsync = function(condOrRefresh, options, cb) {
if (typeof condOrRefresh === 'function'
&& options === undefined && cb === undefined) {
if (typeof condOrRefresh === 'function' &&
options === undefined && cb === undefined) {
// customer.orders.getAsync(cb)
cb = condOrRefresh;
options = {};

View File

@ -39,7 +39,6 @@ Types.Any.prototype.toObject = Types.Any.prototype.toJSON = function() {
};
module.exports = function(modelTypes) {
var GeoPoint = require('./geo').GeoPoint;
for (var t in Types) {

View File

@ -29,9 +29,9 @@ function safeRequire(module) {
try {
return require(module);
} catch (e) {
console.log('Run "npm install loopback-datasource-juggler ' + module
+ '" command to use loopback-datasource-juggler using ' + module
+ ' database engine');
console.log('Run "npm install loopback-datasource-juggler ' + module +
'" command to use loopback-datasource-juggler using ' + module +
' database engine');
process.exit(1);
}
}
@ -55,9 +55,8 @@ function setScopeValuesFromWhere(data, where, targetModel) {
var prop = targetModel.definition.properties[i];
if (prop) {
var val = where[i];
if (typeof val !== 'object' || val instanceof prop.type
|| prop.type.name === 'ObjectID') // MongoDB key
{
if (typeof val !== 'object' || val instanceof prop.type ||
prop.type.name === 'ObjectID') { // MongoDB key
// Only pick the {propertyName: propertyValue}
data[i] = where[i];
}
@ -136,8 +135,7 @@ function convertToArray(include) {
var obj = {};
obj[includeEntry] = true;
normalized.push(obj);
}
else {
} else {
normalized.push(includeEntry);
}
}
@ -181,8 +179,7 @@ function mergeQuery(base, update, spec) {
var saved = base.include;
base.include = {};
base.include[update.include] = saved;
}
else {
} else {
//default behaviour of inclusion merge - merge inclusions at the same
//level. - https://github.com/strongloop/loopback-datasource-juggler/pull/569#issuecomment-95310874
base.include = mergeIncludes(base.include, update.include);
@ -323,8 +320,8 @@ function removeUndefined(query, handleUndefined) {
}
}
if (!Array.isArray(x) && (typeof x === 'object' && x !== null
&& x.constructor !== Object)) {
if (!Array.isArray(x) && (typeof x === 'object' && x !== null &&
x.constructor !== Object)) {
// This object is not a plain object
this.update(x, true); // Stop navigating into this object
return x;
@ -441,12 +438,10 @@ function defineCachedRelations(obj) {
* @returns {boolean}
*/
function isPlainObject(obj) {
return (typeof obj === 'object') && (obj !== null)
&& (obj.constructor === Object);
return (typeof obj === 'object') && (obj !== null) &&
(obj.constructor === Object);
}
function sortObjectsByIds(idName, ids, objects, strict) {
ids = ids.map(function(id) {
return (typeof id === 'object') ? String(id) : id;

View File

@ -356,7 +356,8 @@ function validateUniqueness(attr, conf, err, done) {
err();
} else if (found.length === 1 && idName === attr && isNewRecord) {
err();
} else if (found.length === 1 && (!this.id || !found[0].id || found[0].id.toString() != this.id.toString())) {
} else if (found.length === 1 && (!this.id || !found[0].id ||
found[0].id.toString() != this.id.toString())) {
err();
}
done();
@ -494,7 +495,6 @@ Validatable.prototype.isValid = function(callback, data) {
});
}
}
}, data, callback);
if (async) {
@ -504,7 +504,6 @@ Validatable.prototype.isValid = function(callback, data) {
} else {
return valid;
}
};
function cleanErrors(inst) {
@ -522,8 +521,8 @@ function validationFailed(inst, attr, conf, cb) {
// here we should check skip validation conditions (if, unless)
// that can be specified in conf
if (skipValidation(inst, conf, 'if')
|| skipValidation(inst, conf, 'unless')) {
if (skipValidation(inst, conf, 'if') ||
skipValidation(inst, conf, 'unless')) {
if (cb) cb(false);
return false;
}

View File

@ -41,6 +41,7 @@
"async": "~1.0.0",
"debug": "^2.1.1",
"depd": "^1.0.0",
"eslint": "^2.9.0",
"inflection": "^1.6.0",
"loopback-connector": "^2.1.0",
"node-uuid": "^1.4.2",

View File

@ -3,6 +3,8 @@
// This file is licensed under the MIT License.
// License text available at https://opensource.org/licenses/MIT
/* eslint-disable camelcase */
/*
* Describe context objects of operation hooks in comprehensive HTML table.
* Usage:

View File

@ -9,7 +9,6 @@ var async = require('async');
var db, User;
describe('basic-querying', function() {
before(function(done) {
db = getSchema();
User = db.define('User', {
@ -23,7 +22,6 @@ describe('basic-querying', function() {
});
db.automigrate(done);
});
describe('ping', function() {
@ -36,7 +34,6 @@ describe('basic-querying', function() {
});
describe('findById', function() {
before(function(done) {
User.destroyAll(done);
});
@ -61,7 +58,6 @@ describe('basic-querying', function() {
});
});
});
});
describe('findByIds', function() {
@ -122,11 +118,9 @@ describe('basic-querying', function() {
done();
});
});
});
describe('find', function() {
before(seed);
it('should query collection', function(done) {
@ -304,7 +298,7 @@ describe('basic-querying', function() {
});
it('should support number "gte" that is satisfied', function(done) {
User.find({ order: 'seq', where: { order: { 'gte': 3 },
User.find({ order: 'seq', where: { order: { 'gte': 3 },
}}, function(err, users) {
should.not.exist(err);
users.should.have.property('length', 4);
@ -361,7 +355,7 @@ describe('basic-querying', function() {
});
it('should support string "gte" that is satisfied by null value', function(done) {
User.find({ order: 'seq', where: { name: { 'gte': null },
User.find({ order: 'seq', where: { name: { 'gte': null },
}}, function(err, users) {
should.not.exist(err);
users.should.have.property('length', 0);
@ -370,7 +364,7 @@ describe('basic-querying', function() {
});
it('should support string "gte" that is satisfied', function(done) {
User.find({ order: 'seq', where: { name: { 'gte': 'Paul McCartney' },
User.find({ order: 'seq', where: { name: { 'gte': 'Paul McCartney' },
}}, function(err, users) {
should.not.exist(err);
users.should.have.property('length', 4);
@ -409,7 +403,7 @@ describe('basic-querying', function() {
});
it('should support boolean "gte" that is satisfied', function(done) {
User.find({ order: 'seq', where: { vip: { 'gte': true },
User.find({ order: 'seq', where: { vip: { 'gte': true },
}}, function(err, users) {
should.not.exist(err);
users.should.have.property('length', 3);
@ -451,12 +445,10 @@ describe('basic-querying', function() {
var remaining = 0;
function sample(fields) {
return {
expect: function(arr) {
remaining++;
User.find({ fields: fields }, function(err, users) {
remaining--;
if (err) return done(err);
@ -493,11 +485,9 @@ describe('basic-querying', function() {
sample(['id']).expect(['id']);
sample(['email']).expect(['email']);
});
});
describe('count', function() {
before(seed);
it('should query total count', function(done) {
@ -520,7 +510,6 @@ describe('basic-querying', function() {
});
describe('findOne', function() {
before(seed);
it('should find first record (default sort by id)', function(done) {
@ -576,11 +565,9 @@ describe('basic-querying', function() {
});
});
});
});
describe('exists', function() {
before(seed);
it('should check whether record exist', function(done) {
@ -744,10 +731,10 @@ describe.skip('queries', function() {
var aliases = ['deleteById', 'destroyById', 'removeById'];
async.each(aliases, function(alias, cb) {
Todo[alias](1, function(err) {
should.exist(err);
err.message.should.equal(expectedErrMsg);
cb();
});
should.exist(err);
err.message.should.equal(expectedErrMsg);
cb();
});
}, done);
});

View File

@ -20,7 +20,6 @@ function skip(name) {
}
module.exports = function testSchema(exportCasesHere, dataSource) {
batch = exportCasesHere;
schemaName = dataSource.name;
if (dataSource.name.match(/^\/.*\/test\/\.\.$/)) {
@ -52,7 +51,6 @@ module.exports = function testSchema(exportCasesHere, dataSource) {
// dataSource.disconnect();
console.log('Test done in %dms\n', Date.now() - start);
}
};
Object.defineProperty(module.exports, 'it', {
@ -96,7 +94,6 @@ function testOrm(dataSource) {
var Post, User, Passport, Log, Dog;
it('should define class', function(test) {
User = dataSource.define('User', {
name: { type: String, index: true },
email: { type: String, index: true },
@ -196,7 +193,6 @@ function testOrm(dataSource) {
test.done();
}
});
});
it('should initialize object properly', function(test) {
@ -317,7 +313,8 @@ function testOrm(dataSource) {
post.destroy(function() {
Post.exists(post.id, function(err, exists) {
if (err) console.log(err);
test.ok(!exists, 'Hey! ORM told me that object exists, but it looks like it doesn\'t. Something went wrong...');
test.ok(!exists, 'Hey! ORM told me that object exists, but it ' +
'looks like it doesn\'t. Something went wrong...');
Post.findById(post.id, function(err, obj) {
test.equal(obj, null, 'Param obj should be null');
test.done();
@ -443,7 +440,6 @@ function testOrm(dataSource) {
});
it('should navigate variations of belongsTo regardless of column name', function(test) {
Dog.create({ name: 'theDog' }, function(err, obj) {
test.ok(obj instanceof Dog);
Log.create({ name: 'theLog', ownerId: obj.id }, function(err, obj) {
@ -468,7 +464,6 @@ function testOrm(dataSource) {
});
it('hasMany should support additional conditions', function(test) {
User.create(function(e, u) {
u.posts.create({}, function(e, p) {
u.posts({ where: { id: p.id }}, function(e, posts) {
@ -477,9 +472,9 @@ function testOrm(dataSource) {
});
});
});
});
/*eslint-disable*/
it('hasMany should be cached', function(test) {
//User.create(function (e, u) {
// u.posts.create({}, function (e, p) {
@ -494,7 +489,6 @@ function testOrm(dataSource) {
User.findById(post.userId, function(err, user) {
User.create(function(err, voidUser) {
Post.create({ userId: user.id }, function() {
// There can't be any concurrency because we are counting requests
// We are first testing cases when user has posts
user.posts(function(err, data) {
@ -531,14 +525,11 @@ function testOrm(dataSource) {
});
});
});
});
});
}
});
});
});
});
});
@ -546,8 +537,8 @@ function testOrm(dataSource) {
}
}
});
});
/*eslint-enable*/
// it('should handle hasOne relationship', function (test) {
// User.create(function (err, u) {
@ -736,7 +727,6 @@ function testOrm(dataSource) {
function numerically(a, b) {
return a - b;
}
});
// if (
@ -1139,5 +1129,4 @@ function testOrm(dataSource) {
});
});
});
}

View File

@ -9,7 +9,6 @@ var async = require('async');
var db, User, options, filter;
describe('crud-with-options', function() {
before(function(done) {
db = getSchema();
User = db.define('User', {
@ -25,11 +24,9 @@ describe('crud-with-options', function() {
filter = { fields: ['name', 'id'] };
db.automigrate(['User'], done);
});
describe('findById', function() {
before(function(done) {
User.destroyAll(done);
});
@ -186,11 +183,9 @@ describe('crud-with-options', function() {
done(err);
});
});
});
describe('findByIds', function() {
before(function(done) {
var people = [
{ id: 1, name: 'a', vip: true },
@ -231,11 +226,9 @@ describe('crud-with-options', function() {
done();
});
});
});
describe('find', function() {
before(seed);
it('should allow find(cb)', function(done) {
@ -303,11 +296,9 @@ describe('crud-with-options', function() {
User.find({ limit: 3 }, {}, 'invalid cb');
}).should.throw('The cb argument must be a function');
});
});
describe('count', function() {
before(seed);
it('should allow count(cb)', function(done) {
@ -336,11 +327,9 @@ describe('crud-with-options', function() {
done();
});
});
});
describe('findOne', function() {
before(seed);
it('should allow findOne(cb)', function(done) {
@ -383,11 +372,9 @@ describe('crud-with-options', function() {
done();
}, undefined);
});
});
describe('exists', function() {
before(seed);
it('should allow exists(id, cb)', function(done) {
@ -410,11 +397,9 @@ describe('crud-with-options', function() {
});
});
});
});
describe('save', function() {
it('should allow save(options, cb)', function(done) {
var options = { foo: 'bar' };
var opts;
@ -431,11 +416,9 @@ describe('crud-with-options', function() {
done();
});
});
});
describe('destroyAll with options', function() {
beforeEach(seed);
it('should allow destroyAll(where, options, cb)', function(done) {
@ -482,11 +465,9 @@ describe('crud-with-options', function() {
});
});
});
});
describe('updateAll ', function() {
beforeEach(seed);
it('should allow updateAll(where, data, cb)', function(done) {
@ -533,9 +514,7 @@ describe('crud-with-options', function() {
});
});
});
});
});
function seed(done) {

View File

@ -9,7 +9,6 @@ var should = require('./init.js');
var db, Model;
describe('datatypes', function() {
before(function(done) {
db = getSchema();
Nested = db.define('Nested', {});
@ -98,7 +97,6 @@ describe('datatypes', function() {
done();
});
}
});
it('should respect data types when updating attributes', function(done) {
@ -137,7 +135,6 @@ describe('datatypes', function() {
}
function testDataInDB(done) {
// verify that the value stored in the db is still an object
function cb(err, data) {
should.exist(data);

View File

@ -51,7 +51,6 @@ var setupProducts = function(ids, done) {
};
describe('default scope', function() {
before(function(done) {
db = getSchema();
@ -132,7 +131,6 @@ describe('default scope', function() {
});
describe('manipulation', function() {
var ids = {};
before(function(done) {
@ -140,7 +138,7 @@ describe('default scope', function() {
});
it('should return a scoped instance', function() {
var p = new Tool({ name: 'Product A', kind:'ignored' });
var p = new Tool({ name: 'Product A', kind: 'ignored' });
p.name.should.equal('Product A');
p.kind.should.equal('Tool');
p.setAttributes({ kind: 'ignored' });
@ -209,11 +207,9 @@ describe('default scope', function() {
done();
});
});
});
describe('findById', function() {
var ids = {};
before(function(done) {
@ -244,11 +240,9 @@ describe('default scope', function() {
done();
});
});
});
describe('find', function() {
var ids = {};
before(function(done) {
@ -318,11 +312,9 @@ describe('default scope', function() {
done();
});
});
});
describe('exists', function() {
var ids = {};
before(function(done) {
@ -368,11 +360,9 @@ describe('default scope', function() {
done();
});
});
});
describe('count', function() {
var ids = {};
before(function(done) {
@ -418,11 +408,9 @@ describe('default scope', function() {
done();
});
});
});
describe('removeById', function() {
var ids = {};
function isDeleted(id, done) {
@ -478,11 +466,9 @@ describe('default scope', function() {
done();
});
});
});
describe('update', function() {
var ids = {};
before(function(done) {
@ -525,11 +511,9 @@ describe('default scope', function() {
done();
});
});
});
describe('remove', function() {
var ids = {};
before(function(done) {
@ -599,11 +583,9 @@ describe('default scope', function() {
});
});
});
});
describe('scopes', function() {
var ids = {};
before(function(done) {
@ -639,17 +621,15 @@ describe('default scope', function() {
done();
});
});
});
describe('scope function', function() {
before(function(done) {
db.automigrate(done);
});
it('should create a scoped instance - widget', function(done) {
Widget.create({ name: 'Product', kind:'ignored' }, function(err, p) {
Widget.create({ name: 'Product', kind: 'ignored' }, function(err, p) {
p.name.should.equal('Product');
p.kind.should.equal('Widget');
done();
@ -657,7 +637,7 @@ describe('default scope', function() {
});
it('should create a scoped instance - thing', function(done) {
Thing.create({ name: 'Product', kind:'ignored' }, function(err, p) {
Thing.create({ name: 'Product', kind: 'ignored' }, function(err, p) {
p.name.should.equal('Product');
p.kind.should.equal('Thing');
done();
@ -691,11 +671,9 @@ describe('default scope', function() {
done();
});
});
});
describe('relations', function() {
var ids = {};
before(function(done) {
@ -814,11 +792,9 @@ describe('default scope', function() {
});
});
});
});
describe('with include option', function() {
before(function(done) {
db.automigrate(done);
});
@ -840,7 +816,5 @@ describe('default scope', function() {
done();
});
});
});
});

View File

@ -65,7 +65,7 @@ describe('defaults', function() {
it('should preserve defaults in upsert update', function(done) {
Server.findOne({}, function(err, server) {
Server.upsert({ id:server.id, port: 1337 }, function(err, s) {
Server.upsert({ id: server.id, port: 1337 }, function(err, s) {
should.not.exist(err);
(Number(1337)).should.equal(s.port);
server.createdAt.should.eql(s.createdAt);
@ -73,5 +73,4 @@ describe('defaults', function() {
});
});
});
});

View File

@ -596,7 +596,8 @@ describe('discoverExportedForeignKeys', function() {
ds.discoverExportedForeignKeys('INVENTORY', options);
});
it('should discover foreign key definitions using `discoverExportedForeignKeys` - promise variant', function(done) {
it('should discover foreign key definitions using ' +
'`discoverExportedForeignKeys` - promise variant', function(done) {
ds.discoverExportedForeignKeys('INVENTORY', {})
.then(function(modelForeignKeys) {
modelForeignKeys.should.be.eql(exportedForeignKeys);

View File

@ -12,9 +12,7 @@ var GeoPoint = require('../lib/geo').GeoPoint;
var DELTA = 0.0000001;
describe('GeoPoint', function() {
describe('constructor', function() {
it('should support a valid array', function() {
var point = new GeoPoint([-34, 150]);
@ -78,33 +76,26 @@ describe('GeoPoint', function() {
};
fn.should.throw();
});
});
describe('toString()', function() {
it('should return a string in the form "lat,lng"', function() {
var point = new GeoPoint({ lat: -34, lng: 150 });
point.toString().should.equal('-34,150');
});
});
describe('distance calculation between two points', function() {
var here = new GeoPoint({ lat: 40.77492964101182, lng: -73.90950187151662 });
var there = new GeoPoint({ lat: 40.7753227, lng: -73.909217 });
it('should return value in miles by default', function() {
var distance = GeoPoint.distanceBetween(here, there);
distance.should.be.a.Number;
distance.should.be.approximately(0.03097916611592679, DELTA);
});
it('should return value using specified unit', function() {
/* Supported units:
* - `radians`
* - `kilometers`
@ -138,7 +129,5 @@ describe('GeoPoint', function() {
distance.should.be.a.Number;
distance.should.be.approximately(0.0004483676593058972, DELTA);
});
});
});

View File

@ -14,7 +14,6 @@ var j = require('../'),
db, User;
describe('hooks', function() {
before(function(done) {
db = getSchema();
@ -29,7 +28,6 @@ describe('hooks', function() {
});
describe('initialize', function() {
afterEach(function() {
User.afterInitialize = null;
});
@ -54,11 +52,9 @@ describe('hooks', function() {
done();
});
});
});
describe('create', function() {
afterEach(removeHooks('Create'));
it('should be triggered on create', function(done) {
@ -209,7 +205,6 @@ describe('hooks', function() {
});
});
});
});
describe('update', function() {
@ -275,7 +270,6 @@ describe('hooks', function() {
});
describe('destroy', function() {
afterEach(removeHooks('Destroy'));
it('should be triggered on destroy', function(done) {
@ -308,7 +302,6 @@ describe('hooks', function() {
});
});
});
});
describe('lifecycle', function() {
@ -435,7 +428,6 @@ describe('hooks', function() {
done();
});
});
});
});

View File

@ -13,7 +13,6 @@ var DataSource = require('../').DataSource;
var db, User, Profile, AccessToken, Post, Passport, City, Street, Building, Assembly, Part;
describe('include', function() {
before(setup);
it('should fetch belongsTo relation', function(done) {
@ -61,7 +60,6 @@ describe('include', function() {
it('should fetch Passport - Owner - Posts', function(done) {
Passport.find({ include: { owner: 'posts' }}, function(err, passports) {
should.not.exist(err);
should.exist(passports);
passports.length.should.be.ok;
@ -156,7 +154,7 @@ describe('include', function() {
it('should fetch Passports with include scope on Posts', function(done) {
Passport.find({
include: { owner: { relation: 'posts', scope:{
include: { owner: { relation: 'posts', scope: {
fields: ['title'], include: ['author'],
order: 'title DESC',
}}},
@ -211,7 +209,7 @@ describe('include', function() {
it('should fetch Users with include scope on Posts - belongsTo', function(done) {
Post.find({
include: { relation: 'author', scope:{ fields: ['name'] }},
include: { relation: 'author', scope: { fields: ['name'] }},
}, function(err, posts) {
should.not.exist(err);
should.exist(posts);
@ -228,9 +226,12 @@ describe('include', function() {
it('should fetch Users with include scope on Posts - hasMany', function(done) {
User.find({
include: { relation: 'posts', scope:{
order: 'title DESC',
}},
include: {
relation: 'posts',
scope: {
order: 'title DESC',
},
},
}, function(err, users) {
should.not.exist(err);
should.exist(users);
@ -258,9 +259,12 @@ describe('include', function() {
it('should fetch Users with include scope on Passports - hasMany', function(done) {
User.find({
include: { relation: 'passports', scope:{
where: { number: '2' },
}},
include: {
relation: 'passports',
scope: {
where: { number: '2' },
},
},
}, function(err, users) {
should.not.exist(err);
should.exist(users);
@ -373,13 +377,11 @@ describe('include', function() {
// Create a part
assembly.parts.create({ partNumber: 'door' }, function(err, part4) {
Assembly.find({ include: 'parts' }, function(err, assemblies) {
assemblies.length.should.equal(1);
assemblies[0].parts().length.should.equal(2);
done();
});
});
});
});
@ -401,8 +403,7 @@ describe('include', function() {
if (profile) {
profile.should.be.an.instanceOf(Profile);
usersWithProfile++;
}
else {
} else {
(profile === null).should.be.true;
}
// The __cachedRelations should be removed from json output
@ -744,7 +745,6 @@ function setup(done) {
}
);
}
});
}
@ -826,7 +826,6 @@ describe('Model instance with included relation .toJSON()', function() {
function(err) {
done(err);
});
});
function createChallengers(callback) {
@ -850,7 +849,6 @@ describe('Model instance with included relation .toJSON()', function() {
it('should recursively serialize objects', function(done) {
var filter = { include: { gameParticipations: 'results' }};
ChallengerModel.find(filter, function(err, challengers) {
var levelOneInclusion = challengers[0].toJSON().gameParticipations[0];
assert(levelOneInclusion.__data === undefined, '.__data of a level 1 inclusion is undefined.');

View File

@ -3,6 +3,8 @@
// This file is licensed under the MIT License.
// License text available at https://opensource.org/licenses/MIT
/* eslint-disable camelcase */
var assert = require('assert');
var should = require('should');
@ -53,7 +55,7 @@ describe('include_util', function() {
var objs = [
{ id: 11, letter: 'A' },
{ id: 22, letter: 'B' },
];
];
var result = includeUtils.buildOneToManyIdentityMapWithOrigKeys(objs, 'id');
result.exist(11).should.be.true;
result.exist(22).should.be.true;
@ -65,7 +67,7 @@ describe('include_util', function() {
{ fk_id: 22, letter: 'B' },
{ fk_id: 33, letter: 'C' },
{ fk_id: 11, letter: 'HA!' },
];
];
var result = includeUtils.buildOneToManyIdentityMapWithOrigKeys(objs, 'fk_id');
result.get(11)[0]['letter'].should.equal('A');

View File

@ -30,7 +30,6 @@ var json = {
};
describe('Introspection of model definitions from JSON', function() {
it('should handle simple types', function() {
assert.equal(introspectType('123'), 'string');
assert.equal(introspectType(true), 'boolean');
@ -129,6 +128,5 @@ describe('Introspection of model definitions from JSON', function() {
assert.deepEqual(obj, copy);
done();
});
});

View File

@ -13,7 +13,6 @@ var ModelBuilder = jdb.ModelBuilder;
var DataSource = jdb.DataSource;
describe('ModelBuilder define model', function() {
it('should be able to define plain models', function(done) {
var modelBuilder = new ModelBuilder();
@ -260,7 +259,6 @@ describe('ModelBuilder define model', function() {
follow.should.have.property('id');
assert.deepEqual(follow.id, { followerId: 1, followeeId: 2 });
});
});
describe('DataSource ping', function() {
@ -398,7 +396,6 @@ describe('DataSource define model', function() {
Color.all(function(err, colors) {
colors.should.have.lengthOf(3);
});
});
it('should emit events during attach', function() {
@ -435,7 +432,6 @@ describe('DataSource define model', function() {
var User = ds.define('User', { name: String, bio: String }, { strict: true });
User.create({ name: 'Joe', age: 20 }, function(err, user) {
User.modelName.should.equal('User');
user.should.be.type('object');
assert(user.name === 'Joe');
@ -479,7 +475,6 @@ describe('DataSource define model', function() {
User.modelName.should.equal('User');
User.create({ name: 'Joe', age: 20 }, function(err, user) {
user.should.be.type('object').and.have.property('name', 'Joe');
user.should.have.property('name', 'Joe');
user.should.have.property('age', 20);
@ -501,7 +496,6 @@ describe('DataSource define model', function() {
var User = ds.define('User', {});
User.create({ name: 'Joe', age: 20 }, function(err, user) {
User.modelName.should.equal('User');
user.should.be.type('object').and.have.property('name', 'Joe');
user.should.have.property('name', 'Joe');
@ -576,7 +570,6 @@ describe('DataSource define model', function() {
user.toObject().should.not.have.property('age');
user.toObject(true).should.not.have.property('age');
user.toObject(false).should.have.property('age', 20);
});
it('should update the instance with unknown properties', function(done) {
@ -601,7 +594,6 @@ describe('DataSource define model', function() {
done();
});
});
});
});
@ -656,7 +648,6 @@ describe('DataSource define model', function() {
});
User.http.path.should.equal('/accounts');
});
});
describe('Load models with base', function() {
@ -791,7 +782,6 @@ describe('Models attached to a dataSource', function() {
done();
});
});
});
});
@ -816,7 +806,6 @@ describe('Models attached to a dataSource', function() {
done();
});
});
});
});
@ -838,7 +827,6 @@ describe('Models attached to a dataSource', function() {
done();
});
});
});
it('save should update the instance with the same id', function(done) {
@ -859,7 +847,6 @@ describe('Models attached to a dataSource', function() {
done();
});
});
});
});
@ -881,7 +868,6 @@ describe('Models attached to a dataSource', function() {
done();
});
});
});
});
@ -903,7 +889,6 @@ describe('Models attached to a dataSource', function() {
done();
});
});
});
});
@ -940,7 +925,6 @@ describe('DataSource connector types', function() {
result = ds.supportTypes(['rdbms']);
assert(!result);
});
});
describe('DataSource constructor', function() {
@ -1012,7 +996,11 @@ describe('Load models with relations', function() {
var ds = new DataSource('memory');
var Post = ds.define('Post', { userId: Number, content: String });
var User = ds.define('User', { name: String }, { relations: { posts: { type: 'hasMany', model: 'Post' }}});
var User = ds.define(
'User',
{ name: String },
{ relations: { posts: { type: 'hasMany', model: 'Post' }}}
);
assert(User.relations['posts']);
done();
@ -1022,7 +1010,11 @@ describe('Load models with relations', function() {
var ds = new DataSource('memory');
var User = ds.define('User', { name: String });
var Post = ds.define('Post', { userId: Number, content: String }, { relations: { user: { type: 'belongsTo', model: 'User' }}});
var Post = ds.define(
'Post',
{ userId: Number, content: String },
{ relations: { user: { type: 'belongsTo', model: 'User' }}}
);
assert(Post.relations['user']);
done();
@ -1032,7 +1024,11 @@ describe('Load models with relations', function() {
var ds = new DataSource('memory');
var Post = ds.define('Post', { userId: Number, content: String });
var User = ds.define('User', { name: String }, { relations: { posts: { type: 'referencesMany', model: 'Post' }}});
var User = ds.define(
'User',
{ name: String },
{ relations: { posts: { type: 'referencesMany', model: 'Post' }}}
);
assert(User.relations['posts']);
done();
@ -1042,7 +1038,11 @@ describe('Load models with relations', function() {
var ds = new DataSource('memory');
var Post = ds.define('Post', { userId: Number, content: String });
var User = ds.define('User', { name: String }, { relations: { posts: { type: 'embedsMany', model: 'Post' }}});
var User = ds.define(
'User',
{ name: String },
{ relations: { posts: { type: 'embedsMany', model: 'Post' }}}
);
assert(User.relations['posts']);
done();
@ -1095,8 +1095,15 @@ describe('Load models with relations', function() {
it('should set up foreign key with the correct type', function(done) {
var ds = new DataSource('memory');
var User = ds.define('User', { name: String, id: { type: String, id: true }});
var Post = ds.define('Post', { content: String }, { relations: { user: { type: 'belongsTo', model: 'User' }}});
var User = ds.define(
'User',
{ name: String, id: { type: String, id: true }}
);
var Post = ds.define(
'Post',
{ content: String },
{ relations: { user: { type: 'belongsTo', model: 'User' }}}
);
var fk = Post.definition.properties['userId'];
assert(fk, 'The foreign key should be added');
@ -1108,14 +1115,37 @@ describe('Load models with relations', function() {
it('should set up hasMany and belongsTo relations', function(done) {
var ds = new DataSource('memory');
var User = ds.define('User', { name: String }, { relations: { posts: { type: 'hasMany', model: 'Post' }, accounts: { type: 'hasMany', model: 'Account' }}});
var User = ds.define(
'User',
{ name: String },
{
relations: {
posts: {
type: 'hasMany',
model: 'Post',
},
accounts: {
type: 'hasMany',
model: 'Account',
},
},
}
);
assert(!User.relations['posts']);
assert(!User.relations['accounts']);
var Post = ds.define('Post', { userId: Number, content: String }, { relations: { user: { type: 'belongsTo', model: 'User' }}});
var Post = ds.define(
'Post',
{ userId: Number, content: String },
{ relations: { user: { type: 'belongsTo', model: 'User' }}}
);
var Account = ds.define('Account', { userId: Number, type: String }, { relations: { user: { type: 'belongsTo', model: 'User' }}});
var Account = ds.define(
'Account',
{ userId: Number, type: String },
{ relations: { user: { type: 'belongsTo', model: 'User' }}}
);
assert(Post.relations['user']);
assert.deepEqual(Post.relations['user'].toJSON(), {
@ -1157,11 +1187,14 @@ describe('Load models with relations', function() {
var Post = ds.define('Post', { userId: Number, content: String });
try {
var User = ds.define('User', { name: String }, { relations: { posts: { model: 'Post' }}});
var User = ds.define(
'User',
{ name: String },
{ relations: { posts: { model: 'Post' }}}
);
} catch (e) {
done();
}
});
it('should throw if the relation type is invalid', function(done) {
@ -1170,11 +1203,14 @@ describe('Load models with relations', function() {
var Post = ds.define('Post', { userId: Number, content: String });
try {
var User = ds.define('User', { name: String }, { relations: { posts: { type: 'hasXYZ', model: 'Post' }}});
var User = ds.define(
'User',
{ name: String },
{ relations: { posts: { type: 'hasXYZ', model: 'Post' }}}
);
} catch (e) {
done();
}
});
it('should handle hasMany through', function(done) {
@ -1190,11 +1226,21 @@ describe('Load models with relations', function() {
assert(!Physician.relations['patients']); // Appointment hasn't been resolved yet
assert(!Patient.relations['physicians']); // Appointment hasn't been resolved yet
var Appointment = ds.createModel('Appointment', {
physicianId: Number,
patientId: Number,
appointmentDate: Date,
}, { relations: { patient: { type: 'belongsTo', model: 'Patient' }, physician: { type: 'belongsTo', model: 'Physician' }}});
var Appointment = ds.createModel('Appointment',
{ physicianId: Number, patientId: Number, appointmentDate: Date },
{
relations: {
patient: {
type: 'belongsTo',
model: 'Patient',
},
physician: {
type: 'belongsTo',
model: 'Physician',
},
},
}
);
assert(Physician.relations['patients']);
assert(Patient.relations['physicians']);
@ -1203,19 +1249,47 @@ describe('Load models with relations', function() {
it('should handle hasMany through options', function(done) {
var ds = new DataSource('memory');
var Physician = ds.createModel('Physician', {
name: String,
}, { relations: { patients: { model: 'Patient', type: 'hasMany', foreignKey: 'leftId', through: 'Appointment' }}});
var Patient = ds.createModel('Patient', {
name: String,
}, { relations: { physicians: { model: 'Physician', type: 'hasMany', foreignKey: 'rightId', through: 'Appointment' }}});
var Appointment = ds.createModel('Appointment', {
physicianId: Number,
patientId: Number,
appointmentDate: Date,
}, { relations: { patient: { type: 'belongsTo', model: 'Patient' }, physician: { type: 'belongsTo', model: 'Physician' }}});
var Physician = ds.createModel('Physician',
{ name: String },
{
relations: {
patients: {
model: 'Patient',
type: 'hasMany',
foreignKey: 'leftId',
through: 'Appointment',
},
},
}
);
var Patient = ds.createModel('Patient',
{ name: String },
{
relations: {
physicians: {
model: 'Physician',
type: 'hasMany',
foreignKey: 'rightId',
through: 'Appointment',
},
},
}
);
var Appointment = ds.createModel('Appointment',
{ physicianId: Number, patientId: Number, appointmentDate: Date },
{
relations: {
patient: {
type: 'belongsTo',
model: 'Patient',
},
physician: {
type: 'belongsTo',
model: 'Physician',
},
},
}
);
assert(Physician.relations['patients'].keyTo === 'leftId');
assert(Patient.relations['physicians'].keyTo === 'rightId');
@ -1227,7 +1301,11 @@ describe('Load models with relations', function() {
var modelBuilder = new ModelBuilder();
var Post = modelBuilder.define('Post', { userId: Number, content: String });
var User = modelBuilder.define('User', { name: String }, { relations: { posts: { type: 'hasMany', model: 'Post' }}});
var User = modelBuilder.define(
'User',
{ name: String },
{ relations: { posts: { type: 'hasMany', model: 'Post' }}}
);
assert(!User.relations['posts']);
Post.attachTo(ds);
@ -1235,7 +1313,6 @@ describe('Load models with relations', function() {
assert(User.relations['posts']);
done();
});
});
describe('Model with scopes', function() {
@ -1355,7 +1432,6 @@ describe('DataAccessObject', function() {
where = model._coerce({ vip: '' });
assert.deepEqual(where, { vip: false });
});
it('should be able to coerce where clause with and operators', function() {
@ -1547,7 +1623,6 @@ describe('DataAccessObject', function() {
ds.settings.test = 'willNotGet';
assert.notEqual(model._getSetting('test'), ds.settings.test, 'Should not get datasource setting');
});
});
describe('Load models from json', function() {
@ -1575,7 +1650,6 @@ describe('Load models from json', function() {
}
it('should be able to define models from json', function() {
var models = loadSchemasSync(path.join(__dirname, 'test1-schemas.json'));
models.should.have.property('AnonymousModel_0');
@ -1828,5 +1902,4 @@ describe('ModelBuilder options.models', function() {
var M1 = builder.define('M1');
assert.equal(M2.M1, M1, 'M1 should be injected to M2');
});
});

View File

@ -13,7 +13,6 @@ var ValidationError = require('..').ValidationError;
var UUID_REGEXP = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
describe('manipulation', function() {
before(function(done) {
db = getSchema();
@ -27,7 +26,6 @@ describe('manipulation', function() {
}, { forceId: true, strict: true });
db.automigrate(['Person'], done);
});
// A simplified implementation of LoopBack's User model
@ -56,7 +54,6 @@ describe('manipulation', function() {
});
describe('create', function() {
before(function(done) {
Person.destroyAll(done);
});
@ -112,7 +109,6 @@ describe('manipulation', function() {
done();
})
.catch(done);
});
it('should return instance of object', function(done) {
@ -328,7 +324,6 @@ describe('manipulation', function() {
});
describe('save', function() {
it('should save new object', function(done) {
var p = new Person;
p.save(function(err) {
@ -530,7 +525,7 @@ describe('manipulation', function() {
// Using {foo: 'bar'} only causes dependent test failures due to the
// stripping of object properties when in strict mode (ie. {foo: 'bar'}
// changes to '{}' and breaks other tests
person.updateAttributes({ name: 'John', foo:'bar' },
person.updateAttributes({ name: 'John', foo: 'bar' },
function(err, p) {
if (err) return done(err);
should.not.exist(p.foo);
@ -545,7 +540,7 @@ describe('manipulation', function() {
it('should throw error on unknown attributes when strict: throw', function(done) {
Person.definition.settings.strict = 'throw';
Person.findById(person.id, function(err, p) {
p.updateAttributes({ foo:'bar' },
p.updateAttributes({ foo: 'bar' },
function(err, p) {
should.exist(err);
err.name.should.equal('Error');
@ -563,7 +558,7 @@ describe('manipulation', function() {
it('should throw error on unknown attributes when strict: throw', function(done) {
Person.definition.settings.strict = 'validate';
Person.findById(person.id, function(err, p) {
p.updateAttributes({ foo:'bar' },
p.updateAttributes({ foo: 'bar' },
function(err, p) {
should.exist(err);
err.name.should.equal('ValidationError');
@ -1029,11 +1024,11 @@ describe('manipulation', function() {
Post.findById(postInstance.id, function(err, p) {
if (err) return done(err);
p.replaceAttributes({ title: 'b' }, function(err, p) {
if (err) return done(err);
p.should.not.have.property('content', undefined);
p.title.should.equal('b');
done();
});
if (err) return done(err);
p.should.not.have.property('content', undefined);
p.title.should.equal('b');
done();
});
});
});
@ -1041,11 +1036,11 @@ describe('manipulation', function() {
Post.findById(postInstance.id, function(err, p) {
if (err) return done(err);
p.replaceAttributes({ title: 'b' }, { validate: false }, function(err, p) {
if (err) return done(err);
p.should.not.have.property('content', undefined);
p.title.should.equal('b');
done();
});
if (err) return done(err);
p.should.not.have.property('content', undefined);
p.title.should.equal('b');
done();
});
});
});
});
@ -1117,7 +1112,6 @@ describe('manipulation', function() {
});
describe('destroy', function() {
it('should destroy record', function(done) {
Person.create(function(err, p) {
p.destroy(function(err) {
@ -1175,7 +1169,6 @@ describe('manipulation', function() {
});
})
.catch(done);
});
// TODO: implement destroy with filtered set
@ -1209,10 +1202,10 @@ describe('manipulation', function() {
if (err) return done(err);
data.should.have.length(0);
Person.find({ where: { name: 'Jane' }}, function(err, data) {
if (err) return done(err);
data.should.have.length(1);
done();
});
if (err) return done(err);
data.should.have.length(1);
done();
});
});
});
});
@ -1514,7 +1507,6 @@ describe('manipulation', function() {
p1 = new Person({ name: 'John', married: undefined });
p1.should.have.property('married', undefined);
});
it('should coerce boolean types properly', function() {
@ -1612,10 +1604,10 @@ describe('manipulation', function() {
if (err) return done(err);
people.should.be.empty;
Person.find({ where: { name: 'Harry Hoe' }}, function(err, people) {
if (err) return done(err);
people.should.have.length(5);
done();
});
if (err) return done(err);
people.should.have.length(5);
done();
});
});
});
});

View File

@ -135,7 +135,6 @@ describe('Memory connector', function() {
assert.equal(users.length, 2);
done(err);
});
});
});
@ -281,7 +280,7 @@ describe('Memory connector', function() {
});
it('should successfully extract 2 users using implied and', function(done) {
User.find({ where: { role:'lead', vip:true }}, function(err, users) {
User.find({ where: { role: 'lead', vip: true }}, function(err, users) {
should(users.length).be.equal(2);
should(users[0].name).be.equal('John Lennon');
should(users[1].name).be.equal('Paul McCartney');
@ -289,8 +288,14 @@ describe('Memory connector', function() {
});
});
it('should successfully extract 2 users using implied and & and', function(done) {
User.find({ where: { name: 'John Lennon', and: [{ role:'lead' }, { vip:true }] }}, function(err, users) {
it('should successfully extract 2 users using implied and & and',
function(done) {
User.find({
where: {
name: 'John Lennon',
and: [{ role: 'lead' }, { vip: true }],
},
}, function(err, users) {
should(users.length).be.equal(1);
should(users[0].name).be.equal('John Lennon');
done();
@ -488,8 +493,8 @@ describe('Memory connector', function() {
should.not.exist(err);
users.length.should.be.equal(2);
for (var i = 0; i < users.length; i++) {
users[i].address.state.should.be.eql('CA');
}
users[i].address.state.should.be.eql('CA');
}
done();
});
});
@ -574,7 +579,6 @@ describe('Memory connector', function() {
},
], done);
}
});
it('should use collection setting', function(done) {
@ -696,7 +700,6 @@ describe('Memory connector', function() {
done();
});
});
});
describe('findOrCreate', function() {
@ -941,7 +944,6 @@ describe('Memory connector with options', function() {
done(err);
});
});
});
describe('Memory connector with observers', function() {

View File

@ -15,7 +15,6 @@ var modelBuilder = new ModelBuilder();
var mixins = modelBuilder.mixins;
function timestamps(Model, options) {
Model.defineProperty('createdAt', { type: Date });
Model.defineProperty('updatedAt', { type: Date });
@ -46,7 +45,6 @@ function timestamps(Model, options) {
mixins.define('TimeStamp', timestamps);
describe('Model class', function() {
it('should define mixins', function() {
mixins.define('Example', function(Model, options) {
Model.prototype.example = function() {
@ -111,7 +109,6 @@ describe('Model class', function() {
});
describe('#mixin()', function() {
var Person, Author, Address;
beforeEach(function() {
@ -139,7 +136,5 @@ describe('Model class', function() {
Author.mixin(Address);
Author._mixins.should.containEql(Address);
});
});
});

View File

@ -49,7 +49,6 @@ describe('ModelDefinition class', function() {
assert.deepEqual(User.toJSON(), json);
done();
});
it('should be able to define additional properties', function(done) {
@ -80,7 +79,6 @@ describe('ModelDefinition class', function() {
assert.deepEqual(json.properties.id, { type: 'Number', id: true });
done();
});
it('should be able to define nesting models', function(done) {
@ -122,7 +120,6 @@ describe('ModelDefinition class', function() {
state: { type: 'String' }});
done();
});
it('should be able to define referencing models', function(done) {
@ -163,7 +160,6 @@ describe('ModelDefinition class', function() {
assert.equal(json.properties.address.type, 'Address');
done();
});
it('should be able to define referencing models by name', function(done) {
@ -204,7 +200,6 @@ describe('ModelDefinition class', function() {
assert.equal(json.properties.address.type, 'Address');
done();
});
it('should report correct id names', function(done) {

View File

@ -16,7 +16,6 @@ var INVALID_DATA = { name: null };
var VALID_DATA = { name: INITIAL_NAME };
describe('optional-validation', function() {
before(function(done) {
db = getSchema();
ModelWithForceId = db.createModel(
@ -137,7 +136,6 @@ describe('optional-validation', function() {
});
describe('no model setting', function() {
describe('method create', function() {
it('should throw on create with validate:true with invalid data', function(done) {
User.create(INVALID_DATA, { validate: true }, expectValidationError(done));
@ -169,8 +167,14 @@ describe('optional-validation', function() {
User.findOrCreate(getNewWhere(), INVALID_DATA, { validate: true }, expectValidationError(done));
});
it('should NOT throw on findOrCreate with validate:false with invalid data', function(done) {
User.findOrCreate(getNewWhere(), INVALID_DATA, { validate: false }, expectCreateSuccess(INVALID_DATA, done));
it('should NOT throw on findOrCreate with validate:false with invalid ' +
'data', function(done) {
User.findOrCreate(
getNewWhere(),
INVALID_DATA,
{ validate: false },
expectCreateSuccess(INVALID_DATA, done)
);
});
it('should NOT throw on findOrCreate with validate:true with valid data', function(done) {
@ -191,12 +195,22 @@ describe('optional-validation', function() {
});
describe('method updateOrCreate on existing data', function() {
it('should throw on updateOrCreate(id) with validate:true with invalid data', function(done) {
callUpdateOrCreateWithExistingUserId(null, { validate: true }, expectValidationError(done));
it('should throw on updateOrCreate(id) with validate:true with invalid ' +
'data', function(done) {
callUpdateOrCreateWithExistingUserId(
null,
{ validate: true },
expectValidationError(done)
);
});
it('should NOT throw on updateOrCreate(id) with validate:false with invalid data', function(done) {
callUpdateOrCreateWithExistingUserId(null, { validate: false }, expectChangeSuccess(INVALID_DATA, done));
it('should NOT throw on updateOrCreate(id) with validate:false with ' +
'invalid data', function(done) {
callUpdateOrCreateWithExistingUserId(
null,
{ validate: false },
expectChangeSuccess(INVALID_DATA, done)
);
});
it('should NOT throw on updateOrCreate(id) with validate:true with valid data', function(done) {
@ -292,11 +306,9 @@ describe('optional-validation', function() {
});
});
});
});
describe('model setting: automaticValidation: false', function() {
before(function(done) {
User.settings.automaticValidation = false;
done();
@ -334,7 +346,12 @@ describe('optional-validation', function() {
});
it('should NOT throw on findOrCreate with validate:false with invalid data', function(done) {
User.findOrCreate(getNewWhere(), INVALID_DATA, { validate: false }, expectCreateSuccess(INVALID_DATA, done));
User.findOrCreate(
getNewWhere(),
INVALID_DATA,
{ validate: false },
expectCreateSuccess(INVALID_DATA, done)
);
});
it('should NOT throw on findOrCreate with validate:true with valid data', function(done) {
@ -346,7 +363,11 @@ describe('optional-validation', function() {
});
it('should NOT throw on findOrCreate with invalid data', function(done) {
User.findOrCreate(getNewWhere(), INVALID_DATA, expectCreateSuccess(INVALID_DATA, done));
User.findOrCreate(
getNewWhere(),
INVALID_DATA,
expectCreateSuccess(INVALID_DATA, done)
);
});
it('should NOT throw on findOrCreate with valid data', function(done) {
@ -355,12 +376,22 @@ describe('optional-validation', function() {
});
describe('method updateOrCreate on existing data', function() {
it('should throw on updateOrCreate(id) with validate:true with invalid data', function(done) {
callUpdateOrCreateWithExistingUserId(null, { validate: true }, expectValidationError(done));
it('should throw on updateOrCreate(id) with validate:true with invalid ' +
'data', function(done) {
callUpdateOrCreateWithExistingUserId(
null,
{ validate: true },
expectValidationError(done)
);
});
it('should NOT throw on updateOrCreate(id) with validate:false with invalid data', function(done) {
callUpdateOrCreateWithExistingUserId(null, { validate: false }, expectChangeSuccess(INVALID_DATA, done));
it('should NOT throw on updateOrCreate(id) with validate:false with ' +
'invalid data', function(done) {
callUpdateOrCreateWithExistingUserId(
null,
{ validate: false },
expectChangeSuccess(INVALID_DATA, done)
);
});
it('should NOT throw on updateOrCreate(id) with validate:true with valid data', function(done) {
@ -417,11 +448,9 @@ describe('optional-validation', function() {
});
});
});
});
describe('model setting: automaticValidation: true', function() {
before(function(done) {
User.settings.automaticValidation = true;
done();
@ -459,7 +488,12 @@ describe('optional-validation', function() {
});
it('should NOT throw on findOrCreate with validate:false with invalid data', function(done) {
User.findOrCreate(getNewWhere(), INVALID_DATA, { validate: false }, expectCreateSuccess(INVALID_DATA, done));
User.findOrCreate(
getNewWhere(),
INVALID_DATA,
{ validate: false },
expectCreateSuccess(INVALID_DATA, done)
);
});
it('should NOT throw on findOrCreate with validate:true with valid data', function(done) {
@ -480,20 +514,40 @@ describe('optional-validation', function() {
});
describe('method updateOrCreate on existing data', function() {
it('should throw on updateOrCreate(id) with validate:true with invalid data', function(done) {
callUpdateOrCreateWithExistingUserId(null, { validate: true }, expectValidationError(done));
it('should throw on updateOrCreate(id) with validate:true with invalid ' +
'data', function(done) {
callUpdateOrCreateWithExistingUserId(
null,
{ validate: true },
expectValidationError(done)
);
});
it('should NOT throw on updateOrCreate(id) with validate:false with invalid data', function(done) {
callUpdateOrCreateWithExistingUserId(null, { validate: false }, expectChangeSuccess(INVALID_DATA, done));
it('should NOT throw on updateOrCreate(id) with validate:false with ' +
'invalid data', function(done) {
callUpdateOrCreateWithExistingUserId(
null,
{ validate: false },
expectChangeSuccess(INVALID_DATA, done)
);
});
it('should NOT throw on updateOrCreate(id) with validate:true with valid data', function(done) {
callUpdateOrCreateWithExistingUserId(NEW_NAME, { validate: true }, expectChangeSuccess(done));
it('should NOT throw on updateOrCreate(id) with validate:true with ' +
'valid data', function(done) {
callUpdateOrCreateWithExistingUserId(
NEW_NAME,
{ validate: true },
expectChangeSuccess(done)
);
});
it('should NOT throw on updateOrCreate(id) with validate:false with valid data', function(done) {
callUpdateOrCreateWithExistingUserId(NEW_NAME, { validate: false }, expectChangeSuccess(done));
it('should NOT throw on updateOrCreate(id) with validate:false with ' +
'valid data', function(done) {
callUpdateOrCreateWithExistingUserId(
NEW_NAME,
{ validate: false },
expectChangeSuccess(done)
);
});
it('should throw on updateOrCreate(id) with invalid data', function(done) {
@ -501,7 +555,10 @@ describe('optional-validation', function() {
});
it('should NOT throw on updateOrCreate(id) with valid data', function(done) {
callUpdateOrCreateWithExistingUserId(NEW_NAME, expectChangeSuccess(done));
callUpdateOrCreateWithExistingUserId(
NEW_NAME,
expectChangeSuccess(done)
);
});
});
@ -542,7 +599,5 @@ describe('optional-validation', function() {
});
});
});
});
});

View File

@ -18,7 +18,8 @@ var HookMonitor = require('./helpers/hook-monitor');
module.exports = function(dataSource, should, connectorCapabilities) {
if (!connectorCapabilities) connectorCapabilities = {};
if (connectorCapabilities.replaceOrCreateReportsNewInstance === undefined) {
console.warn('The connector does not support a recently added feature: replaceOrCreateReportsNewInstance');
console.warn('The connector does not support a recently added feature: ' +
'replaceOrCreateReportsNewInstance');
}
describe('Persistence hooks', function() {
var ctxRecorder, hookMonitor, expectedError;
@ -319,7 +320,6 @@ module.exports = function(dataSource, should, connectorCapabilities) {
});
done();
});
});
});
@ -1564,7 +1564,7 @@ module.exports = function(dataSource, should, connectorCapabilities) {
name: 'changed',
id: data.id,
},
isNewInstance : false,
isNewInstance: false,
}));
done();
});
@ -2968,7 +2968,6 @@ module.exports = function(dataSource, should, connectorCapabilities) {
done();
});
});
});
function nextWithError(err) {

View File

@ -24,7 +24,6 @@ var getMemoryDataSource = function(settings) {
};
describe('relations', function() {
before(function() {
db = getSchema();
});
@ -63,7 +62,6 @@ describe('relations', function() {
});
describe('with scope', function() {
before(function(done) {
Book.hasMany(Chapter);
done();
@ -552,7 +550,6 @@ describe('relations', function() {
}).catch(done);
});
});
});
describe('hasMany through', function() {
@ -673,7 +670,6 @@ describe('relations', function() {
});
function verify(physician) {
physician.patients(function(err, ch) {
var patients = physician.patients();
patients.should.eql(ch);
@ -702,7 +698,6 @@ describe('relations', function() {
function verify(physician) {
return physician.patients.getAsync()
.then(function(ch) {
var patients = physician.patients();
patients.should.eql(ch);
@ -725,13 +720,13 @@ describe('relations', function() {
});
function verify(physician) {
//limit plus skip
physician.patients({ limit:1, skip:1 }, function(err, ch) {
physician.patients({ limit: 1, skip: 1 }, function(err, ch) {
should.not.exist(err);
should.exist(ch);
ch.should.have.lengthOf(1);
ch[0].name.should.eql('z');
//offset plus skip
physician.patients({ limit:1, offset:1 }, function(err1, ch1) {
physician.patients({ limit: 1, offset: 1 }, function(err1, ch1) {
should.not.exist(err1);
should.exist(ch1);
ch1.should.have.lengthOf(1);
@ -1123,7 +1118,6 @@ describe('relations', function() {
});
});
});
});
describe('hasMany through - collect', function() {
@ -1162,8 +1156,17 @@ describe('relations', function() {
describe('when custom reverse belongsTo names for both sides', function() {
it('can determine the collect via keyThrough', function() {
Physician.hasMany(Patient, { through: Appointment, foreignKey: 'fooId', keyThrough: 'barId' });
Patient.hasMany(Physician, { through: Appointment, foreignKey: 'barId', keyThrough: 'fooId', as: 'yyy' });
Physician.hasMany(Patient, {
through: Appointment,
foreignKey: 'fooId',
keyThrough: 'barId',
});
Patient.hasMany(Physician, {
through: Appointment,
foreignKey: 'barId',
keyThrough: 'fooId',
as: 'yyy',
});
Appointment.belongsTo(Physician, { as: 'foo' });
Appointment.belongsTo(Patient, { as: 'bar' });
Patient.belongsTo(Address); // jam.
@ -1217,7 +1220,6 @@ describe('relations', function() {
});
describe('when custom reverse belongsTo name for one side only', function() {
beforeEach(function() {
Physician.hasMany(Patient, { as: 'xxx', through: Appointment, foreignKey: 'fooId' });
Patient.hasMany(Physician, { as: 'yyy', through: Appointment, keyThrough: 'fooId' });
@ -1255,8 +1257,18 @@ describe('relations', function() {
} }});
Address = db.define('Address', { name: String });
User.hasMany(User, { as: 'followers', foreignKey: 'followeeId', keyThrough: 'followerId', through: Follow });
User.hasMany(User, { as: 'following', foreignKey: 'followerId', keyThrough: 'followeeId', through: Follow });
User.hasMany(User, {
as: 'followers',
foreignKey: 'followeeId',
keyThrough: 'followerId',
through: Follow,
});
User.hasMany(User, {
as: 'following',
foreignKey: 'followerId',
keyThrough: 'followeeId',
through: Follow,
});
User.belongsTo(Address);
Follow.belongsTo(User, { as: 'follower' });
Follow.belongsTo(User, { as: 'followee' });
@ -1302,8 +1314,18 @@ describe('relations', function() {
} }});
Address = db.define('Address', { name: String });
User.hasMany(User, { as: 'followers', foreignKey: 'followeeId', keyThrough: 'followerId', through: Follow });
User.hasMany(User, { as: 'following', foreignKey: 'followerId', keyThrough: 'followeeId', through: Follow });
User.hasMany(User, {
as: 'followers',
foreignKey: 'followeeId',
keyThrough: 'followerId',
through: Follow,
});
User.hasMany(User, {
as: 'following',
foreignKey: 'followerId',
keyThrough: 'followeeId',
through: Follow,
});
User.belongsTo(Address);
Follow.belongsTo(User, { as: 'follower' });
Follow.belongsTo(User, { as: 'followee' });
@ -1556,7 +1578,6 @@ describe('relations', function() {
});
});
});
});
describe('polymorphic hasOne', function() {
@ -1703,7 +1724,6 @@ describe('relations', function() {
});
});
});
});
describe('polymorphic hasOne with non standard ids', function() {
@ -2056,7 +2076,6 @@ describe('relations', function() {
done();
});
});
});
describe('polymorphic hasAndBelongsToMany through', function() {
@ -2203,7 +2222,12 @@ describe('relations', function() {
});
it('should create polymorphic through model', function(done) {
PictureLink.findOne({ where: { pictureId: anotherPicture.id, imageableType: 'Author' }}, function(err, link) {
PictureLink.findOne({
where: {
pictureId: anotherPicture.id,
imageableType: 'Author',
},
}, function(err, link) {
should.not.exist(err);
link.pictureId.should.eql(anotherPicture.id);
link.imageableId.should.eql(author.id);
@ -2339,7 +2363,6 @@ describe('relations', function() {
});
});
});
});
describe('belongsTo', function() {
@ -2549,7 +2572,6 @@ describe('relations', function() {
done();
}).catch(done);
});
});
describe('belongsTo with scope', function() {
@ -2621,7 +2643,6 @@ describe('relations', function() {
})
.catch(done);
});
});
// Disable the tests until the issue in
@ -2907,11 +2928,9 @@ describe('relations', function() {
done();
});
});
});
describe('hasOne with scope', function() {
var Supplier, Account;
var supplierId, accountId;
@ -3017,7 +3036,6 @@ describe('relations', function() {
})
.catch(done);
});
});
describe('hasOne with non standard id', function() {
@ -3104,7 +3122,6 @@ describe('relations', function() {
done();
});
});
});
describe('hasOne with primaryKey different from model PK', function() {
@ -3470,7 +3487,6 @@ describe('relations', function() {
});
describe('embedsOne', function() {
var person;
var Passport;
var Other;
@ -3480,7 +3496,7 @@ describe('relations', function() {
// db = getSchema();
Person = db.define('Person', { name: String });
Passport = tmp.define('Passport',
{ name:{ type:'string', required: true }},
{ name: { type: 'string', required: true }},
{ idInjection: false }
);
Address = tmp.define('Address', { street: String }, { idInjection: false });
@ -3762,7 +3778,6 @@ describe('relations', function() {
});
describe('embedsOne - persisted model', function() {
// This test spefically uses the Memory connector
// in order to test the use of the auto-generated
// id, in the sequence of the related model.
@ -3771,7 +3786,7 @@ describe('relations', function() {
db = getMemoryDataSource();
Person = db.define('Person', { name: String });
Passport = db.define('Passport',
{ name:{ type:'string', required: true }}
{ name: { type: 'string', required: true }}
);
});
@ -3783,7 +3798,7 @@ describe('relations', function() {
});
it('should create an item - to offset id', function(done) {
Passport.create({ name:'Wilma' }, function(err, p) {
Passport.create({ name: 'Wilma' }, function(err, p) {
should.not.exist(err);
p.id.should.equal(1);
p.name.should.equal('Wilma');
@ -3814,18 +3829,16 @@ describe('relations', function() {
});
}).catch(done);
});
});
describe('embedsOne - generated id', function() {
before(function() {
tmp = getTransientDataSource();
// db = getSchema();
Person = db.define('Person', { name: String });
Passport = tmp.define('Passport',
{ id: { type:'string', id: true, generated:true }},
{ name: { type:'string', required: true }}
{ id: { type: 'string', id: true, generated: true }},
{ name: { type: 'string', required: true }}
);
});
@ -3845,11 +3858,9 @@ describe('relations', function() {
});
});
});
});
describe('embedsMany', function() {
var address1, address2;
before(function(done) {
@ -4083,20 +4094,17 @@ describe('relations', function() {
done();
});
});
});
describe('embedsMany - numeric ids + forceId', function() {
before(function(done) {
tmp = getTransientDataSource();
// db = getSchema();
Person = db.define('Person', { name: String });
Address = tmp.define('Address', {
id: { type: Number, id:true },
id: { type: Number, id: true },
street: String,
});
db.automigrate(['Person'], done);
});
@ -4120,7 +4128,6 @@ describe('relations', function() {
});
});
});
});
describe('embedsMany - explicit ids', function() {
@ -4289,11 +4296,9 @@ describe('relations', function() {
});
});
});
});
describe('embedsMany - persisted model', function() {
var address0, address1, address2;
var person;
@ -4415,11 +4420,9 @@ describe('relations', function() {
});
});
});
});
describe('embedsMany - relations, scope and properties', function() {
var category, job1, job2, job3;
before(function() {
@ -4647,11 +4650,9 @@ describe('relations', function() {
done();
});
});
});
describe('embedsMany - polymorphic relations', function() {
var person1, person2;
before(function(done) {
@ -4757,7 +4758,6 @@ describe('relations', function() {
});
it('should include nested related items on scope', function(done) {
// There's some date duplication going on, so it might
// make sense to override toObject on a case-by-case basis
// to sort this out (delete links, keep people).
@ -4784,11 +4784,9 @@ describe('relations', function() {
done();
});
});
});
describe('referencesMany', function() {
var job1, job2, job3;
before(function(done) {
@ -5433,7 +5431,5 @@ describe('relations', function() {
})
.catch(done);
});
});
});

View File

@ -9,7 +9,6 @@ var should = require('./init.js');
var db = getSchema(), slave = getSchema(), Model, SlaveModel;
describe('dataSource', function() {
it('should define Model', function() {
Model = db.define('Model');
Model.dataSource.should.eql(db);
@ -58,5 +57,4 @@ describe('dataSource', function() {
});
});
});
});

View File

@ -9,7 +9,6 @@ var should = require('./init.js');
var db, Railway, Station;
describe('scope', function() {
before(function() {
db = getSchema();
Railway = db.define('Railway', {
@ -102,11 +101,9 @@ describe('scope', function() {
});
});
});
});
describe('scope - order', function() {
before(function() {
db = getSchema();
Station = db.define('Station', {
@ -155,11 +152,9 @@ describe('scope - order', function() {
done();
});
});
});
describe('scope - filtered count, updateAll and destroyAll', function() {
var stationA;
before(function() {
@ -325,7 +320,6 @@ describe('scope - filtered count, updateAll and destroyAll', function() {
});
};
});
});
describe('scope - dynamic target class', function() {
@ -410,25 +404,23 @@ describe('scope - dynamic target class', function() {
done();
});
});
});
describe('scope - dynamic function', function() {
var Item, seed = 0;
before(function() {
db = getSchema();
Item = db.define('Item', { title: Number, creator:Number });
Item = db.define('Item', { title: Number, creator: Number });
Item.scope('dynamicQuery', function() {
seed++;
return { where:{ creator:seed }};
return { where: { creator: seed }};
});
});
beforeEach(function(done) {
Item.create({ title:1, creator:1 }, function() {
Item.create({ title:2, creator:2 }, done);
Item.create({ title: 1, creator: 1 }, function() {
Item.create({ title: 2, creator: 2 }, done);
});
});

View File

@ -3,6 +3,8 @@
// This file is licensed under the MIT License.
// License text available at https://opensource.org/licenses/MIT
/* eslint-disable camelcase */
/*
if (!process.env.TRAVIS) {
var semicov = require('semicov');

View File

@ -16,7 +16,6 @@ var getTransientDataSource = function(settings) {
};
describe('Transient connector', function() {
before(function() {
db = getTransientDataSource();
TransientModel = db.define('TransientModel', {}, { idInjection: false });
@ -82,5 +81,4 @@ describe('Transient connector', function() {
});
});
});
});

View File

@ -24,7 +24,6 @@ describe('util.fieldsToArray', function() {
it('Turn objects and strings into an array of fields' +
' to include when finding models', function() {
sample(false).expect(undefined);
sample(null).expect(undefined);
sample({}).expect(undefined);
@ -37,7 +36,6 @@ describe('util.fieldsToArray', function() {
});
it('should exclude unknown properties', function() {
sample(false, true).expect(undefined);
sample(null, true).expect(undefined);
sample({}, true).expect(undefined);
@ -77,7 +75,6 @@ describe('util.removeUndefined', function() {
var q6 = { where: { x: 1, y: undefined }};
(function() { removeUndefined(q6, 'throw'); }).should.throw(/`undefined` in query/);
});
});
@ -94,7 +91,6 @@ describe('util.parseSettings', function() {
should.equal(settings.connector, 'mongodb');
should.equal(settings.w, '2');
should.equal(settings.url, 'mongodb://x:y@localhost:27017/mydb?w=2');
});
it('Parse a url without auth into a settings object', function() {
@ -109,7 +105,6 @@ describe('util.parseSettings', function() {
should.equal(settings.connector, 'mongodb');
should.equal(settings.w, '2');
should.equal(settings.url, 'mongodb://localhost:27017/mydb/abc?w=2');
});
it('Parse a url with complex query into a settings object', function() {
@ -126,7 +121,6 @@ describe('util.parseSettings', function() {
should.equal(settings.x.b, '2');
should.equal(settings.engine, 'InnoDB');
should.equal(settings.url, 'mysql://127.0.0.1:3306/mydb?x[a]=1&x[b]=2&engine=InnoDB');
});
it('Parse a url without auth into a settings object', function() {
@ -139,9 +133,7 @@ describe('util.parseSettings', function() {
should.equal(settings.connector, 'memory');
should.equal(settings.x, '1');
should.equal(settings.url, 'memory://?x=1');
});
});
describe('mergeSettings', function() {
@ -217,7 +209,6 @@ describe('mergeSettings', function() {
});
describe('sortObjectsByIds', function() {
var items = [
{ id: 1, name: 'a' },
{ id: 2, name: 'b' },
@ -244,11 +235,9 @@ describe('sortObjectsByIds', function() {
var names = sorted.map(function(u) { return u.name; });
should.deepEqual(names, ['e', 'c', 'b']);
});
});
describe('util.mergeIncludes', function() {
function checkInputOutput(baseInclude, updateInclude, expectedInclude) {
var mergedInclude = mergeIncludes(baseInclude, updateInclude);
should.deepEqual(mergedInclude, expectedInclude,
@ -390,7 +379,6 @@ describe('util.mergeIncludes', function() {
});
describe('util.uniq', function() {
it('should dedupe an array with duplicate number entries', function() {
var a = [1, 2, 1, 3];
var b = uniq(a);
@ -430,7 +418,6 @@ describe('util.uniq', function() {
err.should.be.instanceof(Error);
}
});
});
describe('util.toRegExp', function() {

View File

@ -23,7 +23,6 @@ function getValidAttributes() {
}
describe('validations', function() {
var User, Entry;
before(function(done) {
@ -61,9 +60,7 @@ describe('validations', function() {
});
describe('commons', function() {
describe('skipping', function() {
it('should NOT skip when `if` is fulfilled', function() {
User.validatesPresenceOf('pendingPeriod', { if: 'createdByAdmin' });
var user = new User;
@ -103,11 +100,9 @@ describe('validations', function() {
user.pendingPeriod = 1;
user.isValid().should.be.true;
});
});
describe('skipping in async validation', function() {
it('should skip when `if` is NOT fulfilled', function(done) {
User.validateAsync('pendingPeriod', function(err, done) {
if (!this.pendingPeriod) err();
@ -163,11 +158,9 @@ describe('validations', function() {
done();
});
});
});
describe('lifecycle', function() {
it('should work on create', function(done) {
delete User.validations;
User.validatesPresenceOf('name');
@ -280,7 +273,7 @@ describe('validations', function() {
});
it('should return validation metadata', function() {
var expected = { name:[{ validation: 'presence', options: {}}] };
var expected = { name: [{ validation: 'presence', options: {}}] };
delete User.validations;
User.validatesPresenceOf('name');
var validations = User.validations;
@ -290,7 +283,6 @@ describe('validations', function() {
});
describe('presence', function() {
it('should validate presence', function() {
User.validatesPresenceOf('name', 'email');
@ -337,11 +329,9 @@ describe('validations', function() {
user.domain = 'domain';
user.isValid().should.be.true;
});
});
describe('absence', function() {
it('should validate absence', function() {
User.validatesAbsenceOf('reserved', { if: 'locked' });
var u = new User({ reserved: 'foo', locked: true });
@ -351,7 +341,6 @@ describe('validations', function() {
var u = new User({ reserved: 'foo', locked: false });
u.isValid().should.be.true;
});
});
describe('uniqueness', function() {