Merge pull request #905 from strongloop/eslint-autofix-2x

Eslint autofix for 2.x
This commit is contained in:
Miroslav Bajtoš 2016-04-18 16:41:28 +02:00
commit feca7481e9
64 changed files with 4957 additions and 4960 deletions

View File

@ -17,23 +17,23 @@ var application = {
name: 'MyApp1',
description: 'My first app',
pushSettings: [
{ "platform": "apns",
"apns": {
"pushOptions": {
"gateway": "gateway.sandbox.push.apple.com",
"cert": "credentials/apns_cert_dev.pem",
"key": "credentials/apns_key_dev.pem"
{ 'platform': 'apns',
'apns': {
'pushOptions': {
'gateway': 'gateway.sandbox.push.apple.com',
'cert': 'credentials/apns_cert_dev.pem',
'key': 'credentials/apns_key_dev.pem',
},
"feedbackOptions": {
"gateway": "feedback.sandbox.push.apple.com",
"cert": "credentials/apns_cert_dev.pem",
"key": "credentials/apns_key_dev.pem",
"batchFeedback": true,
"interval": 300
}
}}
]}
'feedbackOptions': {
'gateway': 'feedback.sandbox.push.apple.com',
'cert': 'credentials/apns_cert_dev.pem',
'key': 'credentials/apns_key_dev.pem',
'batchFeedback': true,
'interval': 300,
},
}},
] };
console.log(new Application(application).toObject());
@ -55,14 +55,14 @@ var user = {
city: 'San Jose',
state: 'CA',
zipcode: '95131',
country: 'US'
country: 'US',
},
friends: ['John', 'Mary'],
emails: [
{ label: 'work', id: 'x@sample.com' },
{label: 'home', id: 'x@home.com'}
{ label: 'home', id: 'x@home.com' },
],
tags: []
tags: [],
};
// Introspect the JSON document to generate a schema

View File

@ -13,7 +13,7 @@ var Post = modelBuilder.define('Post', {
return new Date();
} },
timestamp: { type: Number, default: Date.now },
published: { type: Boolean, default: false, index: true }
published: { type: Boolean, default: false, index: true },
});
// simpler way to describe model
@ -22,7 +22,7 @@ var User = modelBuilder.define('User', {
bio: ModelBuilder.Text,
approved: Boolean,
joinedAt: Date,
age: Number
age: Number,
});
var Group = modelBuilder.define('Group', { group: String });

View File

@ -15,7 +15,7 @@ var Post = ds.define('Post', {
return new Date;
} },
timestamp: { type: Number, default: Date.now },
published: { type: Boolean, default: false, index: true }
published: { type: Boolean, default: false, index: true },
});
// simplier way to describe model
@ -24,7 +24,7 @@ var User = ds.define('User', {
bio: DataSource.Text,
approved: Boolean,
joinedAt: Date,
age: Number
age: Number,
});
var Group = ds.define('Group', { name: String });
@ -106,7 +106,7 @@ Article.create(function (e, article) {
var modelBuilder = new ModelBuilder();
Color = modelBuilder.define('Color', {
name: String
name: String,
});
// attach

View File

@ -23,7 +23,7 @@ setup(function () {
});
Passport.find({
include: {owner: {posts: 'author'}}
include: { owner: { posts: 'author' }},
}, function(err, passports) {
console.log('passports.owner.posts.author', passports);
});
@ -41,13 +41,13 @@ function setup(done) {
Building = db.define('Building');
User = db.define('User', {
name: String,
age: Number
age: Number,
});
Passport = db.define('Passport', {
number: String
number: String,
});
Post = db.define('Post', {
title: String
title: String,
});
Passport.belongsTo('owner', { model: User });
@ -68,7 +68,7 @@ function setup(done) {
{ name: 'User B', age: 22 },
{ name: 'User C', age: 23 },
{ name: 'User D', age: 24 },
{name: 'User E', age: 25}
{ name: 'User E', age: 25 },
],
function(items) {
createdUsers = items;
@ -83,7 +83,7 @@ function setup(done) {
[
{ number: '1', ownerId: createdUsers[0].id },
{ number: '2', ownerId: createdUsers[1].id },
{number: '3'}
{ number: '3' },
],
function(items) {
createdPassports = items;
@ -100,7 +100,7 @@ function setup(done) {
{ title: 'Post B', userId: createdUsers[0].id },
{ title: 'Post C', userId: createdUsers[0].id },
{ title: 'Post D', userId: createdUsers[1].id },
{title: 'Post E'}
{ title: 'Post E' },
],
function(items) {
createdPosts = items;

View File

@ -18,20 +18,20 @@ var User = modelBuilder.define('User', {
city: String,
state: String,
zipCode: String,
country: String
country: String,
},
emails: [
{
label: String,
email: String
}
email: String,
},
],
friends: [String]
friends: [String],
});
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'}
{ label: 'work', email: 'xyz@sample.com' },
],
friends: ['John', 'Mary'] });
console.log(user);

View File

@ -9,11 +9,11 @@ var ds = new DataSource('memory');
var Order = ds.createModel('Order', {
items: [String],
orderDate: Date,
qty: Number
qty: Number,
});
var Customer = ds.createModel('Customer', {
name: String
name: String,
});
Order.belongsTo(Customer);
@ -67,17 +67,17 @@ Customer.create({name: 'Ray'}, function (err, customer) {
});
var Physician = ds.createModel('Physician', {
name: String
name: String,
});
var Patient = ds.createModel('Patient', {
name: String
name: String,
});
var Appointment = ds.createModel('Appointment', {
physicianId: Number,
patientId: Number,
appointmentDate: Date
appointmentDate: Date,
});
Appointment.belongsTo(Patient);
@ -116,11 +116,11 @@ Physician.create({name: 'Dr John'}, function (err, physician1) {
});
var Assembly = ds.createModel('Assembly', {
name: String
name: String,
});
var Part = ds.createModel('Part', {
partNumber: String
partNumber: String,
});
Assembly.hasAndBelongsToMany(Part);

View File

@ -10,12 +10,12 @@ exports.GeoPoint = require('./lib/geo.js').GeoPoint;
exports.ValidationError = require('./lib/validations.js').ValidationError;
Object.defineProperty(exports, 'version', {
get: function() {return require('./package.json').version;}
get: function() { return require('./package.json').version; },
});
var commonTest = './test/common_test';
Object.defineProperty(exports, 'test', {
get: function() {return require(commonTest);}
get: function() { return require(commonTest); },
});
exports.Transaction = require('loopback-connector').Transaction;

View File

@ -81,12 +81,12 @@ Memory.prototype.getCollection = function(model) {
model = modelClass.settings.memory.collection || model;
}
return model;
}
};
Memory.prototype.initCollection = function(model) {
this.collection(model, {});
this.collectionSeq(model, 1);
}
};
Memory.prototype.collection = function(model, val) {
model = this.getCollection(model);
@ -157,7 +157,7 @@ Memory.prototype.saveToFile = function (result, callback) {
// Flush out the models/ids
var data = JSON.stringify({
ids: self.ids,
models: self.cache
models: self.cache,
}, null, ' ');
fs.writeFile(self.settings.file, data, function(err) {
@ -169,13 +169,13 @@ Memory.prototype.saveToFile = function (result, callback) {
// Enqueue the write
self.writeQueue.push({
data: result,
callback: callback
callback: callback,
});
} else if (localStorage) {
// Flush out the models/ids
var data = JSON.stringify({
ids: self.ids,
models: self.cache
models: self.cache,
}, null, ' ');
window.localStorage.setItem(localStorage, data);
process.nextTick(function() {
@ -371,7 +371,7 @@ Memory.prototype._findAllSkippingIncludes = function(model, filter) {
// do we need some sorting?
if (filter.order) {
var orders = filter.order;
if (typeof filter.order === "string") {
if (typeof filter.order === 'string') {
orders = [filter.order];
}
orders.forEach(function(key, i) {
@ -381,7 +381,7 @@ Memory.prototype._findAllSkippingIncludes = function(model, filter) {
key = key.replace(/\s+(A|DE)SC/i, '');
if (m[1].toLowerCase() === 'de') reverse = -1;
}
orders[i] = {"key": key, "reverse": reverse};
orders[i] = { 'key': key, 'reverse': reverse };
});
nodes = nodes.sort(sorting.bind(orders));
}
@ -500,7 +500,7 @@ function applyFilter(filter) {
return false;
});
}
};
function toRegExp(pattern) {
if (pattern instanceof RegExp) {
@ -509,7 +509,7 @@ function applyFilter(filter) {
var regex = '';
// Escaping user input to be treated as a literal string within a regular expression
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions#Writing_a_Regular_Expression_Pattern
pattern = pattern.replace(/([.*+?^=!:${}()|\[\]\/\\])/g, "\\$1");
pattern = pattern.replace(/([.*+?^=!:${}()|\[\]\/\\])/g, '\\$1');
for (var i = 0, n = pattern.length; i < n; i++) {
var char = pattern.charAt(i);
if (char === '\\') {
@ -526,8 +526,7 @@ function applyFilter(filter) {
regex += '\\.';
} else if (char === '*') {
regex += '\\*';
}
else {
} else {
regex += char;
}
}
@ -573,7 +572,6 @@ function applyFilter(filter) {
}
if (example.like || example.nlike) {
var like = example.like || example.nlike;
if (typeof like === 'string') {
like = toRegExp(like);
@ -592,8 +590,8 @@ function applyFilter(filter) {
}
}
// not strict equality
return (example !== null ? example.toString() : example)
== (value != null ? value.toString() : value);
return (example !== null ? example.toString() : example) ==
(value != null ? value.toString() : value);
}
/**
@ -797,7 +795,7 @@ Memory.prototype.exec = function (callback) {
Memory.prototype.buildNearFilter = function(filter) {
// noop
}
};
Memory.prototype.automigrate = function(models, cb) {
var self = this;
@ -831,7 +829,7 @@ Memory.prototype.automigrate = function (models, cb) {
self.initCollection(m);
});
if (cb) process.nextTick(cb);
}
};
function merge(base, update) {
if (!base) {

View File

@ -177,7 +177,7 @@ DataAccessObject.lookupModel = function(data) {
*/
DataAccessObject.getConnector = function() {
return this.getDataSource().connector;
}
};
// Empty callback function
function noCallback(err, result) {
@ -296,7 +296,7 @@ DataAccessObject.create = function (data, options, cb) {
instance: obj,
isNewInstance: true,
hookState: hookState,
options: options
options: options,
};
Model.notifyObserversOf('before save', context, function(err) {
if (err) return cb(err);
@ -347,7 +347,7 @@ DataAccessObject.create = function (data, options, cb) {
data: val,
isNewInstance: true,
hookState: hookState,
options: options
options: options,
};
Model.notifyObserversOf('loaded', context, function(err) {
if (err) return cb(err);
@ -369,7 +369,7 @@ DataAccessObject.create = function (data, options, cb) {
instance: obj,
isNewInstance: true,
hookState: hookState,
options: options
options: options,
};
Model.notifyObserversOf('after save', context, function(err) {
@ -387,7 +387,7 @@ DataAccessObject.create = function (data, options, cb) {
isNewInstance: true,
currentInstance: obj,
hookState: hookState,
options: options
options: options,
};
Model.notifyObserversOf('persist', context, function(err) {
if (err) return cb(err);
@ -415,7 +415,7 @@ function stillConnecting(dataSource, obj, args) {
// promise variant
var promiseArgs = Array.prototype.slice.call(args);
promiseArgs.callee = args.callee
promiseArgs.callee = args.callee;
var cb = utils.createPromiseCallback();
promiseArgs.push(cb);
if (dataSource.ready(obj, promiseArgs)) {
@ -483,21 +483,21 @@ DataAccessObject.upsert = function(data, options, cb) {
Model: Model,
query: byIdQuery(Model, id),
hookState: hookState,
options: options
options: options,
};
Model.notifyObserversOf('access', context, doUpdateOrCreate);
function doUpdateOrCreate(err, ctx) {
if (err) return cb(err);
var isOriginalQuery = isWhereByGivenId(Model, ctx.query.where, id)
var isOriginalQuery = isWhereByGivenId(Model, ctx.query.where, id);
if (connector.updateOrCreate && isOriginalQuery) {
var context = {
Model: Model,
where: ctx.query.where,
data: data,
hookState: hookState,
options: options
options: options,
};
Model.notifyObserversOf('before save', context, function(err, ctx) {
if (err) return cb(err);
@ -522,7 +522,7 @@ DataAccessObject.upsert = function(data, options, cb) {
doValidate = Model.settings.automaticValidation;
}
} else {
doValidate = Model.settings.validateUpsert
doValidate = Model.settings.validateUpsert;
}
} else {
doValidate = options.validate;
@ -554,7 +554,7 @@ DataAccessObject.upsert = function(data, options, cb) {
data: update,
currentInstance: inst,
hookState: ctx.hookState,
options: options
options: options,
};
Model.notifyObserversOf('persist', context, function(err) {
if (err) return done(err);
@ -570,7 +570,7 @@ DataAccessObject.upsert = function(data, options, cb) {
Model: Model,
data: data,
hookState: ctx.hookState,
options: options
options: options,
};
Model.notifyObserversOf('loaded', context, function(err) {
if (err) return cb(err);
@ -593,7 +593,7 @@ DataAccessObject.upsert = function(data, options, cb) {
instance: obj,
isNewInstance: info ? info.isNewInstance : undefined,
hookState: hookState,
options: options
options: options,
};
Model.notifyObserversOf('after save', context, function(err) {
@ -687,7 +687,7 @@ DataAccessObject.replaceOrCreate = function replaceOrCreate(data, options, cb) {
Model: Model,
query: byIdQuery(Model, id),
hookState: hookState,
options: options
options: options,
};
Model.notifyObserversOf('access', context, doReplaceOrCreate);
@ -701,7 +701,7 @@ DataAccessObject.replaceOrCreate = function replaceOrCreate(data, options, cb) {
Model: Model,
instance: inst,
hookState: hookState,
options: options
options: options,
};
Model.notifyObserversOf('before save', context, function(err, ctx) {
if (err) return cb(err);
@ -741,7 +741,7 @@ DataAccessObject.replaceOrCreate = function replaceOrCreate(data, options, cb) {
data: update,
currentInstance: inst,
hookState: ctx.hookState,
options: options
options: options,
};
Model.notifyObserversOf('persist', context, function(err) {
if (err) return done(err);
@ -755,7 +755,7 @@ DataAccessObject.replaceOrCreate = function replaceOrCreate(data, options, cb) {
data: data,
isNewInstance: info ? info.isNewInstance : undefined,
hookState: ctx.hookState,
options: options
options: options,
};
Model.notifyObserversOf('loaded', context, function(err) {
if (err) return cb(err);
@ -775,7 +775,7 @@ DataAccessObject.replaceOrCreate = function replaceOrCreate(data, options, cb) {
instance: obj,
isNewInstance: info ? info.isNewInstance : undefined,
hookState: hookState,
options: options
options: options,
};
Model.notifyObserversOf('after save', context, function(err) {
@ -879,7 +879,7 @@ DataAccessObject.findOrCreate = function findOrCreate(query, data, options, cb)
data: data,
isNewInstance: created,
hookState: hookState,
options: options
options: options,
};
Model.notifyObserversOf('loaded', context, function(err) {
if (err) return cb(err);
@ -897,7 +897,7 @@ DataAccessObject.findOrCreate = function findOrCreate(query, data, options, cb)
instance: obj,
isNewInstance: true,
hookState: hookState,
options: options
options: options,
};
Model.notifyObserversOf('after save', context, function(err) {
if (cb.promise) {
@ -926,7 +926,7 @@ DataAccessObject.findOrCreate = function findOrCreate(query, data, options, cb)
isNewInstance: true,
currentInstance : currentInstance,
hookState: hookState,
options: options
options: options,
};
Model.notifyObserversOf('persist', context, function(err) {
@ -958,7 +958,7 @@ DataAccessObject.findOrCreate = function findOrCreate(query, data, options, cb)
Model: Model,
query: query,
hookState: hookState,
options: options
options: options,
};
Model.notifyObserversOf('access', context, function(err, ctx) {
if (err) return cb(err);
@ -977,7 +977,7 @@ DataAccessObject.findOrCreate = function findOrCreate(query, data, options, cb)
instance: obj,
isNewInstance: true,
hookState: hookState,
options: options
options: options,
};
Model.notifyObserversOf('before save', context, function(err, ctx) {
if (err) return cb(err);
@ -1216,7 +1216,7 @@ DataAccessObject._getSetting = function(key) {
// Check for settings in model
var m = this.definition;
if (m && m.settings && m.settings[key]) {
return m.settings[key]
return m.settings[key];
}
// Check for settings in connector
@ -1239,7 +1239,7 @@ var operators = {
neq: '!=',
like: 'LIKE',
nlike: 'NOT LIKE',
regexp: 'REGEXP'
regexp: 'REGEXP',
};
/*
@ -1636,7 +1636,7 @@ DataAccessObject.find = function find(query, options, cb) {
Model: self,
query: query,
hookState: hookState,
options: options
options: options,
};
self.notifyObserversOf('access', context, function(err, ctx) {
if (err) return cb(err);
@ -1651,7 +1651,7 @@ DataAccessObject.find = function find(query, options, cb) {
memory.define({
properties: self.dataSource.definitions[self.modelName].properties,
settings: self.dataSource.definitions[self.modelName].settings,
model: self
model: self,
});
data.forEach(function(obj) {
@ -1723,7 +1723,7 @@ DataAccessObject.find = function find(query, options, cb) {
instance: obj,
isNewInstance: false,
hookState: hookState,
options: options
options: options,
};
Model.notifyObserversOf('loaded', context, function(err) {
@ -1765,7 +1765,7 @@ DataAccessObject.find = function find(query, options, cb) {
Model: this,
query: query,
hookState: hookState,
options: options
options: options,
};
this.notifyObserversOf('access', context, function(err, ctx) {
if (err) return cb(err);
@ -1876,7 +1876,7 @@ DataAccessObject.remove = DataAccessObject.deleteAll = DataAccessObject.destroyA
Model: Model,
where: whereIsEmpty(where) ? {} : where,
hookState: hookState,
options: options
options: options,
};
if (options.notify === false) {
@ -1887,7 +1887,7 @@ DataAccessObject.remove = DataAccessObject.deleteAll = DataAccessObject.destroyA
Model: Model,
query: query,
hookState: hookState,
options: options
options: options,
};
Model.notifyObserversOf('access', context, function(err, ctx) {
if (err) return cb(err);
@ -1895,7 +1895,7 @@ DataAccessObject.remove = DataAccessObject.deleteAll = DataAccessObject.destroyA
Model: Model,
where: ctx.query.where,
hookState: hookState,
options: options
options: options,
};
Model.notifyObserversOf('before delete', context, function(err, ctx) {
if (err) return cb(err);
@ -1941,7 +1941,7 @@ DataAccessObject.remove = DataAccessObject.deleteAll = DataAccessObject.destroyA
Model: Model,
where: where,
hookState: hookState,
options: options
options: options,
};
Model.notifyObserversOf('after delete', context, function(err) {
cb(err, info);
@ -1955,7 +1955,7 @@ DataAccessObject.remove = DataAccessObject.deleteAll = DataAccessObject.destroyA
function whereIsEmpty(where) {
return !where ||
(typeof where === 'object' && Object.keys(where).length === 0)
(typeof where === 'object' && Object.keys(where).length === 0);
}
/**
@ -2085,7 +2085,7 @@ DataAccessObject.count = function (where, options, cb) {
Model: Model,
query: { where: where },
hookState: hookState,
options: options
options: options,
};
this.notifyObserversOf('access', context, function(err, ctx) {
if (err) return cb(err);
@ -2158,7 +2158,7 @@ DataAccessObject.prototype.save = function (options, cb) {
Model: Model,
instance: inst,
hookState: hookState,
options: options
options: options,
};
Model.notifyObserversOf('before save', context, function(err) {
if (err) return cb(err);
@ -2200,7 +2200,7 @@ DataAccessObject.prototype.save = function (options, cb) {
data: data,
isNewInstance: result && result.isNewInstance,
hookState: hookState,
options: options
options: options,
};
Model.notifyObserversOf('loaded', context, function(err) {
if (err) return cb(err);
@ -2212,7 +2212,7 @@ DataAccessObject.prototype.save = function (options, cb) {
instance: inst,
isNewInstance: result && result.isNewInstance,
hookState: hookState,
options: options
options: options,
};
Model.notifyObserversOf('after save', context, function(err) {
if (err) return cb(err, inst);
@ -2234,7 +2234,7 @@ DataAccessObject.prototype.save = function (options, cb) {
where: byIdQuery(Model, getIdValue(Model, inst)).where,
currentInstance: inst,
hookState: hookState,
options: options
options: options,
};
Model.notifyObserversOf('persist', context, function(err) {
@ -2328,7 +2328,7 @@ DataAccessObject.updateAll = function (where, data, options, cb) {
Model: Model,
query: { where: where },
hookState: hookState,
options: options
options: options,
};
Model.notifyObserversOf('access', context, function(err, ctx) {
if (err) return cb(err);
@ -2337,7 +2337,7 @@ DataAccessObject.updateAll = function (where, data, options, cb) {
where: ctx.query.where,
data: data,
hookState: hookState,
options: options
options: options,
};
Model.notifyObserversOf('before save', context,
function(err, ctx) {
@ -2366,7 +2366,7 @@ DataAccessObject.updateAll = function (where, data, options, cb) {
where: where,
data: data,
hookState: hookState,
options: options
options: options,
};
Model.notifyObserversOf('after save', context, function(err, ctx) {
return cb(err, info);
@ -2378,7 +2378,7 @@ DataAccessObject.updateAll = function (where, data, options, cb) {
where: where,
data: data,
hookState: hookState,
options: options
options: options,
};
Model.notifyObserversOf('persist', context, function(err, ctx) {
if (err) return cb (err);
@ -2446,7 +2446,7 @@ DataAccessObject.prototype.remove =
Model: Model,
query: byIdQuery(Model, id),
hookState: hookState,
options: options
options: options,
};
Model.notifyObserversOf('access', context, function(err, ctx) {
@ -2456,7 +2456,7 @@ DataAccessObject.prototype.remove =
where: ctx.query.where,
instance: inst,
hookState: hookState,
options: options
options: options,
};
Model.notifyObserversOf('before delete', context, function(err, ctx) {
if (err) return cb(err);
@ -2483,7 +2483,7 @@ DataAccessObject.prototype.remove =
where: where,
instance: inst,
hookState: hookState,
options: options
options: options,
};
Model.notifyObserversOf('after delete', context, function(err) {
cb(err, info);
@ -2510,7 +2510,7 @@ DataAccessObject.prototype.remove =
where: where,
instance: inst,
hookState: hookState,
options: options
options: options,
};
Model.notifyObserversOf('after delete', context, function(err) {
cb(err, info);
@ -2656,7 +2656,7 @@ DataAccessObject.replaceById = function(id, data, options, cb) {
instance: inst,
isNewInstance: false,
hookState: hookState,
options: options
options: options,
};
Model.notifyObserversOf('before save', context, function(err, ctx) {
@ -2715,7 +2715,7 @@ DataAccessObject.replaceById = function(id, data, options, cb) {
hookState: hookState,
data: context.data,
isNewInstance:false,
options: options
options: options,
};
Model.notifyObserversOf('loaded', ctx, function(err) {
if (err) return cb(err);
@ -2728,7 +2728,7 @@ DataAccessObject.replaceById = function(id, data, options, cb) {
instance: inst,
isNewInstance: false,
hookState: hookState,
options: options
options: options,
};
Model.notifyObserversOf('after save', context, function(err) {
if (!err) Model.emit('changed', inst);
@ -2745,7 +2745,7 @@ DataAccessObject.replaceById = function(id, data, options, cb) {
isNewInstance:false,
currentInstance: inst,
hookState: hookState,
options: options
options: options,
};
Model.notifyObserversOf('persist', ctx, function(err) {
connector.replaceById(model, id,
@ -2841,7 +2841,7 @@ function(data, options, cb) {
data: data,
currentInstance: inst,
hookState: hookState,
options: options
options: options,
};
Model.notifyObserversOf('before save', context, function(err, ctx) {
@ -2895,7 +2895,7 @@ function(data, options, cb) {
Model: Model,
data: context.data,
hookState: hookState,
options: options
options: options,
};
Model.notifyObserversOf('loaded', ctx, function(err) {
if (err) return cb(err);
@ -2918,7 +2918,7 @@ function(data, options, cb) {
instance: inst,
isNewInstance: false,
hookState: hookState,
options: options
options: options,
};
Model.notifyObserversOf('after save', context, function(err) {
if (!err) Model.emit('changed', inst);
@ -2936,7 +2936,7 @@ function(data, options, cb) {
currentInstance: inst,
isNewInstance: false,
hookState: hookState,
options: options
options: options,
};
Model.notifyObserversOf('persist', ctx, function(err) {
if (connector.updateAttributes.length === 5) {
@ -2984,7 +2984,7 @@ function defineReadonlyProp(obj, key, value) {
writable: false,
enumerable: true,
configurable: true,
value: value
value: value,
});
}

View File

@ -135,7 +135,7 @@ function DataSource(name, settings, modelBuilder) {
http: fn.http,
remoteEnabled: fn.shared ? true : false,
scope: this.DataAccessObject,
fnName: name
fnName: name,
});
}
}.bind(this));
@ -152,7 +152,7 @@ function DataSource(name, settings, modelBuilder) {
http: fn.http,
remoteEnabled: fn.shared ? true : false,
scope: this.DataAccessObject.prototype,
fnName: name
fnName: name,
});
}
}.bind(this));
@ -244,7 +244,7 @@ DataSource._resolveConnector = function (name, loader) {
}
return {
connector: connector,
error: error
error: error,
};
};
@ -455,7 +455,7 @@ DataSource.prototype.defineRelations = function (modelClass, relations) {
if (relations) {
Object.keys(relations).forEach(function(rn) {
var r = relations[rn];
assert(DataSource.relationTypes.indexOf(r.type) !== -1, "Invalid relation type: " + r.type);
assert(DataSource.relationTypes.indexOf(r.type) !== -1, 'Invalid relation type: ' + r.type);
var targetModel, polymorphicName;
if (r.polymorphic && r.type !== 'belongsTo' && !r.model) {
@ -523,7 +523,7 @@ DataSource.prototype.setupDataAccess = function (modelClass, settings) {
this.connector.define({
model: modelClass,
properties: modelClass.definition.properties,
settings: settings
settings: settings,
});
}
}
@ -665,7 +665,7 @@ DataSource.prototype.mixin = function (ModelCtor) {
return ~[
'scope',
'fnName',
'prototype'
'prototype',
].indexOf(key);
})
.forEach(function(key) {
@ -1337,14 +1337,14 @@ DataSource.prototype.discoverSchemas = function (modelName, options, cb) {
var schema = {
name: nameMapper('table', modelName),
options: {
idInjection: false // DO NOT add id property
idInjection: false, // DO NOT add id property
},
properties: {}
properties: {},
};
schema.options[dbType] = {
schema: columns[0].owner,
table: modelName
table: modelName,
};
columns.forEach(function(item) {
@ -1357,7 +1357,7 @@ DataSource.prototype.discoverSchemas = function (modelName, options, cb) {
|| item.nullable === 0 || item.nullable === false),
length: item.dataLength,
precision: item.dataPrecision,
scale: item.dataScale
scale: item.dataScale,
};
if (pks[item.columnName]) {
@ -1369,7 +1369,7 @@ DataSource.prototype.discoverSchemas = function (modelName, options, cb) {
dataLength: i.dataLength,
dataPrecision: item.dataPrecision,
dataScale: item.dataScale,
nullable: i.nullable
nullable: i.nullable,
};
});
@ -1393,7 +1393,7 @@ DataSource.prototype.discoverSchemas = function (modelName, options, cb) {
keySeq: fk.keySeq,
owner: fk.pkOwner,
tableName: fk.pkTableName,
columnName: fk.pkColumnName
columnName: fk.pkColumnName,
};
if (fks[fk.fkName]) {
fks[fk.fkName].push(fkInfo);
@ -1412,7 +1412,7 @@ DataSource.prototype.discoverSchemas = function (modelName, options, cb) {
schema.options.relations[propName] = {
model: nameMapper('table', fk.pkTableName),
type: 'belongsTo',
foreignKey: nameMapper('column', fk.fkColumnName)
foreignKey: nameMapper('column', fk.fkColumnName),
};
var key = fk.pkOwner + '.' + fk.pkTableName;
@ -1488,14 +1488,14 @@ DataSource.prototype.discoverSchemasSync = function (modelName, options) {
var schema = {
name: nameMapper('table', modelName),
options: {
idInjection: false // DO NOT add id property
idInjection: false, // DO NOT add id property
},
properties: {}
properties: {},
};
schema.options[dbType] = {
schema: columns.length > 0 && columns[0].owner,
table: modelName
table: modelName,
};
columns.forEach(function(item) {
@ -1507,7 +1507,7 @@ DataSource.prototype.discoverSchemasSync = function (modelName, options) {
required: (item.nullable === 'N'),
length: item.dataLength,
precision: item.dataPrecision,
scale: item.dataScale
scale: item.dataScale,
};
if (pks[item.columnName]) {
@ -1519,7 +1519,7 @@ DataSource.prototype.discoverSchemasSync = function (modelName, options) {
dataLength: i.dataLength,
dataPrecision: item.dataPrecision,
dataScale: item.dataScale,
nullable: i.nullable
nullable: i.nullable,
};
});
@ -1544,7 +1544,7 @@ DataSource.prototype.discoverSchemasSync = function (modelName, options) {
keySeq: fk.keySeq,
owner: fk.pkOwner,
tableName: fk.pkTableName,
columnName: fk.pkColumnName
columnName: fk.pkColumnName,
};
if (fks[fk.fkName]) {
fks[fk.fkName].push(fkInfo);
@ -1563,7 +1563,7 @@ DataSource.prototype.discoverSchemasSync = function (modelName, options) {
schema.options.relations[propName] = {
model: nameMapper('table', fk.pkTableName),
type: 'belongsTo',
foreignKey: nameMapper('column', fk.fkColumnName)
foreignKey: nameMapper('column', fk.fkColumnName),
};
var key = fk.pkOwner + '.' + fk.pkTableName;
@ -1914,7 +1914,7 @@ DataSource.prototype.copyModel = function copyModel(Master) {
dataSource.connector.define({
model: Slave,
properties: md.properties,
settings: md.settings
settings: md.settings,
});
}
@ -1973,7 +1973,7 @@ DataSource.prototype.enableRemote = function (operation) {
} else {
throw new Error(operation + ' is not provided by the attached connector');
}
}
};
/**
* Disable remote access to a data source operation. Each [connector](#connector) has its own set of set enabled
@ -2002,7 +2002,7 @@ DataSource.prototype.disableRemote = function (operation) {
} else {
throw new Error(operation + ' is not provided by the attached connector');
}
}
};
/**
* Get an operation's metadata.
@ -2020,7 +2020,7 @@ DataSource.prototype.getOperation = function (operation) {
return op;
}
}
}
};
/**
* Return JSON object describing all operations.
@ -2047,7 +2047,7 @@ DataSource.prototype.getOperation = function (operation) {
*/
DataSource.prototype.operations = function() {
return this._operations;
}
};
/**
* Define an operation to the data source
@ -2171,7 +2171,7 @@ function hiddenProperty(obj, key, value) {
writable: false,
enumerable: false,
configurable: false,
value: value
value: value,
});
}
@ -2187,7 +2187,7 @@ function defineReadonlyProp(obj, key, value) {
writable: false,
enumerable: true,
configurable: true,
value: value
value: value,
});
}

View File

@ -21,14 +21,14 @@ exports.nearFilter = function nearFilter(where) {
near: ex.near,
maxDistance: ex.maxDistance,
unit: ex.unit,
key: key
key: key,
};
}
});
}
return result;
}
};
/*!
* Filter a set of objects using the given `nearFilter`.
@ -81,7 +81,7 @@ exports.filter = function (arr, filter) {
return 0;
}
});
}
};
exports.GeoPoint = GeoPoint;
@ -134,7 +134,7 @@ function GeoPoint(data) {
if (arguments.length === 2) {
data = {
lat: arguments[0],
lng: arguments[1]
lng: arguments[1],
};
}
@ -147,7 +147,7 @@ function GeoPoint(data) {
if (Array.isArray(data)) {
data = {
lat: Number(data[0]),
lng: Number(data[1])
lng: Number(data[1]),
};
} else {
data.lng = Number(data.lng);
@ -255,7 +255,7 @@ var EARTH_RADIUS = {
miles: 3958.75,
feet: 20902200,
radians: 1,
degrees: RAD2DEG
degrees: RAD2DEG,
};
function geoDistance(x1, y1, x2, y2, options) {

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

@ -321,10 +321,10 @@ Inclusion.include = function (objects, include, options, cb) {
//default filters are not applicable on through model. should be applied
//on modelTo later in 2nd DB call.
var throughFilter = {
where: {}
where: {},
};
throughFilter.where[relation.keyTo] = {
inq: uniq(sourceIds)
inq: uniq(sourceIds),
};
if (polymorphic) {
//handle polymorphic hasMany (reverse) in which case we need to filter
@ -367,7 +367,7 @@ Inclusion.include = function (objects, include, options, cb) {
//Polymorphic relation does not have idKey of modelTo. Find it manually
var modelToIdName = idName(relation.modelTo);
filter.where[modelToIdName] = {
inq: uniq(targetIds)
inq: uniq(targetIds),
};
//make sure that the modelToIdName is included if fields are specified
@ -450,7 +450,7 @@ Inclusion.include = function (objects, include, options, cb) {
obj.__cachedRelations[relationName] = [];
}
filter.where[relation.keyTo] = {
inq: uniq(allTargetIds)
inq: uniq(allTargetIds),
};
relation.applyScope(null, filter);
/**
@ -503,7 +503,7 @@ Inclusion.include = function (objects, include, options, cb) {
var objIdMap2 = includeUtils.buildOneToOneIdentityMapWithOrigKeys(objs, relation.keyFrom);
filter.where[relation.keyTo] = {
inq: uniq(objIdMap2.getKeys())
inq: uniq(objIdMap2.getKeys()),
};
relation.applyScope(null, filter);
@ -545,7 +545,7 @@ Inclusion.include = function (objects, include, options, cb) {
obj.__cachedRelations[relationName] = [];
}
filter.where[relation.keyTo] = {
inq: uniq(sourceIds)
inq: uniq(sourceIds),
};
relation.applyScope(null, filter);
options.partitionBy = relation.keyTo;
@ -648,7 +648,7 @@ Inclusion.include = function (objects, include, options, cb) {
utils.mergeQuery(typeFilter, filter);
var targetIds = targetIdsByType[modelType];
typeFilter.where[relation.keyTo] = {
inq: uniq(targetIds)
inq: uniq(targetIds),
};
var Model = lookupModel(relation.modelFrom.dataSource.modelBuilder.
models, modelType);
@ -720,7 +720,7 @@ Inclusion.include = function (objects, include, options, cb) {
obj.__cachedRelations[relationName] = null;
}
filter.where[relation.keyTo] = {
inq: uniq(sourceIds)
inq: uniq(sourceIds),
};
relation.applyScope(null, filter);
relation.modelTo.find(filter, options, targetFetchHandler);
@ -787,7 +787,7 @@ Inclusion.include = function (objects, include, options, cb) {
obj.__cachedRelations[relationName] = null;
}
filter.where[relation.keyTo] = {
inq: uniq(targetIds)
inq: uniq(targetIds),
};
relation.applyScope(null, filter);
relation.modelTo.find(filter, options, targetFetchHandler);

View File

@ -66,7 +66,7 @@ function KVMap(){
var _originalKeyFieldName = 'originalKey';
var _valueKeyFieldName = 'value';
var _dict = {};
var keyToString = function(key){ return key.toString() };
var keyToString = function(key) { return key.toString(); };
var mapImpl = {
set: function(key, value) {
var recordObj = {};
@ -97,7 +97,7 @@ function KVMap(){
result.push(_dict[key][_originalKeyFieldName]);
}
return result;
}
},
};
return mapImpl;

View File

@ -62,6 +62,6 @@ module.exports = function getIntrospector(ModelBuilder) {
ModelBuilder.introspect = introspectType;
return introspectType;
}
};

View File

@ -15,7 +15,7 @@ exports.inherits = function (newClass, baseClass, options) {
options = options || {
staticProperties: true,
override: false
override: false,
};
if (options.staticProperties) {
@ -49,7 +49,7 @@ exports.mixin = function (newClass, mixinClass, options) {
staticProperties: true,
instanceProperties: true,
override: false,
proxyFunctions: false
proxyFunctions: false,
};
if (options.staticProperties === undefined) {

View File

@ -49,14 +49,14 @@ function List(items, itemType, parent) {
Object.defineProperty(arr, 'itemType', {
writable: true,
enumerable: false,
value: itemType
value: itemType,
});
if (parent) {
Object.defineProperty(arr, 'parent', {
writable: true,
enumerable: false,
value: parent
value: parent,
});
}

View File

@ -302,7 +302,7 @@ ModelBuilder.prototype.define = function defineClass(className, properties, sett
return this.__data[idProp];
},
configurable: true,
enumerable: false
enumerable: false,
});
}
} else {
@ -318,7 +318,7 @@ ModelBuilder.prototype.define = function defineClass(className, properties, sett
return compositeId;
},
configurable: true,
enumerable: false
enumerable: false,
});
}
@ -474,7 +474,7 @@ ModelBuilder.prototype.define = function defineClass(className, properties, sett
}
},
configurable: true,
enumerable: true
enumerable: true,
});
// FIXME: [rfeng] Do we need to keep the raw data?
@ -490,7 +490,7 @@ ModelBuilder.prototype.define = function defineClass(className, properties, sett
this.__data[propertyName] = value;
},
configurable: true,
enumerable: false
enumerable: false,
});
};
@ -638,7 +638,7 @@ ModelBuilder.prototype.copyModel = function copyModel(Master) {
modelBuilder.models[className] = Slave;
modelBuilder.definitions[className] = {
properties: md.properties,
settings: md.settings
settings: md.settings,
};
}
@ -653,7 +653,7 @@ function hiddenProperty(where, property, value) {
writable: true,
enumerable: false,
configurable: true,
value: value
value: value,
});
}
@ -740,8 +740,8 @@ ModelBuilder.prototype.buildModels = function (schemas, createModel) {
{
name: this.getSchemaName(),
properties: schemas,
options: {anonymous: true}
}
options: { anonymous: true },
},
];
}
}

View File

@ -229,11 +229,11 @@ ModelDefinition.prototype.build = function (forceRebuild) {
source: this.name,
target: type,
type: Array.isArray(prop) ? 'hasMany' : 'belongsTo',
as: p
as: p,
});
} else {
var typeDef = {
type: type
type: type,
};
if (typeof prop === 'object' && prop !== null) {
for (var a in prop) {
@ -276,7 +276,7 @@ ModelDefinition.prototype.toJSON = function (forceRebuild) {
var json = {
name: this.name,
properties: {},
settings: this.settings
settings: this.settings,
};
this.build(forceRebuild);

View File

@ -31,7 +31,7 @@ var BASE_TYPES = {
'Number': true,
'Date': true,
'Text': true,
'ObjectID': true
'ObjectID': true,
};
/**
@ -99,14 +99,14 @@ ModelBaseClass.prototype._initProperties = function (data, options) {
writable: true,
enumerable: false,
configurable: true,
value: {}
value: {},
},
__data: {
writable: true,
enumerable: false,
configurable: true,
value: {}
value: {},
},
// Instance level data source
@ -114,7 +114,7 @@ ModelBaseClass.prototype._initProperties = function (data, options) {
writable: true,
enumerable: false,
configurable: true,
value: options.dataSource
value: options.dataSource,
},
// Instance level strict mode
@ -122,14 +122,14 @@ ModelBaseClass.prototype._initProperties = function (data, options) {
writable: true,
enumerable: false,
configurable: true,
value: strict
value: strict,
},
__persisted: {
writable: true,
enumerable: false,
configurable: true,
value: false
value: false,
},
});
@ -138,7 +138,7 @@ ModelBaseClass.prototype._initProperties = function (data, options) {
writable: true,
enumerable: false,
configrable: true,
value: []
value: [],
});
}
} else {
@ -587,7 +587,7 @@ ModelBaseClass.prototype.inspect = function (depth) {
return util.inspect(this.__data, {
showHidden: false,
depth: depth,
colors: false
colors: false,
});
};

View File

@ -108,7 +108,7 @@ ObserverMixin.notifyObserversOf = function(operation, context, callback) {
);
}
},
function(err) { callback(err, context) }
function(err) { callback(err, context); }
);
});
return callback.promise;

View File

@ -26,7 +26,7 @@ var RelationTypes = {
hasAndBelongsToMany: 'hasAndBelongsToMany',
referencesMany: 'referencesMany',
embedsOne: 'embedsOne',
embedsMany: 'embedsMany'
embedsMany: 'embedsMany',
};
var RelationClasses = {
@ -37,7 +37,7 @@ var RelationClasses = {
hasAndBelongsToMany: HasAndBelongsToMany,
referencesMany: ReferencesMany,
embedsOne: EmbedsOne,
embedsMany: EmbedsMany
embedsMany: EmbedsMany,
};
exports.Relation = Relation;
@ -151,7 +151,7 @@ RelationDefinition.prototype.toJSON = function () {
keyFrom: this.keyFrom,
modelTo: modelToName,
keyTo: this.keyTo,
multiple: this.multiple
multiple: this.multiple,
};
if (this.modelThrough) {
json.modelThrough = this.modelThrough.modelName;
@ -186,7 +186,7 @@ RelationDefinition.prototype.defineMethod = function(name, fn) {
method = function() {
var rel = this[relationName];
return rel[name].apply(rel, arguments);
}
};
}
if (method && fn.shared) {
sharedMethod(definition, name, method, fn);
@ -623,7 +623,7 @@ RelationDefinition.hasMany = function hasMany(modelFrom, modelTo, params) {
scope: params.scope,
options: params.options,
keyThrough: keyThrough,
polymorphic: polymorphic
polymorphic: polymorphic,
});
definition.modelThrough = params.through;
@ -641,7 +641,7 @@ RelationDefinition.hasMany = function hasMany(modelFrom, modelTo, params) {
findById: scopeMethod(definition, 'findById'),
destroy: scopeMethod(definition, 'destroyById'),
updateById: scopeMethod(definition, 'updateById'),
exists: scopeMethod(definition, 'exists')
exists: scopeMethod(definition, 'exists'),
};
var findByIdFunc = scopeMethods.findById;
@ -906,7 +906,7 @@ var throughKeys = function(definition) {
var fk2 = findBelongsTo(modelThrough, definition.modelTo, pk2)[0];
}
return [fk1, fk2];
}
};
/**
* Find a related item by foreign key
@ -1266,7 +1266,7 @@ RelationDefinition.belongsTo = function (modelFrom, modelTo, params) {
scope: params.scope,
options: params.options,
polymorphic: polymorphic,
methods: params.methods
methods: params.methods,
});
// Define a property for the scope so that we have 'this' for the scoped methods
@ -1286,7 +1286,7 @@ RelationDefinition.belongsTo = function (modelFrom, modelTo, params) {
}
bindRelationMethods(relation, relationMethod, definition);
return relationMethod;
}
},
});
// FIXME: [rfeng] Wrap the property into a function for remoting
@ -1531,7 +1531,7 @@ BelongsTo.prototype.getAsync = function (options, cb) {
cb = cb || utils.createPromiseCallback();
this.related(true, options, cb);
return cb.promise;
}
};
/**
@ -1632,7 +1632,7 @@ RelationDefinition.hasOne = function (modelFrom, modelTo, params) {
scope: params.scope,
options: params.options,
polymorphic: polymorphic,
methods: params.methods
methods: params.methods,
});
modelTo.dataSource.defineForeignKey(modelTo.modelName, fk, modelFrom.modelName, pk);
@ -1643,7 +1643,7 @@ RelationDefinition.hasOne = function (modelFrom, modelTo, params) {
configurable: true,
get: function() {
var relation = new HasOne(definition, this);
var relationMethod = relation.related.bind(relation)
var relationMethod = relation.related.bind(relation);
relationMethod.getAsync = relation.getAsync.bind(relation);
relationMethod.create = relation.create.bind(relation);
relationMethod.build = relation.build.bind(relation);
@ -1652,7 +1652,7 @@ RelationDefinition.hasOne = function (modelFrom, modelTo, params) {
relationMethod._targetClass = definition.modelTo.modelName;
bindRelationMethods(relation, relationMethod, definition);
return relationMethod;
}
},
});
// FIXME: [rfeng] Wrap the property into a function for remoting
@ -1968,7 +1968,7 @@ RelationDefinition.embedsOne = function (modelFrom, modelTo, params) {
scope: params.scope,
options: params.options,
embed: true,
methods: params.methods
methods: params.methods,
});
var opts = { type: modelTo };
@ -2015,7 +2015,7 @@ RelationDefinition.embedsOne = function (modelFrom, modelTo, params) {
relationMethod._targetClass = definition.modelTo.modelName;
bindRelationMethods(relation, relationMethod, definition);
return relationMethod;
}
},
});
// FIXME: [rfeng] Wrap the property into a function for remoting
@ -2247,11 +2247,11 @@ RelationDefinition.embedsMany = function embedsMany(modelFrom, modelTo, params)
properties: params.properties,
scope: params.scope,
options: params.options,
embed: true
embed: true,
});
modelFrom.dataSource.defineProperty(modelFrom.modelName, propertyName, {
type: [modelTo], default: function() { return []; }
type: [modelTo], default: function() { return []; },
});
if (typeof modelTo.dataSource.connector.generateId !== 'function') {
@ -2282,7 +2282,7 @@ RelationDefinition.embedsMany = function embedsMany(modelFrom, modelTo, params)
this.errors.add(propertyName, 'contains duplicate `' + idName + '`', 'uniqueness');
err(false);
}
}, { code: 'uniqueness' })
}, { code: 'uniqueness' });
}
// validate all embedded items
@ -2325,7 +2325,7 @@ RelationDefinition.embedsMany = function embedsMany(modelFrom, modelTo, params)
set: scopeMethod(definition, 'set'),
unset: scopeMethod(definition, 'unset'),
at: scopeMethod(definition, 'at'),
value: scopeMethod(definition, 'embeddedValue')
value: scopeMethod(definition, 'embeddedValue'),
};
var findByIdFunc = scopeMethods.findById;
@ -2604,7 +2604,7 @@ EmbedsMany.prototype.destroyAll = function(where, options, cb) {
if (where && Object.keys(where).length > 0) {
var filter = applyFilter({ where: where });
var reject = function(v) { return !filter(v) };
var reject = function(v) { return !filter(v); };
embeddedList = embeddedList ? embeddedList.filter(reject) : embeddedList;
} else {
embeddedList = [];
@ -2867,11 +2867,11 @@ RelationDefinition.referencesMany = function referencesMany(modelFrom, modelTo,
multiple: true,
properties: params.properties,
scope: params.scope,
options: params.options
options: params.options,
});
modelFrom.dataSource.defineProperty(modelFrom.modelName, fk, {
type: [idType], default: function() { return []; }
type: [idType], default: function() { return []; },
});
modelFrom.validate(relationName, function(err) {
@ -2884,7 +2884,7 @@ RelationDefinition.referencesMany = function referencesMany(modelFrom, modelTo,
this.errors.add(relationName, msg, 'uniqueness');
err(false);
}
}, { code: 'uniqueness' })
}, { code: 'uniqueness' });
var scopeMethods = {
findById: scopeMethod(definition, 'findById'),
@ -2893,7 +2893,7 @@ RelationDefinition.referencesMany = function referencesMany(modelFrom, modelTo,
exists: scopeMethod(definition, 'exists'),
add: scopeMethod(definition, 'add'),
remove: scopeMethod(definition, 'remove'),
at: scopeMethod(definition, 'at')
at: scopeMethod(definition, 'at'),
};
var findByIdFunc = scopeMethods.findById;
@ -3034,7 +3034,7 @@ ReferencesMany.prototype.exists = function (fkId, options, cb) {
var ids = this.modelInstance[fk] || [];
cb = cb || utils.createPromiseCallback();
process.nextTick(function() { cb(null, utils.findIndexOf(ids, fkId, idEquals) > -1) });
process.nextTick(function() { cb(null, utils.findIndexOf(ids, fkId, idEquals) > -1); });
return cb.promise;
};

View File

@ -97,7 +97,7 @@ ScopeDefinition.prototype.related = function(receiver, scopeParams, condOrRefres
cb(null, self.__cachedRelations[name]);
}
return cb.promise;
}
};
/**
* Define a scope method
@ -106,7 +106,7 @@ ScopeDefinition.prototype.related = function(receiver, scopeParams, condOrRefres
*/
ScopeDefinition.prototype.defineMethod = function(name, fn) {
return this.methods[name] = fn;
}
};
/**
* Define a scope to the class
@ -143,7 +143,7 @@ function defineScope(cls, targetClass, name, params, methods, options) {
name: name,
params: params,
methods: methods,
options: options
options: options,
});
if (isStatic) {
@ -192,7 +192,7 @@ function defineScope(cls, targetClass, name, params, methods, options) {
cb = options;
options = {};
}
options = options || {}
options = options || {};
// Check if there is a through model
// see https://github.com/strongloop/loopback/issues/1076
if (f._scope.collect &&
@ -208,7 +208,7 @@ function defineScope(cls, targetClass, name, params, methods, options) {
// the target model
f._scope.include = {
relation: f._scope.collect,
scope: condOrRefresh
scope: condOrRefresh,
};
condOrRefresh = {};
}
@ -237,9 +237,9 @@ function defineScope(cls, targetClass, name, params, methods, options) {
cb = options;
options = {};
}
options = options || {}
options = options || {};
return definition.related(self, f._scope, condOrRefresh, options, cb);
}
};
f.build = build;
f.create = create;
@ -265,11 +265,11 @@ function defineScope(cls, targetClass, name, params, methods, options) {
get: function() {
mergeQuery(f._scope, targetModel._scopeMeta[name]);
return f;
}
},
});
}.bind(self));
return f;
}
},
});
// Wrap the property into a function for remoting

View File

@ -78,7 +78,7 @@ TransactionMixin.beginTransaction = function(options, cb) {
setTimeout(function() {
var context = {
transaction: transaction,
operation: 'timeout'
operation: 'timeout',
};
transaction.notifyObserversOf('timeout', context, function(err) {
if (!err) {
@ -121,7 +121,7 @@ if (Transaction) {
}
var context = {
transaction: self,
operation: 'commit'
operation: 'commit',
};
function work(done) {
@ -155,7 +155,7 @@ if (Transaction) {
}
var context = {
transaction: self,
operation: 'rollback'
operation: 'rollback',
};
function work(done) {

View File

@ -135,7 +135,7 @@ function convertToArray(include) {
if (typeof includeEntry === 'string') {
var obj = {};
obj[includeEntry] = true;
normalized.push(obj)
normalized.push(obj);
}
else {
normalized.push(includeEntry);
@ -430,7 +430,7 @@ function defineCachedRelations(obj) {
writable: true,
enumerable: false,
configurable: true,
value: {}
value: {},
});
}
}

View File

@ -292,7 +292,7 @@ function validateInclusion(attr, conf, err) {
if (nullCheck.call(this, attr, conf, err)) return;
if (!~conf.in.indexOf(this[attr])) {
err()
err();
}
}
@ -303,7 +303,7 @@ function validateExclusion(attr, conf, err) {
if (nullCheck.call(this, attr, conf, err)) return;
if (~conf.in.indexOf(this[attr])) {
err()
err();
}
}
@ -372,7 +372,7 @@ var validators = {
exclusion: validateExclusion,
format: validateFormat,
custom: validateCustom,
uniqueness: validateUniqueness
uniqueness: validateUniqueness,
};
function getConfigurator(name, opts) {
@ -438,7 +438,7 @@ Validatable.prototype.isValid = function (callback, data) {
Object.defineProperty(this, 'errors', {
enumerable: false,
configurable: true,
value: new Errors
value: new Errors,
});
this.trigger('validate', function(validationsDone) {
@ -511,7 +511,7 @@ function cleanErrors(inst) {
Object.defineProperty(inst, 'errors', {
enumerable: false,
configurable: true,
value: false
value: false,
});
}
@ -593,19 +593,19 @@ var defaultMessages = {
length: {
min: 'too short',
max: 'too long',
is: 'length is wrong'
is: 'length is wrong',
},
common: {
blank: 'is blank',
'null': 'is null'
'null': 'is null',
},
numericality: {
'int': 'is not an integer',
'number': 'is not a number'
'number': 'is not a number',
},
inclusion: 'is not included in the list',
exclusion: 'is reserved',
uniqueness: 'is not unique'
uniqueness: 'is not unique',
};
function nullCheck(attr, conf, err) {
@ -647,7 +647,7 @@ function configure(cls, validation, args, opts) {
writable: true,
configurable: true,
enumerable: false,
value: {}
value: {},
});
}
args = [].slice.call(args);
@ -675,7 +675,7 @@ function Errors() {
Object.defineProperty(this, 'codes', {
enumerable: false,
configurable: true,
value: {}
value: {},
});
}
@ -763,7 +763,7 @@ function ValidationError(obj) {
this.details = {
context: context,
codes: obj.errors && obj.errors.codes,
messages: obj.errors
messages: obj.errors,
};
if (Error.captureStackTrace) {
@ -813,7 +813,7 @@ function formatPropertyError(propertyName, propertyValue, errorMessage) {
showHidden: false,
color: false,
// show top-level object properties only
depth: Array.isArray(propertyValue) ? 1 : 0
depth: Array.isArray(propertyValue) ? 1 : 0,
});
formattedValue = truncatePropertyString(formattedValue);
} else {

View File

@ -17,12 +17,12 @@ var Memory = require('../lib/connectors/memory').Memory;
var HOOK_NAMES = [
'access',
'before save', 'persist', 'after save',
'before delete', 'after delete'
'before delete', 'after delete',
];
var dataSources = [
createOptimizedDataSource(),
createUnoptimizedDataSource()
createUnoptimizedDataSource(),
];
var observedContexts = [];
@ -134,7 +134,7 @@ function setupTestModels() {
var TestModel = ds.TestModel = ds.createModel('TestModel', {
id: { type: String, id: true, default: uid },
name: { type: String, required: true },
extra: { type: String, required: false }
extra: { type: String, required: false },
});
});
return Promise.resolve();
@ -155,7 +155,7 @@ function runner(fn) {
observedContexts.push({
operation: fn.name,
connector: ds.name,
hooks: {}
hooks: {},
});
return fn(ds);
});
@ -171,11 +171,11 @@ function resetStorage(ds) {
});
return TestModel.deleteAll()
.then(function() {
return TestModel.create({ name: 'first' })
return TestModel.create({ name: 'first' });
})
.then(function(instance) {
// Look it up from DB so that default values are retrieved
return TestModel.findById(instance.id)
return TestModel.findById(instance.id);
})
.then(function(instance) {
ds.existingInstance = instance;
@ -193,7 +193,7 @@ function resetStorage(ds) {
}
function report() {
console.log('<style>')
console.log('<style>');
console.log('td { font-family: "monospace": }');
console.log('td, th {');
console.log(' vertical-align: text-top;');

View File

@ -13,23 +13,23 @@ describe('Datasource-specific field types for foreign keys', function () {
before(function() {
ds = new DataSource('memory');
Item = ds.define('Item', {
"myProp": {
"id": true,
"type": "string",
"memory": {
"dataType": "string"
}
}
'myProp': {
'id': true,
'type': 'string',
'memory': {
'dataType': 'string',
},
},
});
Variant = ds.define('Variant', {}, {
relations: {
"item": {
"type": "belongsTo",
"as": "item",
"model": "Item",
"foreignKey": "myProp"
}
}
'item': {
'type': 'belongsTo',
'as': 'item',
'model': 'Item',
'foreignKey': 'myProp',
},
},
});
});
@ -38,7 +38,7 @@ describe('Datasource-specific field types for foreign keys', function () {
should.exist(VariantDefinition);
should.exist(VariantDefinition.properties.myProp.memory);
should.exist(VariantDefinition.properties.myProp.memory.dataType);
VariantDefinition.properties.myProp.memory.dataType.should.be.equal("string");
VariantDefinition.properties.myProp.memory.dataType.should.be.equal('string');
done();
});
})

View File

@ -160,7 +160,7 @@ describe('async observer', function() {
it('passes context to final callback', function(done) {
var context = {};
TestModel.notifyObserversOf('event', context, function(err, ctx) {
(ctx || "null").should.equal(context);
(ctx || 'null').should.equal(context);
done();
});
});

View File

@ -19,7 +19,7 @@ describe('basic-querying', function () {
birthday: { type: Date, index: true },
role: { type: String, index: true },
order: { type: Number, index: true, sort: true },
vip: {type: Boolean}
vip: { type: Boolean },
});
db.automigrate(done);
@ -73,7 +73,7 @@ describe('basic-querying', function () {
{ name: 'c' },
{ name: 'd', vip: true },
{ name: 'e' },
{ name: 'f' }
{ name: 'f' },
];
db.automigrate(['User'], function(err) {
User.create(people, function(err, users) {
@ -223,7 +223,7 @@ describe('basic-querying', function () {
it('should support "and" operator that is satisfied', function(done) {
User.find({ where: { and: [
{ name: 'John Lennon' },
{role: 'lead'}
{ role: 'lead' },
] }}, function(err, users) {
should.not.exist(err);
users.should.have.property('length', 1);
@ -234,7 +234,7 @@ describe('basic-querying', function () {
it('should support "and" operator that is not satisfied', function(done) {
User.find({ where: { and: [
{ name: 'John Lennon' },
{role: 'member'}
{ role: 'member' },
] }}, function(err, users) {
should.not.exist(err);
users.should.have.property('length', 0);
@ -245,7 +245,7 @@ describe('basic-querying', function () {
it('should support "or" that is satisfied', function(done) {
User.find({ where: { or: [
{ name: 'John Lennon' },
{role: 'lead'}
{ role: 'lead' },
] }}, function(err, users) {
should.not.exist(err);
users.should.have.property('length', 2);
@ -256,7 +256,7 @@ describe('basic-querying', function () {
it('should support "or" operator that is not satisfied', function(done) {
User.find({ where: { or: [
{ name: 'XYZ' },
{role: 'Hello1'}
{ role: 'Hello1' },
] }}, function(err, users) {
should.not.exist(err);
users.should.have.property('length', 0);
@ -265,7 +265,7 @@ describe('basic-querying', function () {
});
it('should support date "gte" that is satisfied', function(done) {
User.find({order: 'seq', where: { birthday: { "gte": new Date('1980-12-08') }
User.find({ order: 'seq', where: { birthday: { 'gte': new Date('1980-12-08') },
}}, function(err, users) {
should.not.exist(err);
users.should.have.property('length', 1);
@ -275,7 +275,7 @@ describe('basic-querying', function () {
});
it('should support date "gt" that is not satisfied', function(done) {
User.find({order: 'seq', where: { birthday: { "gt": new Date('1980-12-08') }
User.find({ order: 'seq', where: { birthday: { 'gt': new Date('1980-12-08') },
}}, function(err, users) {
should.not.exist(err);
users.should.have.property('length', 0);
@ -284,7 +284,7 @@ describe('basic-querying', function () {
});
it('should support date "gt" that is satisfied', function(done) {
User.find({order: 'seq', where: { birthday: { "gt": new Date('1980-12-07') }
User.find({ order: 'seq', where: { birthday: { 'gt': new Date('1980-12-07') },
}}, function(err, users) {
should.not.exist(err);
users.should.have.property('length', 1);
@ -294,7 +294,7 @@ describe('basic-querying', function () {
});
it('should support date "lt" that is satisfied', function(done) {
User.find({order: 'seq', where: { birthday: { "lt": new Date('1980-12-07') }
User.find({ order: 'seq', where: { birthday: { 'lt': new Date('1980-12-07') },
}}, function(err, users) {
should.not.exist(err);
users.should.have.property('length', 1);
@ -304,7 +304,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);
@ -314,7 +314,7 @@ describe('basic-querying', function () {
});
it('should support number "gt" that is not satisfied', function(done) {
User.find({order: 'seq', where: { order: { "gt": 6 }
User.find({ order: 'seq', where: { order: { 'gt': 6 },
}}, function(err, users) {
should.not.exist(err);
users.should.have.property('length', 0);
@ -323,7 +323,7 @@ describe('basic-querying', function () {
});
it('should support number "gt" that is satisfied', function(done) {
User.find({order: 'seq', where: { order: { "gt": 5 }
User.find({ order: 'seq', where: { order: { 'gt': 5 },
}}, function(err, users) {
should.not.exist(err);
users.should.have.property('length', 1);
@ -333,7 +333,7 @@ describe('basic-querying', function () {
});
it('should support number "lt" that is satisfied', function(done) {
User.find({order: 'seq', where: { order: { "lt": 2 }
User.find({ order: 'seq', where: { order: { 'lt': 2 },
}}, function(err, users) {
should.not.exist(err);
users.should.have.property('length', 1);
@ -343,7 +343,7 @@ describe('basic-querying', function () {
});
it('should support number "gt" that is satisfied by null value', function(done) {
User.find({order: 'seq', where: { order: { "gt": null }
User.find({ order: 'seq', where: { order: { 'gt': null },
}}, function(err, users) {
should.not.exist(err);
users.should.have.property('length', 0);
@ -352,7 +352,7 @@ describe('basic-querying', function () {
});
it('should support number "lt" that is not satisfied by null value', function(done) {
User.find({order: 'seq', where: { order: { "lt": null }
User.find({ order: 'seq', where: { order: { 'lt': null },
}}, function(err, users) {
should.not.exist(err);
users.should.have.property('length', 0);
@ -361,7 +361,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 +370,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);
@ -380,7 +380,7 @@ describe('basic-querying', function () {
});
it('should support string "gt" that is not satisfied', function(done) {
User.find({order: 'seq', where: { name: { "gt": 'xyz' }
User.find({ order: 'seq', where: { name: { 'gt': 'xyz' },
}}, function(err, users) {
should.not.exist(err);
users.should.have.property('length', 0);
@ -389,7 +389,7 @@ describe('basic-querying', function () {
});
it('should support string "gt" that is satisfied', function(done) {
User.find({order: 'seq', where: { name: { "gt": 'Paul McCartney' }
User.find({ order: 'seq', where: { name: { 'gt': 'Paul McCartney' },
}}, function(err, users) {
should.not.exist(err);
users.should.have.property('length', 3);
@ -399,7 +399,7 @@ describe('basic-querying', function () {
});
it('should support string "lt" that is satisfied', function(done) {
User.find({order: 'seq', where: { name: { "lt": 'Paul McCartney' }
User.find({ order: 'seq', where: { name: { 'lt': 'Paul McCartney' },
}}, function(err, users) {
should.not.exist(err);
users.should.have.property('length', 2);
@ -409,7 +409,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);
@ -419,7 +419,7 @@ describe('basic-querying', function () {
});
it('should support boolean "gt" that is not satisfied', function(done) {
User.find({order: 'seq', where: { vip: { "gt": true }
User.find({ order: 'seq', where: { vip: { 'gt': true },
}}, function(err, users) {
should.not.exist(err);
users.should.have.property('length', 0);
@ -428,7 +428,7 @@ describe('basic-querying', function () {
});
it('should support boolean "gt" that is satisfied', function(done) {
User.find({order: 'seq', where: { vip: { "gt": false }
User.find({ order: 'seq', where: { vip: { 'gt': false },
}}, function(err, users) {
should.not.exist(err);
users.should.have.property('length', 3);
@ -438,7 +438,7 @@ describe('basic-querying', function () {
});
it('should support boolean "lt" that is satisfied', function(done) {
User.find({order: 'seq', where: { vip: { "lt": true }
User.find({ order: 'seq', where: { vip: { 'lt': true },
}}, function(err, users) {
should.not.exist(err);
users.should.have.property('length', 2);
@ -482,8 +482,8 @@ describe('basic-querying', function () {
});
});
});
}
}
},
};
}
sample({ name: true }).expect(['name']);
@ -558,7 +558,7 @@ describe('basic-querying', function () {
it('should find last record in filtered set', function(done) {
User.findOne({
where: { role: 'lead' },
order: 'order DESC'
order: 'order DESC',
}, function(e, u) {
should.not.exist(e);
should.exist(u);
@ -632,9 +632,9 @@ describe.skip('queries', function() {
var db = getSchema();
Todo = db.define('Todo', {
id: false,
content: {type: 'string'}
content: { type: 'string' },
}, {
idInjection: false
idInjection: false,
});
db.automigrate(['Todo'], done);
});
@ -643,7 +643,7 @@ describe.skip('queries', function() {
Todo.create([
{ content: 'Buy eggs' },
{ content: 'Buy milk' },
{content: 'Buy sausages'}
{ content: 'Buy sausages' },
], done);
});
});
@ -803,7 +803,7 @@ function seed(done) {
role: 'lead',
birthday: new Date('1980-12-08'),
order: 2,
vip: true
vip: true,
},
{
seq: 1,
@ -812,18 +812,18 @@ function seed(done) {
role: 'lead',
birthday: new Date('1942-06-18'),
order: 1,
vip: true
vip: true,
},
{ seq: 2, name: 'George Harrison', order: 5, vip: false },
{ seq: 3, name: 'Ringo Starr', order: 6, vip: false },
{ seq: 4, name: 'Pete Best', order: 4 },
{seq: 5, name: 'Stuart Sutcliffe', order: 3, vip: true}
{ seq: 5, name: 'Stuart Sutcliffe', order: 3, vip: true },
];
async.series([
User.destroyAll.bind(User),
function(cb) {
async.each(beatles, User.create.bind(User), cb);
}
},
], done);
}

View File

@ -59,14 +59,14 @@ Object.defineProperty(module.exports, 'it', {
writable: true,
enumerable: false,
configurable: true,
value: it
value: it,
});
Object.defineProperty(module.exports, 'skip', {
writable: true,
enumerable: false,
configurable: true,
value: skip
value: skip,
});
function clearAndCreate(model, data, callback) {
@ -104,23 +104,23 @@ function testOrm(dataSource) {
approved: Boolean,
joinedAt: Date,
age: Number,
passwd: { type: String, index: true }
passwd: { type: String, index: true },
});
Dog = dataSource.define('Dog', {
name: { type: String, limit: 64, allowNull: false }
name: { type: String, limit: 64, allowNull: false },
});
Log = dataSource.define('Log', {
ownerId: { type: Number, allowNull: true },
name: { type: String, limit: 64, allowNull: false }
name: { type: String, limit: 64, allowNull: false },
});
Log.belongsTo(Dog, { as: 'owner', foreignKey: 'ownerId' });
dataSource.extendModel('User', {
settings: { type: Schema.JSON },
extra: Object
extra: Object,
});
var newuser = new User({ settings: { hey: 'you' }});
@ -131,11 +131,11 @@ function testOrm(dataSource) {
subject: { type: String },
content: { type: Text },
date: { type: Date, default: function() {
return new Date
return new Date;
}, index: true },
published: { type: Boolean, default: false, index: true },
likes: [],
related: [RelatedPost]
related: [RelatedPost],
}, { table: 'posts' });
function RelatedPost() {
@ -171,7 +171,7 @@ function testOrm(dataSource) {
// post.author(user) -- setter when called with object
Passport = dataSource.define('Passport', {
number: String
number: String,
});
Passport.belongsTo(User, { as: 'owner', foreignKey: 'ownerId' });
@ -224,7 +224,7 @@ function testOrm(dataSource) {
Post.create({
title: title,
date: date
date: date,
}, function(err, obj) {
test.ok(obj.id, 'Object id should present');
test.equals(obj.title, title);
@ -258,7 +258,7 @@ function testOrm(dataSource) {
Post.create({
title: title,
date: date
date: date,
}, function(err, obj) {
test.ok(obj.id);
test.equals(obj.title, title);
@ -597,12 +597,12 @@ function testOrm(dataSource) {
it('should handle ORDER clause', function(test) {
var titles = [
{ title: 'Title A', subject: "B" },
{ title: 'Title Z', subject: "A" },
{ title: 'Title M', subject: "C" },
{ title: 'Title A', subject: "A" },
{ title: 'Title B', subject: "A" },
{ title: 'Title C', subject: "D" }
{ title: 'Title A', subject: 'B' },
{ title: 'Title Z', subject: 'A' },
{ title: 'Title M', subject: 'C' },
{ title: 'Title A', subject: 'A' },
{ title: 'Title B', subject: 'A' },
{ title: 'Title C', subject: 'D' },
];
var isRedis = Post.dataSource.name === 'redis';
var dates = isRedis ? [5, 9, 0, 17, 10, 9] : [
@ -611,7 +611,7 @@ function testOrm(dataSource) {
new Date(1000 * 0),
new Date(1000 * 17),
new Date(1000 * 10),
new Date(1000 * 9)
new Date(1000 * 9),
];
titles.forEach(function(t, i) {
Post.create({ title: t.title, subject: t.subject, date: dates[i] }, done);
@ -697,28 +697,28 @@ function testOrm(dataSource) {
function doMultipleSortTest() {
tests += 1;
Post.all({order: "title ASC, subject ASC"}, function (err, posts) {
Post.all({ order: 'title ASC, subject ASC' }, function(err, posts) {
if (err) console.log(err);
test.equal(posts.length, 6);
test.equal(posts[0].title, "Title A");
test.equal(posts[0].subject, "A");
test.equal(posts[1].title, "Title A");
test.equal(posts[1].subject, "B");
test.equal(posts[5].title, "Title Z");
test.equal(posts[0].title, 'Title A');
test.equal(posts[0].subject, 'A');
test.equal(posts[1].title, 'Title A');
test.equal(posts[1].subject, 'B');
test.equal(posts[5].title, 'Title Z');
finished();
});
}
function doMultipleReverseSortTest() {
tests += 1;
Post.all({order: "title ASC, subject DESC"}, function (err, posts) {
Post.all({ order: 'title ASC, subject DESC' }, function(err, posts) {
if (err) console.log(err);
test.equal(posts.length, 6);
test.equal(posts[0].title, "Title A");
test.equal(posts[0].subject, "B");
test.equal(posts[1].title, "Title A");
test.equal(posts[1].subject, "A");
test.equal(posts[5].title, "Title Z");
test.equal(posts[0].title, 'Title A');
test.equal(posts[0].subject, 'B');
test.equal(posts[1].title, 'Title A');
test.equal(posts[1].subject, 'A');
test.equal(posts[5].title, 'Title Z');
finished();
});
}
@ -886,7 +886,7 @@ function testOrm(dataSource) {
'tin@hcompany.com',
'mike@hcompany.com',
'susan@hcompany.com',
'test@hcompany.com'
'test@hcompany.com',
];
User.destroyAll(function() {
emails.forEach(function(email) {
@ -1027,7 +1027,7 @@ function testOrm(dataSource) {
var newData = {
id: 1,
title: 'New title (really new)',
content: 'Some example content (updated)'
content: 'Some example content (updated)',
};
Post.updateOrCreate(newData, function(err, updatedPost) {
if (err) throw err;

View File

@ -19,7 +19,7 @@ describe('crud-with-options', function () {
birthday: { type: Date, index: true },
role: { type: String, index: true },
order: { type: Number, index: true, sort: true },
vip: {type: Boolean}
vip: { type: Boolean },
});
options = {};
filter = { fields: ['name', 'id'] };
@ -198,7 +198,7 @@ describe('crud-with-options', function () {
{ id: 3, name: 'c' },
{ id: 4, name: 'd', vip: true },
{ id: 5, name: 'e' },
{ id: 6, name: 'f' }
{ id: 6, name: 'f' },
];
// Use automigrate so that serial keys are 1-6
db.automigrate(['User'], function(err) {
@ -547,7 +547,7 @@ function seed(done) {
role: 'lead',
birthday: new Date('1980-12-08'),
order: 2,
vip: true
vip: true,
},
{
seq: 1,
@ -556,18 +556,18 @@ function seed(done) {
role: 'lead',
birthday: new Date('1942-06-18'),
order: 1,
vip: true
vip: true,
},
{ seq: 2, name: 'George Harrison', order: 5, vip: false },
{ seq: 3, name: 'Ringo Starr', order: 6, vip: false },
{ seq: 4, name: 'Pete Best', order: 4 },
{seq: 5, name: 'Stuart Sutcliffe', order: 3, vip: true}
{ seq: 5, name: 'Stuart Sutcliffe', order: 3, vip: true },
];
async.series([
User.destroyAll.bind(User),
function(cb) {
async.each(beatles, User.create.bind(User), cb);
}
},
], done);
}

View File

@ -19,7 +19,7 @@ describe('DataSource', function() {
// this is what LoopBack does
return new DataSource({
name: 'dsname',
connector: throwingConnector
connector: throwingConnector,
});
}).should.throw(/loopback-connector-throwing/);
});

View File

@ -21,7 +21,7 @@ describe('datatypes', function () {
bool: Boolean,
list: { type: [String] },
arr: Array,
nested: Nested
nested: Nested,
});
db.automigrate(['Model'], done);
});
@ -29,7 +29,7 @@ describe('datatypes', function () {
it('should return 400 when property of type array is set to string value',
function(done) {
var myModel = db.define('myModel', {
list: { type: ['object'] }
list: { type: ['object'] },
});
(function() {
@ -42,7 +42,7 @@ describe('datatypes', function () {
it('should return 400 when property of type array is set to object value',
function(done) {
var myModel = db.define('myModel', {
list: { type: ['object'] }
list: { type: ['object'] },
});
(function() {
@ -56,7 +56,7 @@ describe('datatypes', function () {
var d = new Date, id;
Model.create({
str: 'hello', date: d, num: '3', bool: 1, list: ['test'], arr: [1, 'str']
str: 'hello', date: d, num: '3', bool: 1, list: ['test'], arr: [1, 'str'],
}, function(err, m) {
should.not.exists(err);
should.exist(m && m.id);
@ -127,7 +127,7 @@ describe('datatypes', function () {
// update using updateAttributes
m.updateAttributes({
id: m.id, num: '10'
id: m.id, num: '10',
}, function(err, m) {
should.not.exist(err);
m.num.should.be.type('number');
@ -162,7 +162,7 @@ describe('datatypes', function () {
function(done) {
db = getSchema();
Model = db.define('RequiredNumber', {
num: { type: Number, required: true }
num: { type: Number, required: true },
});
db.automigrate(['Model'], function() {
Model.create({ num: [1, 2, 3] }, function(err, inst) {
@ -180,10 +180,10 @@ describe('datatypes', function () {
'TestModel',
{
desc: { type: String, required: false },
stars: { type: Number, required: false }
stars: { type: Number, required: false },
},
{
persistUndefinedAsNull: true
persistUndefinedAsNull: true,
});
isStrict = TestModel.definition.settings.strict;
@ -294,7 +294,7 @@ describe('datatypes', function () {
inst.__data.dx = undefined;
inst.toObject(false).should.have.properties({
desc: null, stars: null, extra: null, dx: null
desc: null, stars: null, extra: null, dx: null,
});
});
});

View File

@ -46,7 +46,7 @@ var setupProducts = function(ids, done) {
ids.widgetB = inst.id;
next();
});
}
},
], done);
};
@ -56,17 +56,17 @@ describe('default scope', function () {
db = getSchema();
Category = db.define('Category', {
name: String
name: String,
});
Product = db.define('Product', {
name: String,
kind: String,
description: String,
active: { type: Boolean, default: true }
active: { type: Boolean, default: true },
}, {
scope: { order: 'name' },
scopes: { active: { where: { active: true } } }
scopes: { active: { where: { active: true }}},
});
Product.lookupModel = function(data) {
@ -80,7 +80,7 @@ describe('default scope', function () {
scope: { where: { kind: 'Tool' }, order: 'name' },
scopes: { active: { where: { active: true }}},
mongodb: { collection: 'Product' },
memory: { collection: 'Product' }
memory: { collection: 'Product' },
});
Widget = db.define('Widget', Product.definition.properties, {
@ -89,11 +89,11 @@ describe('default scope', function () {
scope: { where: { kind: 'Widget' }, order: 'name' },
scopes: { active: { where: { active: true }}},
mongodb: { collection: 'Product' },
memory: { collection: 'Product' }
memory: { collection: 'Product' },
});
Person = db.define('Person', { name: String }, {
scope: { include: 'things' }
scope: { include: 'things' },
});
// inst is only valid for instance methods
@ -112,7 +112,7 @@ describe('default scope', function () {
attributes: propertiesFn,
scope: scopeFn,
mongodb: { collection: 'Product' },
memory: { collection: 'Product' }
memory: { collection: 'Product' },
});
Category.hasMany(Product);
@ -685,7 +685,7 @@ describe('default scope', function () {
products.should.have.length(2);
products[0].name.should.equal('Product');
products[1].name.should.equal('Product');
var kinds = products.map(function(p) { return p.kind; })
var kinds = products.map(function(p) { return p.kind; });
kinds.sort();
kinds.should.eql(['Thing', 'Widget']);
done();
@ -717,7 +717,7 @@ describe('default scope', function () {
},
function(next) {
cat.things.create({ name: 'Thing A' }, next);
}
},
], done);
});
});

View File

@ -15,7 +15,7 @@ describe('defaults', function () {
Server = db.define('Server', {
host: String,
port: { type: Number, default: 80 },
createdAt: {type: Date, default: '$now'}
createdAt: { type: Date, default: '$now' },
});
});
@ -34,7 +34,7 @@ describe('defaults', function () {
it('should apply defaults on read', function(done) {
db.defineProperty('Server', 'host', {
type: String,
default: 'localhost'
default: 'localhost',
});
Server.all(function(err, servers) {
(new String('localhost')).should.equal(servers[0].host);

View File

@ -31,7 +31,7 @@ describe('Memory connector with mocked discovery', function() {
dataLength: 20,
dataPrecision: null,
dataScale: null,
nullable: 0
nullable: 0,
},
{
owner: 'STRONGLOOP',
@ -41,7 +41,7 @@ describe('Memory connector with mocked discovery', function() {
dataLength: 20,
dataPrecision: null,
dataScale: null,
nullable: 0
nullable: 0,
},
{
owner: 'STRONGLOOP',
@ -51,7 +51,7 @@ describe('Memory connector with mocked discovery', function() {
dataLength: null,
dataPrecision: 10,
dataScale: 0,
nullable: 1
nullable: 1,
},
{
owner: 'STRONGLOOP',
@ -61,7 +61,7 @@ describe('Memory connector with mocked discovery', function() {
dataLength: null,
dataPrecision: 10,
dataScale: 0,
nullable: 1
nullable: 1,
}];
ds.discoverModelProperties = function(modelName, options, cb) {
@ -88,7 +88,7 @@ describe('Memory connector with mocked discovery', function() {
nameMapper: function(type, name) {
// Convert all names to lower case
return name.toLowerCase();
}
},
}, function(err, schemas) {
if (err) return done(err);
schemas.should.have.property('STRONGLOOP.INVENTORY');
@ -118,8 +118,8 @@ describe('Memory connector with mocked discovery', function() {
var models = {
inventory: {
product: { type: 'string' },
location: {type: 'string'}
}
location: { type: 'string' },
},
};
ds.connector.discoverSchemas = function(modelName, options, cb) {
process.nextTick(function() {
@ -138,8 +138,8 @@ describe('Memory connector with mocked discovery', function() {
var models = {
inventory: {
product: { type: 'string' },
location: {type: 'string'}
}
location: { type: 'string' },
},
};
ds.connector.discoverSchemas = function(modelName, options, cb) {
process.nextTick(function() {
@ -184,7 +184,7 @@ describe('Memory connector with mocked discovery', function() {
name: 'Inventory',
options: {
idInjection: false,
memory: { schema: 'STRONGLOOP', table: 'INVENTORY' }
memory: { schema: 'STRONGLOOP', table: 'INVENTORY' },
},
properties: {
available: {
@ -195,12 +195,12 @@ describe('Memory connector with mocked discovery', function() {
dataPrecision: 10,
dataScale: 0,
dataType: 'int',
nullable: 1
nullable: 1,
},
precision: 10,
required: false,
scale: 0,
type: undefined
type: undefined,
},
locationId: {
length: 20,
@ -210,12 +210,12 @@ describe('Memory connector with mocked discovery', function() {
dataPrecision: null,
dataScale: null,
dataType: 'varchar',
nullable: 0
nullable: 0,
},
precision: null,
required: true,
scale: null,
type: undefined
type: undefined,
},
productId: {
length: 20,
@ -225,12 +225,12 @@ describe('Memory connector with mocked discovery', function() {
dataPrecision: null,
dataScale: null,
dataType: 'varchar',
nullable: 0
nullable: 0,
},
precision: null,
required: true,
scale: null,
type: undefined
type: undefined,
},
total: {
length: null,
@ -240,14 +240,14 @@ describe('Memory connector with mocked discovery', function() {
dataPrecision: 10,
dataScale: 0,
dataType: 'int',
nullable: 1
nullable: 1,
},
precision: 10,
required: false,
scale: 0,
type: undefined
}
}
type: undefined,
},
},
};
});
@ -307,7 +307,7 @@ describe('discoverModelDefinitions', function(){
});
tableNames.should.be.eql(
["CUSTOMER", "INVENTORY", "LOCATION"]
['CUSTOMER', 'INVENTORY', 'LOCATION']
);
done();
});
@ -322,7 +322,7 @@ describe('discoverModelDefinitions', function(){
});
tableNames.should.be.eql(
["CUSTOMER", "INVENTORY", "LOCATION"]
['CUSTOMER', 'INVENTORY', 'LOCATION']
);
done();
};
@ -338,7 +338,7 @@ describe('discoverModelDefinitions', function(){
});
tableNames.should.be.eql(
["CUSTOMER", "INVENTORY", "LOCATION"]
['CUSTOMER', 'INVENTORY', 'LOCATION']
);
done();
})
@ -362,7 +362,7 @@ describe('discoverModelProperties', function(){
dataLength: 20,
dataPrecision: null,
dataScale: null,
nullable: 0
nullable: 0,
},
{
owner: 'STRONGLOOP',
@ -372,7 +372,7 @@ describe('discoverModelProperties', function(){
dataLength: 20,
dataPrecision: null,
dataScale: null,
nullable: 0
nullable: 0,
},
{
owner: 'STRONGLOOP',
@ -382,7 +382,7 @@ describe('discoverModelProperties', function(){
dataLength: null,
dataPrecision: 10,
dataScale: 0,
nullable: 1
nullable: 1,
},
{
owner: 'STRONGLOOP',
@ -392,7 +392,7 @@ describe('discoverModelProperties', function(){
dataLength: null,
dataPrecision: 10,
dataScale: 0,
nullable: 1
nullable: 1,
}];
ds.connector.discoverModelProperties = function(modelName, options, cb) {
@ -446,14 +446,14 @@ describe('discoverPrimaryKeys', function(){
tableName: 'INVENTORY',
columnName: 'PRODUCT_ID',
keySeq: 1,
pkName: 'ID_PK'
pkName: 'ID_PK',
},
{
owner: 'STRONGLOOP',
tableName: 'INVENTORY',
columnName: 'LOCATION_ID',
keySeq: 2,
pkName: 'ID_PK'
pkName: 'ID_PK',
}];
ds.connector.discoverPrimaryKeys = function(modelName, options, cb) {
@ -509,7 +509,7 @@ describe('discoverForeignKeys', function(){
pkOwner: 'STRONGLOOP',
pkName: 'PRODUCT_PK',
pkTableName: 'PRODUCT',
pkColumnName: 'ID'
pkColumnName: 'ID',
}];
ds.connector.discoverForeignKeys = function(modelName, options, cb) {
@ -566,7 +566,7 @@ describe('discoverExportedForeignKeys', function(){
pkName: 'PRODUCT_PK',
pkOwner: 'STRONGLOOP',
pkTableName: 'PRODUCT',
pkColumnName: 'ID'
pkColumnName: 'ID',
}];
ds.connector.discoverExportedForeignKeys = function(modelName, options, cb) {

View File

@ -23,7 +23,7 @@ describe('events', function() {
listener.apply(this, arguments);
done();
});
}
};
});
describe('changed', function() {

View File

@ -63,7 +63,7 @@ describe('GeoPoint', function () {
fn = function() {
new GeoPoint({
lat: 150,
lng: null
lng: null,
});
};
fn.should.throw();

View File

@ -22,7 +22,7 @@ describe('hooks', function () {
email: { type: String, index: true },
name: String,
password: String,
state: String
state: String,
});
db.automigrate('User', done);
@ -83,7 +83,7 @@ describe('hooks', function () {
var old = User.dataSource.connector.create;
User.dataSource.connector.create = function(modelName, id, cb) {
cb(new Error('error'));
}
};
User.afterCreate = function() {
throw new Error('shouldn\'t be called');
@ -103,7 +103,7 @@ describe('hooks', function () {
var old = User.dataSource.connector.create;
User.dataSource.connector.create = function(modelName, id, cb) {
throw new Error('shouldn\'t be called');
}
};
User.afterCreate = function() {
throw new Error('shouldn\'t be called');
@ -147,7 +147,7 @@ describe('hooks', function () {
User.create(function(err, user) {
User.beforeSave = function(next, data) {
data.should.have.keys('id', 'name', 'email',
'password', 'state')
'password', 'state');
done();
};
user.save();
@ -162,10 +162,10 @@ describe('hooks', function () {
User.destroyAll(function() {
User.create({
email: 'james.bond@example.com',
password: '53cr3t'
password: '53cr3t',
}, function() {
User.findOne({
where: {email: 'james.bond@example.com'}
where: { email: 'james.bond@example.com' },
}, function(err, jb) {
jb.password.should.equal('hash');
done();
@ -181,14 +181,14 @@ describe('hooks', function () {
};
User.destroyAll(function() {
User.create({
email: 'james.bond@example.com'
email: 'james.bond@example.com',
}, function(err, u) {
u.updateAttribute('password', 'new password', function(e, u) {
should.not.exist(e);
should.exist(u);
u.password.should.equal('hash');
User.findOne({
where: {email: 'james.bond@example.com'}
where: { email: 'james.bond@example.com' },
}, function(err, jb) {
jb.password.should.equal('hash');
done();
@ -265,7 +265,7 @@ describe('hooks', function () {
User.dataSource.connector.save = function(modelName, id, cb) {
User.dataSource.connector.save = save;
cb(new Error('Error'));
}
};
user.save(function(err) {
done();
@ -297,9 +297,9 @@ describe('hooks', function () {
var destroy = User.dataSource.connector.destroy;
User.dataSource.connector.destroy = function(modelName, id, cb) {
cb(new Error('error'));
}
};
User.afterDestroy = function() {
should.fail('afterDestroy shouldn\'t be called')
should.fail('afterDestroy shouldn\'t be called');
};
User.create(function(err, user) {
user.destroy(function(err) {
@ -376,7 +376,7 @@ describe('hooks', function () {
'beforeCreate',
'beforeSave',
'afterSave',
'afterCreate'
'afterCreate',
]);
done();
});
@ -392,7 +392,7 @@ describe('hooks', function () {
'beforeCreate',
'beforeSave',
'afterSave',
'afterCreate'
'afterCreate',
]);
done();
});
@ -420,7 +420,7 @@ describe('hooks', function () {
valid.should.be.true;
life.should.eql([
'beforeValidate',
'afterValidate'
'afterValidate',
]);
done();
});
@ -430,7 +430,7 @@ describe('hooks', function () {
user.destroy(function() {
life.should.eql([
'beforeDestroy',
'afterDestroy'
'afterDestroy',
]);
done();
});

View File

@ -126,7 +126,7 @@ describe('include', function () {
it('should fetch Passports - User - Posts - User', function(done) {
Passport.find({
include: {owner: {posts: 'author'}}
include: { owner: { posts: 'author' }},
}, function(err, passports) {
should.not.exist(err);
should.exist(passports);
@ -158,8 +158,8 @@ describe('include', function () {
Passport.find({
include: { owner: { relation: 'posts', scope:{
fields: ['title'], include: ['author'],
order: 'title DESC'
}}}
order: 'title DESC',
}}},
}, function(err, passports) {
should.not.exist(err);
should.exist(passports);
@ -196,11 +196,11 @@ describe('include', function () {
relation: 'posts', scope: {
fields: ['title'], include: ['author'],
order: 'title DESC',
limit: 2
}
}
limit: 2,
},
limit: 1
},
},
limit: 1,
}, function(err, passports) {
if (err) return done(err);
passports.length.should.equal(1);
@ -211,7 +211,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);
@ -229,8 +229,8 @@ describe('include', function () {
it('should fetch Users with include scope on Posts - hasMany', function(done) {
User.find({
include: { relation: 'posts', scope:{
order: 'title DESC'
}}
order: 'title DESC',
}},
}, function(err, users) {
should.not.exist(err);
should.exist(users);
@ -259,8 +259,8 @@ describe('include', function () {
it('should fetch Users with include scope on Passports - hasMany', function(done) {
User.find({
include: { relation: 'passports', scope:{
where: { number: '2' }
}}
where: { number: '2' },
}},
}, function(err, users) {
should.not.exist(err);
should.exist(users);
@ -313,9 +313,9 @@ describe('include', function () {
function(done) {
User.find({ include: [
{ relation: 'posts', scope: {
where: {title: 'Post A'}
where: { title: 'Post A' },
}},
'passports'
'passports',
] }, function(err, users) {
should.not.exist(err);
should.exist(users);
@ -423,7 +423,7 @@ describe('include', function () {
// fixed by DB optimization
it('should support include scope on hasAndBelongsToMany', function(done) {
Assembly.find({ include: { relation: 'parts', scope: {
where: { partNumber: 'engine' }
where: { partNumber: 'engine' },
}}}, function(err, assemblies) {
assemblies.length.should.equal(1);
var parts = assemblies[0].parts();
@ -435,7 +435,7 @@ describe('include', function () {
it('should save related items separately', function(done) {
User.find({
include: 'posts'
include: 'posts',
})
.then(function(users) {
var posts = users[0].posts();
@ -444,7 +444,7 @@ describe('include', function () {
})
.then(function(updatedUser) {
return User.findById(updatedUser.id, {
include: 'posts'
include: 'posts',
});
})
.then(function(user) {
@ -518,10 +518,10 @@ describe('include', function () {
Assembly.find({
where: {
name: {
inq: ['sedan', 'hatchback', 'SUV']
}
inq: ['sedan', 'hatchback', 'SUV'],
},
include: 'parts'
},
include: 'parts',
}, function(err, result) {
should.not.exist(err);
should.exists(result);
@ -584,7 +584,7 @@ describe('include', function () {
function(done) {
var self = this;
User.find({ include: [{ relation: 'posts', scope: {
where: {title: 'Post A'}
where: { title: 'Post A' },
}}, 'passports'] }, function(err, users) {
should.not.exist(err);
should.exist(users);
@ -627,19 +627,19 @@ function setup(done) {
Building = db.define('Building');
User = db.define('User', {
name: String,
age: Number
age: Number,
});
Profile = db.define('Profile', {
profileName: String
profileName: String,
});
AccessToken = db.define('AccessToken', {
token: String
token: String,
});
Passport = db.define('Passport', {
number: String
number: String,
});
Post = db.define('Post', {
title: String
title: String,
});
Passport.belongsTo('owner', { model: User });
@ -647,18 +647,18 @@ function setup(done) {
User.hasMany('posts', { foreignKey: 'userId' });
User.hasMany('accesstokens', {
foreignKey: 'userId',
options: {disableInclude: true}
options: { disableInclude: true },
});
Profile.belongsTo('user', { model: User });
User.hasOne('profile', { foreignKey: 'userId' });
Post.belongsTo('author', { model: User, foreignKey: 'userId' });
Assembly = db.define('Assembly', {
name: String
name: String,
});
Part = db.define('Part', {
partNumber: String
partNumber: String,
});
Assembly.hasAndBelongsToMany(Part);
@ -678,7 +678,7 @@ function setup(done) {
{ name: 'User B', age: 22 },
{ name: 'User C', age: 23 },
{ name: 'User D', age: 24 },
{name: 'User E', age: 25}
{ name: 'User E', age: 25 },
],
function(items) {
createdUsers = items;
@ -693,7 +693,7 @@ function setup(done) {
AccessToken,
[
{ token: '1', userId: createdUsers[0].id },
{token: '2', userId: createdUsers[1].id}
{ token: '2', userId: createdUsers[1].id },
],
function(items) {}
);
@ -721,10 +721,10 @@ function setup(done) {
[
{ profileName: 'Profile A', userId: createdUsers[0].id },
{ profileName: 'Profile B', userId: createdUsers[1].id },
{profileName: 'Profile Z'}
{ profileName: 'Profile Z' },
],
function(items) {
createdProfiles = items
createdProfiles = items;
done();
}
);
@ -738,7 +738,7 @@ function setup(done) {
{ title: 'Post B', userId: createdUsers[0].id },
{ title: 'Post C', userId: createdUsers[0].id },
{ title: 'Post D', userId: createdUsers[1].id },
{title: 'Post E'}
{ title: 'Post E' },
],
function(items) {
createdPosts = items;
@ -778,35 +778,35 @@ describe('Model instance with included relation .toJSON()', function() {
db = new DataSource({ connector: 'memory' });
ChallengerModel = db.createModel('Challenger',
{
name: String
name: String,
},
{
relations: {
gameParticipations: {
type: 'hasMany',
model: 'GameParticipation',
foreignKey: ''
}
}
foreignKey: '',
},
},
}
);
GameParticipationModel = db.createModel('GameParticipation',
{
date: Date
date: Date,
},
{
relations: {
challenger: {
type: 'belongsTo',
model: 'Challenger',
foreignKey: ''
foreignKey: '',
},
results: {
type: 'hasMany',
model: 'Result',
foreignKey: ''
}
}
foreignKey: '',
},
},
}
);
ResultModel = db.createModel('Result', {
@ -816,9 +816,9 @@ describe('Model instance with included relation .toJSON()', function() {
gameParticipation: {
type: 'belongsTo',
model: 'GameParticipation',
foreignKey: ''
}
}
foreignKey: '',
},
},
});
async.waterfall([
@ -838,14 +838,14 @@ describe('Model instance with included relation .toJSON()', function() {
function createGameParticipations(challengers, callback) {
GameParticipationModel.create([
{ challengerId: challengers[0].id, date: Date.now() },
{challengerId: challengers[0].id, date: Date.now()}
{ challengerId: challengers[0].id, date: Date.now() },
], callback);
}
function createResults(gameParticipations, callback) {
ResultModel.create([
{ gameParticipationId: gameParticipations[0].id, points: 10 },
{gameParticipationId: gameParticipations[0].id, points: 20}
{ gameParticipationId: gameParticipations[0].id, points: 20 },
], callback);
}

View File

@ -3,44 +3,44 @@
// This file is licensed under the MIT License.
// License text available at https://opensource.org/licenses/MIT
var assert = require("assert");
var should = require("should");
var assert = require('assert');
var should = require('should');
var includeUtils = require("../lib/include_utils");
var includeUtils = require('../lib/include_utils');
describe('include_util', function() {
describe('#buildOneToOneIdentityMapWithOrigKeys', function() {
it('should return an object with keys', function() {
var objs = [
{id: 11, letter: "A"},
{id: 22, letter: "B"}
{ id: 11, letter: 'A' },
{ id: 22, letter: 'B' },
];
var result = includeUtils.buildOneToOneIdentityMapWithOrigKeys(objs, "id");
var result = includeUtils.buildOneToOneIdentityMapWithOrigKeys(objs, 'id');
result.get(11).should.be.ok;
result.get(22).should.be.ok;
});
it('should overwrite keys in case of collision', function() {
var objs = [
{id: 11, letter: "A"},
{id: 22, letter: "B"},
{id: 33, letter: "C"},
{id: 11, letter: "HA!"}
{ id: 11, letter: 'A' },
{ id: 22, letter: 'B' },
{ id: 33, letter: 'C' },
{ id: 11, letter: 'HA!' },
];
var result = includeUtils.buildOneToOneIdentityMapWithOrigKeys(objs, "id");
var result = includeUtils.buildOneToOneIdentityMapWithOrigKeys(objs, 'id');
result.getKeys().should.containEql(11);
result.getKeys().should.containEql(22);
result.getKeys().should.containEql(33);
result.get(11)["letter"].should.equal("HA!");
result.get(33)["letter"].should.equal("C");
result.get(11)['letter'].should.equal('HA!');
result.get(33)['letter'].should.equal('C');
});
});
describe('#buildOneToOneIdentityMapWithOrigKeys', function() {
it('should return an object with keys', function() {
var objs = [
{id: 11, letter: "A"},
{id: 22, letter: "B"}
{ id: 11, letter: 'A' },
{ id: 22, letter: 'B' },
];
var result = includeUtils.buildOneToOneIdentityMapWithOrigKeys(objs, 'id');
result.get(11).should.be.ok;
@ -51,26 +51,26 @@ describe('include_util', function(){
describe('#buildOneToManyIdentityMap', function() {
it('should return an object with keys', function() {
var objs = [
{id: 11, letter: "A"},
{id: 22, letter: "B"}
{ id: 11, letter: 'A' },
{ id: 22, letter: 'B' },
];
var result = includeUtils.buildOneToManyIdentityMapWithOrigKeys(objs, "id");
var result = includeUtils.buildOneToManyIdentityMapWithOrigKeys(objs, 'id');
result.exist(11).should.be.true;
result.exist(22).should.be.true;
});
it('should collect keys in case of collision', function() {
var objs = [
{fk_id: 11, letter: "A"},
{fk_id: 22, letter: "B"},
{fk_id: 33, letter: "C"},
{fk_id: 11, letter: "HA!"}
{ fk_id: 11, letter: 'A' },
{ 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");
result.get(11)[1]["letter"].should.equal("HA!");
result.get(33)[0]["letter"].should.equal("C");
var result = includeUtils.buildOneToManyIdentityMapWithOrigKeys(objs, 'fk_id');
result.get(11)[0]['letter'].should.equal('A');
result.get(11)[1]['letter'].should.equal('HA!');
result.get(33)[0]['letter'].should.equal('C');
});
});
});

View File

@ -19,14 +19,14 @@ var json = {
city: 'San Jose',
state: 'CA',
zipcode: '95131',
country: 'US'
country: 'US',
},
friends: ['John', 'Mary'],
emails: [
{ label: 'work', id: 'x@sample.com' },
{label: 'home', id: 'x@home.com'}
{ label: 'home', id: 'x@home.com' },
],
tags: []
tags: [],
};
describe('Introspection of model definitions from JSON', function() {

View File

@ -22,7 +22,7 @@ describe('JSON property', function () {
it('should accept JSON in constructor and return object', function() {
var m = new Model({
propertyName: '{"foo": "bar"}'
propertyName: '{"foo": "bar"}',
});
m.propertyName.should.be.an.Object;
m.propertyName.foo.should.equal('bar');
@ -30,7 +30,7 @@ describe('JSON property', function () {
it('should accept object in setter and return object', function() {
var m = new Model;
m.propertyName = {"foo": "bar"};
m.propertyName = { 'foo': 'bar' };
m.propertyName.should.be.an.Object;
m.propertyName.foo.should.equal('bar');
});

View File

@ -22,7 +22,7 @@ describe('ModelBuilder define model', function () {
bio: ModelBuilder.Text,
approved: Boolean,
joinedAt: Date,
age: Number
age: Number,
});
// define any custom method
@ -169,15 +169,15 @@ describe('ModelBuilder define model', function () {
city: String,
state: String,
zipCode: String,
country: String
country: String,
},
emails: [
{
label: String,
email: String
}
email: String,
},
],
friends: [String]
friends: [String],
});
// define any custom method
@ -192,9 +192,9 @@ describe('ModelBuilder define model', function () {
name: 'Joe', age: 20,
address: { street: '123 Main St', 'city': 'San Jose', state: 'CA' },
emails: [
{label: 'work', email: 'xyz@sample.com'}
{ label: 'work', email: 'xyz@sample.com' },
],
friends: ['Mary', 'John']
friends: ['Mary', 'John'],
});
User.modelName.should.equal('User');
@ -234,7 +234,7 @@ describe('ModelBuilder define model', function () {
city: String,
state: String,
zipCode: String,
country: String
country: String,
});
user = new User({ name: 'Joe', address: { street: '123 Main St', 'city': 'San Jose', state: 'CA' }});
@ -253,7 +253,7 @@ describe('ModelBuilder define model', function () {
var Follow = modelBuilder.define('Follow', {
followerId: { type: String, id: 1 },
followeeId: { type: String, id: 2 },
followAt: Date
followAt: Date,
});
var follow = new Follow({ followerId: 1, followeeId: 2 });
@ -272,7 +272,7 @@ describe('DataSource ping', function() {
};
ds.connector.ping = function(cb) {
cb(new Error('bad connection 2'));
}
};
it('should report connection errors during ping', function(done) {
ds.ping(function(err) {
@ -285,7 +285,7 @@ describe('DataSource ping', function() {
it('should cancel invocation after timeout', function(done) {
ds.connected = false; // Force connect
var Post = ds.define('Post', {
title: { type: String, length: 255 }
title: { type: String, length: 255 },
});
Post.create(function(err) {
(!!err).should.be.true;
@ -307,7 +307,7 @@ describe('DataSource define model', function () {
return new Date();
} },
timestamp: { type: Number, default: Date.now },
published: { type: Boolean, default: false, index: true }
published: { type: Boolean, default: false, index: true },
});
// simpler way to describe model
@ -316,7 +316,7 @@ describe('DataSource define model', function () {
bio: ModelBuilder.Text,
approved: Boolean,
joinedAt: { type: Date, default: Date },
age: Number
age: Number,
});
var Group = ds.define('Group', { group: String });
@ -382,7 +382,7 @@ describe('DataSource define model', function () {
var modelBuilder = new ModelBuilder();
var Color = modelBuilder.define('Color', {
name: String
name: String,
});
Color.should.not.have.property('create');
@ -406,7 +406,7 @@ describe('DataSource define model', function () {
var modelBuilder = new ModelBuilder();
var User = modelBuilder.define('User', {
name: String
name: String,
});
var seq = 0;
@ -583,7 +583,7 @@ describe('DataSource define model', function () {
var ds = new DataSource('memory');// define models
Post = ds.define('Post', {
title: { type: String, length: 255, index: true },
content: { type: String }
content: { type: String },
});
Post.create({ title: 'a', content: 'AAA' }, function(err, post) {
@ -643,7 +643,7 @@ describe('DataSource define model', function () {
var ds = new DataSource('memory');
var User = ds.define('User', { name: String, bio: String }, {
http: { path: 'accounts' }
http: { path: 'accounts' },
});
User.http.path.should.equal('/accounts');
});
@ -652,7 +652,7 @@ describe('DataSource define model', function () {
var ds = new DataSource('memory');
var User = ds.define('User', { name: String, bio: String }, {
http: { path: '/accounts' }
http: { path: '/accounts' },
});
User.http.path.should.equal('/accounts');
});
@ -766,7 +766,7 @@ describe('Models attached to a dataSource', function() {
Post = ds.define('Post', {
title: { type: String, length: 255, index: true },
content: { type: String },
comments: [String]
comments: [String],
});
});
@ -956,7 +956,7 @@ describe('DataSource constructor', function () {
return null;
}
return {
name: name
name: name,
};
};
@ -1053,10 +1053,10 @@ describe('Load models with relations', function () {
var ds = new DataSource('memory');
var Author = ds.define('Author', { name: String }, { relations: {
pictures: {type: 'hasMany', model: 'Picture', polymorphic: 'imageable'}
pictures: { type: 'hasMany', model: 'Picture', polymorphic: 'imageable' },
}});
var Picture = ds.define('Picture', { name: String }, { relations: {
imageable: {type: 'belongsTo', polymorphic: true}
imageable: { type: 'belongsTo', polymorphic: true },
}});
assert(Author.relations['pictures']);
@ -1071,8 +1071,8 @@ describe('Load models with relations', function () {
polymorphic: {
as: 'imageable',
foreignKey: 'imageableId',
discriminator: 'imageableType'
}
discriminator: 'imageableType',
},
});
assert(Picture.relations['imageable']);
@ -1087,8 +1087,8 @@ describe('Load models with relations', function () {
polymorphic: {
as: 'imageable',
foreignKey: 'imageableId',
discriminator: 'imageableType'
}
discriminator: 'imageableType',
},
});
done();
});
@ -1126,7 +1126,7 @@ describe('Load models with relations', function () {
keyFrom: 'userId',
modelTo: 'User',
keyTo: 'id',
multiple: false
multiple: false,
});
assert(User.relations['posts']);
assert.deepEqual(User.relations['posts'].toJSON(), {
@ -1136,7 +1136,7 @@ describe('Load models with relations', function () {
keyFrom: 'id',
modelTo: 'Post',
keyTo: 'userId',
multiple: true
multiple: true,
});
assert(User.relations['accounts']);
assert.deepEqual(User.relations['accounts'].toJSON(), {
@ -1146,7 +1146,7 @@ describe('Load models with relations', function () {
keyFrom: 'id',
modelTo: 'Account',
keyTo: 'userId',
multiple: true
multiple: true,
});
done();
@ -1181,11 +1181,11 @@ describe('Load models with relations', function () {
it('should handle hasMany through', function(done) {
var ds = new DataSource('memory');
var Physician = ds.createModel('Physician', {
name: String
name: String,
}, { relations: { patients: { model: 'Patient', type: 'hasMany', through: 'Appointment' }}});
var Patient = ds.createModel('Patient', {
name: String
name: String,
}, { relations: { physicians: { model: 'Physician', type: 'hasMany', through: 'Appointment' }}});
assert(!Physician.relations['patients']); // Appointment hasn't been resolved yet
@ -1194,7 +1194,7 @@ describe('Load models with relations', function () {
var Appointment = ds.createModel('Appointment', {
physicianId: Number,
patientId: Number,
appointmentDate: Date
appointmentDate: Date,
}, { relations: { patient: { type: 'belongsTo', model: 'Patient' }, physician: { type: 'belongsTo', model: 'Physician' }}});
assert(Physician.relations['patients']);
@ -1205,17 +1205,17 @@ 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
name: String,
}, { relations: { patients: { model: 'Patient', type: 'hasMany', foreignKey: 'leftId', through: 'Appointment' }}});
var Patient = ds.createModel('Patient', {
name: String
name: String,
}, { relations: { physicians: { model: 'Physician', type: 'hasMany', foreignKey: 'rightId', through: 'Appointment' }}});
var Appointment = ds.createModel('Appointment', {
physicianId: Number,
patientId: Number,
appointmentDate: Date
appointmentDate: Date,
}, { relations: { patient: { type: 'belongsTo', model: 'Patient' }, physician: { type: 'belongsTo', model: 'Physician' }}});
assert(Physician.relations['patients'].keyTo === 'leftId');
@ -1277,7 +1277,7 @@ describe('DataAccessObject', function () {
vip: Boolean,
date: Date,
location: 'GeoPoint',
scores: [Number]
scores: [Number],
});
});
@ -1383,7 +1383,7 @@ describe('DataAccessObject', function () {
try {
// The where clause cannot be an array
model._coerce([
{vip: true}
{ vip: true },
]);
} catch (err) {
error = err;
@ -1505,7 +1505,7 @@ describe('DataAccessObject', function () {
assert.deepEqual(filter, { filter: { x: null }}, 'Should nullify undefined');
ds.settings.normalizeUndefinedInQuery = 'throw';
(function(){ model._normalize({filter: { x: undefined }}) }).should.throw(/`undefined` in query/);
(function() { model._normalize({ filter: { x: undefined }}); }).should.throw(/`undefined` in query/);
});
it('should skip GeoPoint', function() {
@ -1614,7 +1614,7 @@ describe('Load models from json', function () {
bio: ModelBuilder.Text,
approved: Boolean,
joinedAt: Date,
age: Number
age: Number,
});
modelBuilder.defaultModelBaseClass = User;
@ -1631,7 +1631,7 @@ describe('Load models from json', function () {
bio: ModelBuilder.Text,
approved: Boolean,
joinedAt: Date,
age: Number
age: Number,
});
var Customer = modelBuilder.define('Customer',
@ -1647,7 +1647,7 @@ describe('Load models from json', function () {
bio: ModelBuilder.Text,
approved: Boolean,
joinedAt: Date,
age: Number
age: Number,
});
var Customer = User.extend('Customer', { customerId: { type: String, id: true }});
@ -1687,22 +1687,22 @@ describe('Load models from json', function () {
var modelBuilder = new ModelBuilder();
var User = modelBuilder.define('User', {
name: String
name: String,
}, {
defaultPermission: 'ALLOW',
acls: [
{
principalType: 'ROLE',
principalId: '$everyone',
permission: 'ALLOW'
}
permission: 'ALLOW',
},
],
relations: {
posts: {
type: 'hasMany',
model: 'Post'
}
}
model: 'Post',
},
},
});
var Customer = User.extend('Customer',
@ -1713,15 +1713,15 @@ describe('Load models from json', function () {
{
principalType: 'ROLE',
principalId: '$unauthenticated',
permission: 'DENY'
}
permission: 'DENY',
},
],
relations: {
orders: {
type: 'hasMany',
model: 'Order'
}
}
model: 'Order',
},
},
}
);
@ -1731,16 +1731,16 @@ describe('Load models from json', function () {
{
principalType: 'ROLE',
principalId: '$everyone',
permission: 'ALLOW'
}
permission: 'ALLOW',
},
],
relations: {
posts: {
type: 'hasMany',
model: 'Post'
}
model: 'Post',
},
strict: false
},
strict: false,
});
assert.deepEqual(Customer.settings, {
@ -1749,26 +1749,26 @@ describe('Load models from json', function () {
{
principalType: 'ROLE',
principalId: '$everyone',
permission: 'ALLOW'
permission: 'ALLOW',
},
{
principalType: 'ROLE',
principalId: '$unauthenticated',
permission: 'DENY'
}
permission: 'DENY',
},
],
relations: {
posts: {
type: 'hasMany',
model: 'Post'
model: 'Post',
},
orders: {
type: 'hasMany',
model: 'Order'
}
model: 'Order',
},
},
strict: false,
base: User
base: User,
});
done();
@ -1802,7 +1802,7 @@ describe('ModelBuilder options.models', function () {
var builder = new ModelBuilder();
var M1 = builder.define('M1');
var M2 = builder.define('M2', {}, { models: {
'M1': M1
'M1': M1,
}});
assert.equal(M2.M1, M1, 'M1 should be injected to M2');
@ -1812,7 +1812,7 @@ describe('ModelBuilder options.models', function () {
var builder = new ModelBuilder();
var M1 = builder.define('M1');
var M2 = builder.define('M2', {}, { models: {
'M1': 'M1'
'M1': 'M1',
}});
assert.equal(M2.M1, M1, 'M1 should be injected to M2');
@ -1822,7 +1822,7 @@ describe('ModelBuilder options.models', function () {
function() {
var builder = new ModelBuilder();
var M2 = builder.define('M2', {}, { models: {
'M1': 'M1'
'M1': 'M1',
}});
assert(M2.M1, 'M1 should be injected to M2');
assert(M2.M1.settings.unresolved, 'M1 is still a proxy');

View File

@ -23,7 +23,7 @@ describe('manipulation', function () {
married: Boolean,
age: { type: Number, index: true },
dob: Date,
createdAt: {type: Date, default: Date}
createdAt: { type: Date, default: Date },
}, { forceId: true, strict: true });
db.automigrate(['Person'], done);
@ -233,7 +233,7 @@ describe('manipulation', function () {
var batch = [
{ name: 'Shaltay' },
{ name: 'Boltay' },
{}
{},
];
Person.create(batch, function(e, ps) {
should.not.exist(e);
@ -269,7 +269,7 @@ describe('manipulation', function () {
var batch = [
{ name: 'A' },
{ name: 'B' },
undefined
undefined,
];
Person.create(batch, function(e, ps) {
should.not.exist(e);
@ -289,7 +289,7 @@ describe('manipulation', function () {
created.toObject().should.have.properties({
id: created.id,
name: 'a-name',
gender: undefined
gender: undefined,
});
Person.findById(created.id, function(err, found) {
@ -297,7 +297,7 @@ describe('manipulation', function () {
var result = found.toObject();
result.should.have.properties({
id: created.id,
name: 'a-name'
name: 'a-name',
});
// The gender can be null from a RDB
should.equal(result.gender, null);
@ -430,7 +430,7 @@ describe('manipulation', function () {
};
(function() {
p.save({
'throws': true
'throws': true,
});
}).should.throw(ValidationError);
});
@ -648,7 +648,7 @@ describe('manipulation', function () {
var fakeConnector = {
updateAttributes: function(model, id, data, options, cb) {
cb(new Error('Database Error'));
}
},
};
person.getConnector = function() { return fakeConnector; };
person.updateAttributes({ name: 'John' }, function(err, p) {
@ -699,7 +699,7 @@ describe('manipulation', function () {
instance.toObject().should.have.properties({
id: instance.id,
name: 'a-name',
gender: undefined
gender: undefined,
});
Person.updateOrCreate(
@ -709,7 +709,7 @@ describe('manipulation', function () {
var result = updated.toObject();
result.should.have.properties({
id: instance.id,
name: 'updated name'
name: 'updated name',
});
should.equal(result.gender, null);
done();
@ -737,7 +737,7 @@ describe('manipulation', function () {
Post = ds.define('Post', {
title: { type: String, length: 255, index: true },
content: { type: String },
comments: [String]
comments: [String],
});
ds.automigrate('Post', done);
});
@ -954,7 +954,7 @@ describe('manipulation', function () {
Post = ds.define('Post', {
title: { type: String, length: 255, index: true },
content: { type: String },
comments: [String]
comments: [String],
});
ds.automigrate('Post', done);
});
@ -1189,9 +1189,9 @@ describe('manipulation', function () {
beforeEach(function createTestData(done) {
Person.create([{
name: 'John'
name: 'John',
}, {
name: 'Jane'
name: 'Jane',
}], done);
});
@ -1347,7 +1347,7 @@ describe('manipulation', function () {
before(function(done) {
CustomModel = db.define('CustomModel1', {
createdAt: { type: Date, default: '$now' }
createdAt: { type: Date, default: '$now' },
});
db.automigrate('CustomModel1', done);
});
@ -1371,7 +1371,7 @@ describe('manipulation', function () {
before(function(done) {
CustomModel = db.define('CustomModel2', {
now: { type: String, default: '$now' }
now: { type: String, default: '$now' },
});
db.automigrate('CustomModel2', done);
});
@ -1393,7 +1393,7 @@ describe('manipulation', function () {
before(function(done) {
CustomModel = db.define('CustomModel3', {
now: { type: Date, defaultFn: 'now' }
now: { type: Date, defaultFn: 'now' },
});
db.automigrate('CustomModel3', done);
});
@ -1415,7 +1415,7 @@ describe('manipulation', function () {
before(function(done) {
CustomModel = db.define('CustomModel4', {
guid: { type: String, defaultFn: 'guid' }
guid: { type: String, defaultFn: 'guid' },
});
db.automigrate('CustomModel4', done);
});
@ -1434,7 +1434,7 @@ describe('manipulation', function () {
before(function(done) {
CustomModel = db.define('CustomModel5', {
guid: { type: String, defaultFn: 'uuid' }
guid: { type: String, defaultFn: 'uuid' },
});
db.automigrate('CustomModel5', done);
});
@ -1454,7 +1454,7 @@ describe('manipulation', function () {
before(function(done) {
CustomModel = db.define('CustomModel5', {
guid: { type: String, defaultFn: 'uuidv4' }
guid: { type: String, defaultFn: 'uuidv4' },
});
db.automigrate('CustomModel5', done);
});
@ -1554,19 +1554,19 @@ describe('manipulation', function () {
beforeEach(function createTestData(done) {
Person.create([{
name: 'Brett Boe',
age: 19
age: 19,
}, {
name: 'Carla Coe',
age: 20
age: 20,
}, {
name: 'Donna Doe',
age: 21
age: 21,
}, {
name: 'Frank Foe',
age: 22
age: 22,
}, {
name: 'Grace Goe',
age: 23
age: 23,
}], done);
});
@ -1654,13 +1654,13 @@ function givenSomePeople(done) {
{ name: 'George Harrison', gender: 'male' },
{ name: 'Ringo Starr', gender: 'male' },
{ name: 'Pete Best', gender: 'male' },
{ name: 'Stuart Sutcliffe', gender: 'male' }
{ name: 'Stuart Sutcliffe', gender: 'male' },
];
async.series([
Person.destroyAll.bind(Person),
function(cb) {
async.each(beatles, Person.create.bind(Person), cb);
}
},
], done);
}

View File

@ -36,20 +36,20 @@ describe('Memory connector', function() {
function createUserModel() {
var ds = new DataSource({
connector: 'memory',
file: file
file: file,
});
var User = ds.createModel('User', {
id: {
type: Number,
id: true,
generated: true
generated: true,
},
name: String,
bio: String,
approved: Boolean,
joinedAt: Date,
age: Number
age: Number,
});
return User;
}
@ -141,7 +141,7 @@ describe('Memory connector', function() {
describe('Query for memory connector', function() {
var ds = new DataSource({
connector: 'memory'
connector: 'memory',
});
var User = ds.define('User', {
@ -156,13 +156,13 @@ describe('Memory connector', function() {
street: String,
city: String,
state: String,
zipCode: String
zipCode: String,
},
friends: [
{
name: String
}
]
name: String,
},
],
});
before(seed);
@ -318,9 +318,9 @@ describe('Memory connector', function() {
User.find({
where: {
children: {
regexp: /an/
}
}
regexp: /an/,
},
},
}, function(err, users) {
should.not.exist(err);
users.length.should.be.equal(2);
@ -333,8 +333,8 @@ describe('Memory connector', function() {
it('should successfully extract 1 users matching over array values', function(done) {
User.find({
where: {
children: 'Dhani'
}
children: 'Dhani',
},
}, function(err, users) {
should.not.exist(err);
users.length.should.be.equal(1);
@ -346,8 +346,8 @@ describe('Memory connector', function() {
it('should successfully extract 5 users matching a neq filter over array values', function(done) {
User.find({
where: {
'children': {neq: 'Dhani'}
}
'children': { neq: 'Dhani' },
},
}, function(err, users) {
should.not.exist(err);
users.length.should.be.equal(5);
@ -531,14 +531,14 @@ describe('Memory connector', function() {
street: '123 A St',
city: 'San Jose',
state: 'CA',
zipCode: '95131'
zipCode: '95131',
},
friends: [
{ name: 'Paul McCartney' },
{ name: 'George Harrison' },
{ name: 'Ringo Starr' },
],
children: ['Sean', 'Julian']
children: ['Sean', 'Julian'],
},
{
seq: 1,
@ -552,26 +552,26 @@ describe('Memory connector', function() {
street: '456 B St',
city: 'San Mateo',
state: 'CA',
zipCode: '94065'
zipCode: '94065',
},
friends: [
{ name: 'John Lennon' },
{ name: 'George Harrison' },
{ name: 'Ringo Starr' },
],
children: ['Stella', 'Mary', 'Heather', 'Beatrice', 'James']
children: ['Stella', 'Mary', 'Heather', 'Beatrice', 'James'],
},
{ seq: 2, name: 'George Harrison', order: 5, vip: false, children: ['Dhani'] },
{ seq: 3, name: 'Ringo Starr', order: 6, vip: false },
{ seq: 4, name: 'Pete Best', order: 4, children: [] },
{seq: 5, name: 'Stuart Sutcliffe', order: 3, vip: true}
{ seq: 5, name: 'Stuart Sutcliffe', order: 3, vip: true },
];
async.series([
User.destroyAll.bind(User),
function(cb) {
async.each(beatles, User.create.bind(User), cb);
}
},
], done);
}
@ -579,19 +579,19 @@ describe('Memory connector', function() {
it('should use collection setting', function(done) {
var ds = new DataSource({
connector: 'memory'
connector: 'memory',
});
var Product = ds.createModel('Product', {
name: String
name: String,
});
var Tool = ds.createModel('Tool', {
name: String
name: String,
}, { memory: { collection: 'Product' }});
var Widget = ds.createModel('Widget', {
name: String
name: String,
}, { memory: { collection: 'Product' }});
ds.connector.getCollection('Tool').should.equal('Product');
@ -606,7 +606,7 @@ describe('Memory connector', function() {
},
function(next) {
Widget.create({ name: 'Widget A' }, next);
}
},
], function(err) {
Product.find(function(err, products) {
should.not.exist(err);
@ -623,11 +623,11 @@ describe('Memory connector', function() {
var ds;
beforeEach(function() {
ds = new DataSource({
connector: 'memory'
connector: 'memory',
});
ds.createModel('m1', {
name: String
name: String,
});
});
@ -704,7 +704,7 @@ describe('Memory connector', function() {
before(function() {
ds = new DataSource({ connector: 'memory' });
Cars = ds.define('Cars', {
color: String
color: String,
});
});
@ -735,14 +735,14 @@ describe('Memory connector', function() {
var ds;
beforeEach(function() {
ds = new DataSource({
connector: 'memory'
connector: 'memory',
});
});
it('automigrate does NOT report error when NO models are attached', function(done) {
ds.automigrate(function(err) {
done();
})
});
});
it('automigrate does NOT report error when NO models are attached - promise variant', function(done) {
@ -758,7 +758,7 @@ describe('Memory connector', function() {
var ds, model;
beforeEach(function() {
ds = new DataSource({
connector: 'memory'
connector: 'memory',
});
ds.connector.autoupdate = function(models, cb) {
@ -766,14 +766,14 @@ describe('Memory connector', function() {
};
model = ds.createModel('m1', {
name: String
name: String,
});
ds.automigrate();
ds.createModel('m1', {
name: String,
address: String
address: String,
});
});
@ -898,7 +898,7 @@ describe('Memory connector with options', function() {
Post = ds.define('Post', {
title: String,
content: String
content: String,
});
});
@ -947,7 +947,7 @@ describe('Memory connector with options', function() {
describe('Memory connector with observers', function() {
var ds = new DataSource({
connector: 'memory'
connector: 'memory',
});
it('should have observer mixed into the connector', function() {

View File

@ -65,12 +65,12 @@ describe('Model class', function () {
it('should apply a mixin class', function() {
var Address = modelBuilder.define('Address', {
street: { type: 'string', required: true },
city: { type: 'string', required: true }
city: { type: 'string', required: true },
});
var memory = new DataSource('mem', { connector: Memory }, modelBuilder);
var Item = memory.createModel('Item', { name: 'string' }, {
mixins: { Address: true }
mixins: { Address: true },
});
var properties = Item.definition.properties;
@ -86,9 +86,9 @@ describe('Model class', function () {
TimeStamp: true, Demo: { value: true },
Multi: [
{ key: 'foo', value: 'bar' },
{ key: 'fox', value: 'baz' }
]
}
{ key: 'fox', value: 'baz' },
],
},
});
Item.mixin('Example', { foo: 'bar' });
@ -117,7 +117,7 @@ describe('Model class', function () {
beforeEach(function() {
Address = modelBuilder.define('Address', {
street: { type: 'string', required: true },
city: { type: 'string', required: true }
city: { type: 'string', required: true },
});
var memory = new DataSource('mem', { connector: Memory }, modelBuilder);
Person = memory.createModel('Person', { name: 'string' });

View File

@ -24,11 +24,11 @@ describe('ModelDefinition class', function () {
var modelBuilder = new ModelBuilder();
var User = new ModelDefinition(modelBuilder, 'User', {
name: "string",
name: 'string',
bio: ModelBuilder.Text,
approved: Boolean,
joinedAt: Date,
age: "number"
age: 'number',
});
User.build();
@ -39,12 +39,12 @@ describe('ModelDefinition class', function () {
assert.equal(User.properties.age.type, Number);
var json = User.toJSON();
assert.equal(json.name, "User");
assert.equal(json.properties.name.type, "String");
assert.equal(json.properties.bio.type, "Text");
assert.equal(json.properties.approved.type, "Boolean");
assert.equal(json.properties.joinedAt.type, "Date");
assert.equal(json.properties.age.type, "Number");
assert.equal(json.name, 'User');
assert.equal(json.properties.name.type, 'String');
assert.equal(json.properties.bio.type, 'Text');
assert.equal(json.properties.approved.type, 'Boolean');
assert.equal(json.properties.joinedAt.type, 'Date');
assert.equal(json.properties.age.type, 'Number');
assert.deepEqual(User.toJSON(), json);
@ -56,18 +56,18 @@ describe('ModelDefinition class', function () {
var modelBuilder = new ModelBuilder();
var User = new ModelDefinition(modelBuilder, 'User', {
name: "string",
name: 'string',
bio: ModelBuilder.Text,
approved: Boolean,
joinedAt: Date,
age: "number"
age: 'number',
});
User.build();
var json = User.toJSON();
User.defineProperty("id", {type: "number", id: true});
User.defineProperty('id', { type: 'number', id: true });
assert.equal(User.properties.name.type, String);
assert.equal(User.properties.bio.type, ModelBuilder.Text);
assert.equal(User.properties.approved.type, Boolean);
@ -96,8 +96,8 @@ describe('ModelDefinition class', function () {
street: String,
city: String,
zipCode: String,
state: String
}
state: String,
},
});
User.build();
@ -109,12 +109,12 @@ describe('ModelDefinition class', function () {
assert.equal(typeof User.properties.address.type, 'function');
var json = User.toJSON();
assert.equal(json.name, "User");
assert.equal(json.properties.name.type, "String");
assert.equal(json.properties.bio.type, "Text");
assert.equal(json.properties.approved.type, "Boolean");
assert.equal(json.properties.joinedAt.type, "Date");
assert.equal(json.properties.age.type, "Number");
assert.equal(json.name, 'User');
assert.equal(json.properties.name.type, 'String');
assert.equal(json.properties.bio.type, 'Text');
assert.equal(json.properties.approved.type, 'Boolean');
assert.equal(json.properties.joinedAt.type, 'Date');
assert.equal(json.properties.age.type, 'Number');
assert.deepEqual(json.properties.address.type, { street: { type: 'String' },
city: { type: 'String' },
@ -132,7 +132,7 @@ describe('ModelDefinition class', function () {
street: String,
city: String,
zipCode: String,
state: String
state: String,
});
var User = new ModelDefinition(modelBuilder, 'User', {
name: String,
@ -140,7 +140,7 @@ describe('ModelDefinition class', function () {
approved: Boolean,
joinedAt: Date,
age: Number,
address: Address
address: Address,
});
@ -153,12 +153,12 @@ describe('ModelDefinition class', function () {
assert.equal(User.properties.address.type, Address);
var json = User.toJSON();
assert.equal(json.name, "User");
assert.equal(json.properties.name.type, "String");
assert.equal(json.properties.bio.type, "Text");
assert.equal(json.properties.approved.type, "Boolean");
assert.equal(json.properties.joinedAt.type, "Date");
assert.equal(json.properties.age.type, "Number");
assert.equal(json.name, 'User');
assert.equal(json.properties.name.type, 'String');
assert.equal(json.properties.bio.type, 'Text');
assert.equal(json.properties.approved.type, 'Boolean');
assert.equal(json.properties.joinedAt.type, 'Date');
assert.equal(json.properties.age.type, 'Number');
assert.equal(json.properties.address.type, 'Address');
@ -173,7 +173,7 @@ describe('ModelDefinition class', function () {
street: String,
city: String,
zipCode: String,
state: String
state: String,
});
var User = new ModelDefinition(modelBuilder, 'User', {
name: String,
@ -181,7 +181,7 @@ describe('ModelDefinition class', function () {
approved: Boolean,
joinedAt: Date,
age: Number,
address: 'Address'
address: 'Address',
});
@ -194,12 +194,12 @@ describe('ModelDefinition class', function () {
assert.equal(User.properties.address.type, Address);
var json = User.toJSON();
assert.equal(json.name, "User");
assert.equal(json.properties.name.type, "String");
assert.equal(json.properties.bio.type, "Text");
assert.equal(json.properties.approved.type, "Boolean");
assert.equal(json.properties.joinedAt.type, "Date");
assert.equal(json.properties.age.type, "Number");
assert.equal(json.name, 'User');
assert.equal(json.properties.name.type, 'String');
assert.equal(json.properties.bio.type, 'Text');
assert.equal(json.properties.approved.type, 'Boolean');
assert.equal(json.properties.joinedAt.type, 'Date');
assert.equal(json.properties.age.type, 'Number');
assert.equal(json.properties.address.type, 'Address');
@ -212,11 +212,11 @@ describe('ModelDefinition class', function () {
var User = new ModelDefinition(modelBuilder, 'User', {
userId: { type: String, id: true },
name: "string",
name: 'string',
bio: ModelBuilder.Text,
approved: Boolean,
joinedAt: Date,
age: "number"
age: 'number',
});
assert.equal(User.idName(), 'userId');
@ -230,11 +230,11 @@ describe('ModelDefinition class', function () {
var User = new ModelDefinition(modelBuilder, 'User', {
userId: { type: String, id: 2 },
userType: { type: String, id: 1 },
name: "string",
name: 'string',
bio: ModelBuilder.Text,
approved: Boolean,
joinedAt: Date,
age: "number"
age: 'number',
});
var ids = User.ids();
@ -251,7 +251,7 @@ describe('ModelDefinition class', function () {
var User = new ModelDefinition(modelBuilder, 'User', {
userId: { type: String, id: true, oracle: { column: 'ID' }},
name: "string"
name: 'string',
}, { oracle: { table: 'USER' }});
assert.equal(User.tableName('oracle'), 'USER');
@ -267,9 +267,9 @@ describe('ModelDefinition class', function () {
relations: {
children: {
type: 'hasMany',
model: 'anotherChild'
}
}
model: 'anotherChild',
},
},
});
var baseChild = modelBuilder.define('baseChild');
baseChild.attachTo(memory);
@ -301,14 +301,14 @@ describe('ModelDefinition class', function () {
it('should serialize protected properties into JSON', function() {
var modelBuilder = memory.modelBuilder;
var ProtectedModel = memory.createModel('protected', {}, {
protected: ['protectedProperty']
protected: ['protectedProperty'],
});
var pm = new ProtectedModel({
id: 1, foo: 'bar', protectedProperty: 'protected'
id: 1, foo: 'bar', protectedProperty: 'protected',
});
var serialized = pm.toJSON();
assert.deepEqual(serialized, {
id: 1, foo: 'bar', protectedProperty: 'protected'
id: 1, foo: 'bar', protectedProperty: 'protected',
});
});
@ -318,11 +318,11 @@ describe('ModelDefinition class', function () {
var Child = memory.createModel('child', {}, { protected: ['protectedProperty'] });
Parent.hasMany(Child);
Parent.create({
name: 'parent'
name: 'parent',
}, function(err, parent) {
parent.children.create({
name: 'child',
protectedProperty: 'protectedValue'
protectedProperty: 'protectedValue',
}, function(err, child) {
Parent.find({ include: 'children' }, function(err, parents) {
var serialized = parents[0].toJSON();
@ -338,17 +338,17 @@ describe('ModelDefinition class', function () {
it('should not serialize hidden properties into JSON', function() {
var modelBuilder = memory.modelBuilder;
var HiddenModel = memory.createModel('hidden', {}, {
hidden: ['secret']
hidden: ['secret'],
});
var hm = new HiddenModel({
id: 1,
foo: 'bar',
secret: 'secret'
secret: 'secret',
});
var serialized = hm.toJSON();
assert.deepEqual(serialized, {
id: 1,
foo: 'bar'
foo: 'bar',
});
});
@ -358,11 +358,11 @@ describe('ModelDefinition class', function () {
var Child = memory.createModel('child', {}, { hidden: ['secret'] });
Parent.hasMany(Child);
Parent.create({
name: 'parent'
name: 'parent',
}, function(err, parent) {
parent.children.create({
name: 'child',
secret: 'secret'
secret: 'secret',
}, function(err, child) {
Parent.find({ include: 'children' }, function(err, parents) {
var serialized = parents[0].toJSON();
@ -399,7 +399,7 @@ describe('ModelDefinition class', function () {
it('should support "array" type shortcut', function() {
var Model = memory.createModel('TwoArrays', {
regular: Array,
sugar: 'array'
sugar: 'array',
});
var props = Model.definition.properties;
@ -411,11 +411,11 @@ describe('ModelDefinition class', function () {
var Todo;
before(function prepModel() {
Todo = new ModelDefinition(new ModelBuilder(), 'Todo', {
content: 'string'
content: 'string',
});
Todo.defineProperty('id', {
type: 'number',
id: true
id: true,
});
Todo.build();
});
@ -429,7 +429,7 @@ describe('ModelDefinition class', function () {
var Todo;
before(function prepModel() {
Todo = new ModelDefinition(new ModelBuilder(), 'Todo', {
content: 'string'
content: 'string',
});
Todo.build();
});

View File

@ -30,7 +30,7 @@ describe('optional-validation', function () {
birthday: { type: Date, index: true },
role: { type: String, index: true },
order: { type: Number, index: true, sort: true },
vip: {type: Boolean}
vip: { type: Boolean },
}, { forceId: true, strict: true });
db.automigrate(['ModelWithForceId', 'User'], done);
});
@ -136,7 +136,6 @@ describe('optional-validation', function () {
});
});
describe('no model setting', function() {
describe('method create', function() {

View File

@ -36,7 +36,7 @@ module.exports = function(dataSource, should, connectorCapabilities) {
// Set id.generated to false to honor client side values
id: { type: String, id: true, generated: false, default: uid.next },
name: { type: String, required: true },
extra: { type: String, required: false }
extra: { type: String, required: false },
});
uid.reset();
@ -79,7 +79,7 @@ module.exports = function(dataSource, should, connectorCapabilities) {
hookMonitor.names.should.eql([
'access',
'loaded'
'loaded',
]);
done();
});
@ -165,7 +165,7 @@ module.exports = function(dataSource, should, connectorCapabilities) {
}));
done();
});
})
});
it('emits error when `loaded` hook fails', function(done) {
TestModel.observe('loaded', nextWithError(expectedError));
@ -191,7 +191,7 @@ module.exports = function(dataSource, should, connectorCapabilities) {
'before save',
'persist',
'loaded',
'after save'
'after save',
]);
done();
});
@ -206,9 +206,9 @@ module.exports = function(dataSource, should, connectorCapabilities) {
instance: {
id: instance.id,
name: 'created',
extra: undefined
extra: undefined,
},
isNewInstance: true
isNewInstance: true,
}));
done();
});
@ -251,11 +251,11 @@ module.exports = function(dataSource, should, connectorCapabilities) {
ctxRecorder.records.should.eql([
aCtxForModel(TestModel, {
instance: { id: list[0].id, name: '1', extra: undefined },
isNewInstance: true
isNewInstance: true,
}),
aCtxForModel(TestModel, {
instance: { id: list[1].id, name: '2', extra: undefined },
isNewInstance: true
isNewInstance: true,
}),
]);
done();
@ -283,7 +283,7 @@ module.exports = function(dataSource, should, connectorCapabilities) {
ctxRecorder.records.should.eql(aCtxForModel(TestModel, {
data: { id: 'new-id', name: 'a name' },
isNewInstance: true,
currentInstance: { extra: null, id: 'new-id', name: 'a name' }
currentInstance: { extra: null, id: 'new-id', name: 'a name' },
}));
done();
@ -315,7 +315,7 @@ module.exports = function(dataSource, should, connectorCapabilities) {
dbInstance.toObject(true).should.eql({
id: 'new-id',
name: 'a name',
extra: 'hook data'
extra: 'hook data',
});
done();
});
@ -338,7 +338,7 @@ module.exports = function(dataSource, should, connectorCapabilities) {
ctxRecorder.records.should.eql(aCtxForModel(TestModel, {
data: { id: 'new-id', name: 'a name' },
isNewInstance: true
isNewInstance: true,
}));
done();
@ -384,9 +384,9 @@ module.exports = function(dataSource, should, connectorCapabilities) {
instance: {
id: instance.id,
name: 'created',
extra: undefined
extra: undefined,
},
isNewInstance: true
isNewInstance: true,
}));
done();
});
@ -429,11 +429,11 @@ module.exports = function(dataSource, should, connectorCapabilities) {
ctxRecorder.records.should.eql([
aCtxForModel(TestModel, {
instance: { id: list[0].id, name: '1', extra: undefined },
isNewInstance: true
isNewInstance: true,
}),
aCtxForModel(TestModel, {
instance: { id: list[1].id, name: '2', extra: undefined },
isNewInstance: true
isNewInstance: true,
}),
]);
done();
@ -463,7 +463,7 @@ module.exports = function(dataSource, should, connectorCapabilities) {
ctxRecorder.records.should.eql(aCtxForModel(TestModel, {
instance: { id: list[0].id, name: 'ok', extra: undefined },
isNewInstance: true
isNewInstance: true,
}));
done();
});
@ -483,7 +483,7 @@ module.exports = function(dataSource, should, connectorCapabilities) {
where: { name: 'new-record' },
limit: 1,
offset: 0,
skip: 0
skip: 0,
}}));
done();
});
@ -503,9 +503,9 @@ module.exports = function(dataSource, should, connectorCapabilities) {
instance: {
id: getLastGeneratedUid(),
name: existingInstance.name,
extra: undefined
extra: undefined,
},
isNewInstance: true
isNewInstance: true,
}));
done();
});
@ -524,9 +524,9 @@ module.exports = function(dataSource, should, connectorCapabilities) {
instance: {
id: record.id,
name: 'new-record',
extra: undefined
extra: undefined,
},
isNewInstance: true
isNewInstance: true,
}));
done();
});
@ -558,7 +558,7 @@ module.exports = function(dataSource, should, connectorCapabilities) {
'before save',
'persist',
'loaded',
'after save'
'after save',
]);
done();
});
@ -578,12 +578,12 @@ module.exports = function(dataSource, should, connectorCapabilities) {
'access',
'before save',
'persist',
'loaded'
'loaded',
]);
} else {
hookMonitor.names.should.eql([
'access',
'loaded'
'loaded',
]);
}
done();
@ -635,15 +635,15 @@ module.exports = function(dataSource, should, connectorCapabilities) {
ctxRecorder.records.should.eql(aCtxForModel(TestModel, {
data: {
id: getLastGeneratedUid(),
name: existingInstance.name
name: existingInstance.name,
},
isNewInstance: true,
currentInstance: {
id: getLastGeneratedUid(),
name: record.name,
extra: null
extra: null,
},
where: { name: existingInstance.name }
where: { name: existingInstance.name },
}));
done();
@ -666,24 +666,24 @@ module.exports = function(dataSource, should, connectorCapabilities) {
ctxRecorder.records.should.eql(aCtxForModel(TestModel, {
data: {
id: record.id,
name: 'new-record'
name: 'new-record',
},
isNewInstance: true,
currentInstance: {
id: record.id,
name: record.name,
extra: null
extra: null,
},
where: { name: 'new-record' }
where: { name: 'new-record' },
}));
} else {
ctxRecorder.records.should.eql(aCtxForModel(TestModel, {
data: {
id: record.id,
name: 'new-record'
name: 'new-record',
},
isNewInstance: true,
currentInstance: { id: record.id, name: record.name, extra: null }
currentInstance: { id: record.id, name: record.name, extra: null },
}));
}
done();
@ -715,7 +715,7 @@ module.exports = function(dataSource, should, connectorCapabilities) {
dbInstance.toObject(true).should.eql({
id: existingInstance.id,
name: existingInstance.name,
extra: undefined
extra: undefined,
});
});
@ -753,7 +753,7 @@ module.exports = function(dataSource, should, connectorCapabilities) {
dbInstance.toObject(true).should.eql({
id: instance.id,
name: instance.name,
extra: 'hook data'
extra: 'hook data',
});
});
}
@ -779,9 +779,9 @@ module.exports = function(dataSource, should, connectorCapabilities) {
ctxRecorder.records.should.eql(aCtxForModel(TestModel, {
data: {
id: existingInstance.id,
name: existingInstance.name
name: existingInstance.name,
},
isNewInstance: false
isNewInstance: false,
}));
done();
@ -801,9 +801,9 @@ module.exports = function(dataSource, should, connectorCapabilities) {
ctxRecorder.records.should.eql(aCtxForModel(TestModel, {
data: {
id: record.id,
name: 'new-record'
name: 'new-record',
},
isNewInstance: true
isNewInstance: true,
}));
done();
@ -876,9 +876,9 @@ module.exports = function(dataSource, should, connectorCapabilities) {
instance: {
id: instance.id,
name: 'new name',
extra: undefined
extra: undefined,
},
isNewInstance: true
isNewInstance: true,
}));
done();
});
@ -936,7 +936,7 @@ module.exports = function(dataSource, should, connectorCapabilities) {
'before save',
'persist',
'loaded',
'after save'
'after save',
]);
done();
});
@ -1003,14 +1003,14 @@ module.exports = function(dataSource, should, connectorCapabilities) {
ctxRecorder.records.should.eql(aCtxForModel(TestModel, {
data: {
id: existingInstance.id,
name: 'changed'
name: 'changed',
},
currentInstance: {
id: existingInstance.id,
name: 'changed'
name: 'changed',
},
where: { id: existingInstance.id },
options: { throws: false, validate: true }
options: { throws: false, validate: true },
}));
done();
@ -1043,7 +1043,7 @@ module.exports = function(dataSource, should, connectorCapabilities) {
extra: 'changed',
},
isNewInstance: false,
options: { throws: false, validate: true }
options: { throws: false, validate: true },
}));
done();
@ -1081,10 +1081,10 @@ module.exports = function(dataSource, should, connectorCapabilities) {
instance: {
id: existingInstance.id,
name: 'changed',
extra: undefined
extra: undefined,
},
isNewInstance: false,
options: { throws: false, validate: true }
options: { throws: false, validate: true },
}));
done();
});
@ -1103,10 +1103,10 @@ module.exports = function(dataSource, should, connectorCapabilities) {
instance: {
id: instance.id,
name: 'created',
extra: undefined
extra: undefined,
},
isNewInstance: true,
options: { throws: false, validate: true }
options: { throws: false, validate: true },
}));
done();
});
@ -1148,7 +1148,7 @@ module.exports = function(dataSource, should, connectorCapabilities) {
'before save',
'persist',
'loaded',
'after save'
'after save',
]);
done();
});
@ -1165,7 +1165,7 @@ module.exports = function(dataSource, should, connectorCapabilities) {
ctxRecorder.records.should.eql(aCtxForModel(TestModel, {
where: { id: existingInstance.id },
data: { name: 'changed' },
currentInstance: currentInstance
currentInstance: currentInstance,
}));
done();
});
@ -1197,7 +1197,7 @@ module.exports = function(dataSource, should, connectorCapabilities) {
instance.toObject(true).should.eql({
id: existingInstance.id,
name: 'hooked name',
extra: 'extra data'
extra: 'extra data',
});
done();
});
@ -1225,9 +1225,9 @@ module.exports = function(dataSource, should, connectorCapabilities) {
currentInstance: {
id: existingInstance.id,
name: 'changed',
extra: null
extra: null,
},
isNewInstance: false
isNewInstance: false,
}));
done();
@ -1255,14 +1255,14 @@ module.exports = function(dataSource, should, connectorCapabilities) {
var Address = dataSource.createModel('NestedAddress', {
id: { type: String, id: true, default: 1 },
city: { type: String, required: true },
country: { type: String, required: true }
country: { type: String, required: true },
});
var User = dataSource.createModel('UserWithAddress', {
id: { type: String, id: true, default: uid.next },
name: { type: String, required: true },
address: { type: Address, required: false },
extra: {type: String}
extra: { type: String },
});
dataSource.automigrate(['UserWithAddress', 'NestedAddress'], function(err) {
@ -1298,7 +1298,7 @@ module.exports = function(dataSource, should, connectorCapabilities) {
id: existingUser.id,
name: existingUser.name,
address: { id: '1', city: 'Springfield', country: 'USA' },
extra: 'hook data'
extra: 'hook data',
});
done();
});
@ -1357,9 +1357,9 @@ module.exports = function(dataSource, should, connectorCapabilities) {
instance: {
id: existingInstance.id,
name: 'changed',
extra: undefined
extra: undefined,
},
isNewInstance: false
isNewInstance: false,
}));
done();
});
@ -1404,7 +1404,7 @@ module.exports = function(dataSource, should, connectorCapabilities) {
'before save',
'persist',
'loaded',
'after save'
'after save',
]);
done();
});
@ -1421,7 +1421,7 @@ module.exports = function(dataSource, should, connectorCapabilities) {
name: 'changed',
extra: undefined,
},
isNewInstance: false
isNewInstance: false,
}));
done();
});
@ -1451,7 +1451,7 @@ module.exports = function(dataSource, should, connectorCapabilities) {
instance.toObject(true).should.eql({
id: existingInstance.id,
name: 'hooked name',
extra: 'extra data'
extra: 'extra data',
});
done();
});
@ -1477,14 +1477,14 @@ module.exports = function(dataSource, should, connectorCapabilities) {
where: { id: existingInstance.id },
data: {
name: 'replacedName',
id: existingInstance.id
id: existingInstance.id,
},
currentInstance: {
id: existingInstance.id,
name: 'replacedName',
extra: null
extra: null,
},
isNewInstance: false
isNewInstance: false,
}));
done();
@ -1507,14 +1507,14 @@ module.exports = function(dataSource, should, connectorCapabilities) {
var Address = dataSource.createModel('NestedAddress', {
id: { type: String, id: true, default: 1 },
city: { type: String, required: true },
country: { type: String, required: true }
country: { type: String, required: true },
});
var User = dataSource.createModel('UserWithAddress', {
id: { type: String, id: true, default: uid.next },
name: { type: String, required: true },
address: { type: Address, required: false },
extra: {type: String}
extra: { type: String },
});
dataSource.automigrate(['UserWithAddress', 'NestedAddress'], function(err) {
@ -1545,7 +1545,7 @@ module.exports = function(dataSource, should, connectorCapabilities) {
id: existingUser.id,
name: 'John',
address: { id: '1', city: 'Springfield', country: 'USA' },
extra: 'hook data'
extra: 'hook data',
});
done();
});
@ -1562,9 +1562,9 @@ module.exports = function(dataSource, should, connectorCapabilities) {
ctxRecorder.records.should.eql(aCtxForModel(TestModel, {
data: {
name: 'changed',
id: data.id
id: data.id,
},
isNewInstance : false
isNewInstance : false,
}));
done();
});
@ -1602,9 +1602,9 @@ module.exports = function(dataSource, should, connectorCapabilities) {
instance: {
id: existingInstance.id,
name: 'replaced',
extra: undefined
extra: undefined,
},
isNewInstance: false
isNewInstance: false,
}));
done();
});
@ -1648,7 +1648,7 @@ module.exports = function(dataSource, should, connectorCapabilities) {
'before save',
'persist',
'loaded',
'after save'
'after save',
]);
done();
});
@ -1667,7 +1667,7 @@ module.exports = function(dataSource, should, connectorCapabilities) {
'before save',
'persist',
'loaded',
'after save'
'after save',
]);
} else {
hookMonitor.names.should.eql([
@ -1676,7 +1676,7 @@ module.exports = function(dataSource, should, connectorCapabilities) {
'before save',
'persist',
'loaded',
'after save'
'after save',
]);
}
done();
@ -1737,7 +1737,7 @@ module.exports = function(dataSource, should, connectorCapabilities) {
if (err) return done(err);
(list || []).map(toObject).should.eql([
{ id: existingInstance.id, name: existingInstance.name, extra: undefined },
{ id: instance.id, name: 'new name', extra: undefined }
{ id: instance.id, name: 'new name', extra: undefined },
]);
done();
});
@ -1759,7 +1759,7 @@ module.exports = function(dataSource, should, connectorCapabilities) {
(list || []).map(toObject).should.eql([
{ id: existingInstance.id, name: existingInstance.name, extra: undefined },
{ id: list[1].id, name: 'second', extra: undefined },
{ id: instance.id, name: 'new name', extra: undefined }
{ id: instance.id, name: 'new name', extra: undefined },
]);
done();
});
@ -1796,7 +1796,7 @@ module.exports = function(dataSource, should, connectorCapabilities) {
// UPDATE or CREATE will be triggered
ctxRecorder.records.should.eql(aCtxForModel(TestModel, {
where: { id: existingInstance.id },
data: { id: existingInstance.id, name: 'updated name' }
data: { id: existingInstance.id, name: 'updated name' },
}));
} else {
// currentInstance is set, because a non-atomic `updateOrCreate`
@ -1805,7 +1805,7 @@ module.exports = function(dataSource, should, connectorCapabilities) {
ctxRecorder.records.should.eql(aCtxForModel(TestModel, {
where: { id: existingInstance.id },
data: { id: existingInstance.id, name: 'updated name' },
currentInstance: existingInstance
currentInstance: existingInstance,
}));
}
done();
@ -1826,14 +1826,14 @@ module.exports = function(dataSource, should, connectorCapabilities) {
// UPDATE or CREATE will be triggered
ctxRecorder.records.should.eql(aCtxForModel(TestModel, {
where: { id: 'new-id' },
data: { id: 'new-id', name: 'a name' }
data: { id: 'new-id', name: 'a name' },
}));
} else {
// The default unoptimized implementation runs
// `instance.save` and thus a full instance is availalbe
ctxRecorder.records.should.eql(aCtxForModel(TestModel, {
instance: { id: 'new-id', name: 'a name', extra: undefined },
isNewInstance: true
isNewInstance: true,
}));
}
@ -1918,21 +1918,21 @@ module.exports = function(dataSource, should, connectorCapabilities) {
currentInstance: {
id: 'new-id',
name: 'a name',
extra: undefined
}
extra: undefined,
},
}));
} else {
ctxRecorder.records.should.eql(aCtxForModel(TestModel, {
data: {
id: 'new-id',
name: 'a name'
name: 'a name',
},
isNewInstance: true,
currentInstance: {
id: 'new-id',
name: 'a name',
extra: undefined
}
extra: undefined,
},
}));
}
done();
@ -1951,13 +1951,13 @@ module.exports = function(dataSource, should, connectorCapabilities) {
where: { id: existingInstance.id },
data: {
id: existingInstance.id,
name: 'updated name'
name: 'updated name',
},
currentInstance: {
id: existingInstance.id,
name: 'updated name',
extra: undefined
}
extra: undefined,
},
});
if (!dataSource.connector.updateOrCreate) {
@ -1987,9 +1987,9 @@ module.exports = function(dataSource, should, connectorCapabilities) {
ctxRecorder.records.should.eql(aCtxForModel(TestModel, {
data: {
id: 'new-id',
name: 'a name'
name: 'a name',
},
isNewInstance: true
isNewInstance: true,
}));
}
done();
@ -2008,8 +2008,8 @@ module.exports = function(dataSource, should, connectorCapabilities) {
ctxRecorder.records.should.eql(aCtxForModel(TestModel, {
data: {
id: existingInstance.id,
name: 'updated name'
}
name: 'updated name',
},
}));
} else {
// For Unoptimized connector, the callback function `contextRecorder.recordAndNext`
@ -2020,17 +2020,17 @@ module.exports = function(dataSource, should, connectorCapabilities) {
instance: {
id: existingInstance.id,
name: 'first',
extra: null
extra: null,
},
isNewInstance: false,
options: { notify: false }
options: { notify: false },
}),
aCtxForModel(TestModel, {
data: {
id: existingInstance.id,
name: 'updated name'
}
})
name: 'updated name',
},
}),
]);
}
done();
@ -2058,9 +2058,9 @@ module.exports = function(dataSource, should, connectorCapabilities) {
instance: {
id: existingInstance.id,
name: 'updated name',
extra: undefined
extra: undefined,
},
isNewInstance: false
isNewInstance: false,
}));
done();
});
@ -2077,9 +2077,9 @@ module.exports = function(dataSource, should, connectorCapabilities) {
instance: {
id: instance.id,
name: 'a name',
extra: undefined
extra: undefined,
},
isNewInstance: true
isNewInstance: true,
}));
done();
});
@ -2102,7 +2102,7 @@ module.exports = function(dataSource, should, connectorCapabilities) {
'before save',
'persist',
'loaded',
'after save'
'after save',
]);
done();
});
@ -2121,7 +2121,7 @@ module.exports = function(dataSource, should, connectorCapabilities) {
'before save',
'persist',
'loaded',
'after save'
'after save',
]);
} else {
// TODO: Please see loopback-datasource-juggler/issues#836
@ -2139,7 +2139,7 @@ module.exports = function(dataSource, should, connectorCapabilities) {
'before save',
'persist',
'loaded',
'after save'
'after save',
]);
};
done();
@ -2200,7 +2200,7 @@ module.exports = function(dataSource, should, connectorCapabilities) {
if (err) return done(err);
(list || []).map(toObject).should.eql([
{ id: existingInstance.id, name: existingInstance.name, extra: undefined },
{ id: instance.id, name: 'new name', extra: undefined }
{ id: instance.id, name: 'new name', extra: undefined },
]);
done();
});
@ -2222,7 +2222,7 @@ module.exports = function(dataSource, should, connectorCapabilities) {
(list || []).map(toObject).should.eql([
{ id: existingInstance.id, name: existingInstance.name, extra: undefined },
{ id: list[1].id, name: 'second', extra: undefined },
{ id: instance.id, name: 'new name', extra: undefined }
{ id: instance.id, name: 'new name', extra: undefined },
]);
done();
});
@ -2275,8 +2275,8 @@ module.exports = function(dataSource, should, connectorCapabilities) {
instance: {
id: existingInstance.id,
name: 'replaced name',
extra: undefined
}
extra: undefined,
},
});
if (!dataSource.connector.replaceOrCreate) {
@ -2300,8 +2300,8 @@ module.exports = function(dataSource, should, connectorCapabilities) {
instance: {
id: 'new-id',
name: 'a name',
extra: undefined
}
extra: undefined,
},
});
if (!dataSource.connector.replaceOrCreate) {
@ -2385,13 +2385,13 @@ module.exports = function(dataSource, should, connectorCapabilities) {
where: { id: existingInstance.id },
data: {
id: existingInstance.id,
name: 'replaced name'
name: 'replaced name',
},
currentInstance: {
id: existingInstance.id,
name: 'replaced name',
extra: undefined
}
extra: undefined,
},
};
var expectedContext = aCtxForModel(TestModel, expected);
@ -2417,8 +2417,8 @@ module.exports = function(dataSource, should, connectorCapabilities) {
var expected = {
data: {
id: 'new-id',
name: 'a name'
}
name: 'a name',
},
};
expected.isNewInstance =
@ -2441,8 +2441,8 @@ module.exports = function(dataSource, should, connectorCapabilities) {
var expected = {
data: {
id: existingInstance.id,
name: 'replaced name'
}
name: 'replaced name',
},
};
expected.isNewInstance =
@ -2465,18 +2465,18 @@ module.exports = function(dataSource, should, connectorCapabilities) {
aCtxForModel(TestModel, {
data: {
id: existingInstance.id,
name: 'first'
name: 'first',
},
isNewInstance: false,
options: { notify: false }
options: { notify: false },
}),
aCtxForModel(TestModel, {
data: {
id: existingInstance.id,
name: 'replaced name'
name: 'replaced name',
},
isNewInstance: false
})
isNewInstance: false,
}),
]);
}
done();
@ -2505,8 +2505,8 @@ module.exports = function(dataSource, should, connectorCapabilities) {
instance: {
id: existingInstance.id,
name: 'replaced name',
extra: undefined
}
extra: undefined,
},
};
expected.isNewInstance =
@ -2530,8 +2530,8 @@ module.exports = function(dataSource, should, connectorCapabilities) {
instance: {
id: instance.id,
name: 'a name',
extra: undefined
}
extra: undefined,
},
};
expected.isNewInstance =
connectorCapabilities.replaceOrCreateReportsNewInstance ?
@ -2746,7 +2746,7 @@ module.exports = function(dataSource, should, connectorCapabilities) {
if (err) return done(err);
ctxRecorder.records.should.eql(aCtxForModel(TestModel, {
where: { id: existingInstance.id },
instance: existingInstance
instance: existingInstance,
}));
done();
});
@ -2788,13 +2788,13 @@ module.exports = function(dataSource, should, connectorCapabilities) {
aCtxForModel(TestModel, {
hookState: { foo: 'bar' },
where: { id: '1' },
instance: existingInstance
instance: existingInstance,
}),
aCtxForModel(TestModel, {
hookState: { foo: 'BAR' },
where: { id: '1' },
instance: existingInstance
})
instance: existingInstance,
}),
]);
done();
});
@ -2846,7 +2846,7 @@ module.exports = function(dataSource, should, connectorCapabilities) {
if (err) return done(err);
(list || []).map(toObject).should.eql([
{ id: existingInstance.id, name: existingInstance.name, extra: undefined },
{ id: '2', name: 'new name', extra: undefined }
{ id: '2', name: 'new name', extra: undefined },
]);
done();
});
@ -2900,7 +2900,7 @@ module.exports = function(dataSource, should, connectorCapabilities) {
ctxRecorder.records.should.eql(aCtxForModel(TestModel, {
data: { name: 'changed' },
where: { name: existingInstance.name }
where: { name: existingInstance.name },
}));
done();
@ -2947,7 +2947,7 @@ module.exports = function(dataSource, should, connectorCapabilities) {
if (err) return done(err);
ctxRecorder.records.should.eql(aCtxForModel(TestModel, {
where: { id: existingInstance.id },
data: { name: 'updated name' }
data: { name: 'updated name' },
}));
done();
});

View File

@ -104,7 +104,7 @@ describe('relations', function () {
var chapters = [
{ name: 'a' },
{ name: 'z' },
{name: 'c'}
{ name: 'c' },
];
Book.create(function(err, book) {
book.chapters.create(chapters, function(err, chs) {
@ -123,7 +123,7 @@ describe('relations', function () {
var chapters = [
{ name: 'a' },
{ name: 'z' },
{name: 'c'}
{ name: 'c' },
];
Book.create(function(err, book) {
book.chapters.create(chapters)
@ -174,10 +174,10 @@ describe('relations', function () {
.then(function(book) {
return book.chapters.create({ name: 'a' })
.then(function() {
return book.chapters.create({name: 'z'})
return book.chapters.create({ name: 'z' });
})
.then(function() {
return book.chapters.create({name: 'c'})
return book.chapters.create({ name: 'c' });
})
.then(function() {
return verify(book);
@ -297,14 +297,14 @@ describe('relations', function () {
return book.chapters.create({ name: 'a' })
.then(function(ch) {
id = ch.id;
return book.chapters.create({name: 'z'})
return book.chapters.create({ name: 'z' });
})
.then(function() {
return book.chapters.create({name: 'c'})
return book.chapters.create({ name: 'c' });
})
.then(function() {
return verify(book);
})
});
}).catch(done);
function verify(book) {
@ -346,10 +346,10 @@ describe('relations', function () {
.then(function(book) {
book.chapters.create({ name: 'a' })
.then(function() {
return book.chapters.create({name: 'b'})
return book.chapters.create({ name: 'b' });
})
.then(function() {
return book.chapters.create({name: 'c'})
return book.chapters.create({ name: 'c' });
})
.then(function() {
return verify(book);
@ -360,7 +360,7 @@ describe('relations', function () {
return book.chapters.count()
.then(function(count) {
count.should.equal(3);
return book.chapters.count({ name: 'b' })
return book.chapters.count({ name: 'b' });
})
.then(function(count) {
count.should.equal(1);
@ -402,7 +402,7 @@ describe('relations', function () {
return book.chapters.create({ name: 'a' })
.then(function(ch) {
id = ch.id;
return book.chapters.updateById(id, {name: 'aa'})
return book.chapters.updateById(id, { name: 'aa' });
})
.then(function(ch) {
return verify(book);
@ -447,7 +447,7 @@ describe('relations', function () {
return book.chapters.create({ name: 'a' })
.then(function(ch) {
id = ch.id;
return book.chapters.destroy(id)
return book.chapters.destroy(id);
})
.then(function(ch) {
return verify(book);
@ -493,10 +493,10 @@ describe('relations', function () {
return book.chapters.create({ name: 'a' })
.then(function(ch) {
id = ch.id;
return book.chapters.create({name: 'z'})
return book.chapters.create({ name: 'z' });
})
.then(function() {
return book.chapters.create({name: 'c'})
return book.chapters.create({ name: 'c' });
})
.then(function() {
return verify(book);
@ -625,7 +625,7 @@ describe('relations', function () {
function verifyPatient(patient, next) {
Appointment.find({ where: {
physicianId: physician.id,
patientId: patient.id
patientId: patient.id,
}},
function(err, apps) {
should.not.exist(err);
@ -649,7 +649,7 @@ describe('relations', function () {
function verifyPatient(patient, next) {
Appointment.find({ where: {
physicianId: physician.id,
patientId: patient.id
patientId: patient.id,
}})
.then(function(apps) {
apps.should.have.lengthOf(1);
@ -690,14 +690,14 @@ describe('relations', function () {
.then(function(physician) {
return physician.patients.create({ name: 'a' })
.then(function() {
return physician.patients.create({name: 'z'})
return physician.patients.create({ name: 'z' });
})
.then(function() {
return physician.patients.create({name: 'c'})
return physician.patients.create({ name: 'c' });
})
.then(function() {
return verify(physician);
})
});
}).catch(done);
function verify(physician) {
return physician.patients.getAsync()
@ -737,7 +737,7 @@ describe('relations', function () {
ch1.should.have.lengthOf(1);
ch1[0].name.should.eql('z');
//order
physician.patients({ order: "patientId DESC" },function (err2, ch2) {
physician.patients({ order: 'patientId DESC' }, function(err2, ch2) {
should.not.exist(err2);
should.exist(ch2);
ch2.should.have.lengthOf(3);
@ -779,10 +779,10 @@ describe('relations', function () {
return physician.patients.create({ name: 'a' })
.then(function(ch) {
id = ch.id;
return physician.patients.create({name: 'z'})
return physician.patients.create({ name: 'z' });
})
.then(function() {
return physician.patients.create({name: 'c'})
return physician.patients.create({ name: 'c' });
})
.then(function() {
return verify(physician);
@ -984,10 +984,10 @@ describe('relations', function () {
return physician.patients.create({ name: 'a' })
.then(function(ch) {
id = ch.id;
return physician.patients.create({name: 'z'})
return physician.patients.create({ name: 'z' });
})
.then(function() {
return physician.patients.create({name: 'c'})
return physician.patients.create({ name: 'c' });
})
.then(function() {
return verify(physician);
@ -1380,7 +1380,7 @@ describe('relations', function () {
scope: function(inst, filter) {
var m = this.properties(inst); // re-use properties
if (m) return { where: m };
}
},
});
db.automigrate(['Category', 'Job'], done);
});
@ -1433,7 +1433,7 @@ describe('relations', function () {
it('should find records on scope with promises', function(done) {
Category.findOne()
.then(function(c) {
return c.jobs.getAsync()
return c.jobs.getAsync();
})
.then(function(jobs) {
jobs.should.have.length(2);
@ -1457,7 +1457,7 @@ describe('relations', function () {
it('should find record on scope with promises - filtered', function(done) {
Category.findOne()
.then(function(c) {
return c.jobs.getAsync({ where: { type: 'book' } })
return c.jobs.getAsync({ where: { type: 'book' }});
})
.then(function(jobs) {
jobs.should.have.length(1);
@ -1713,11 +1713,11 @@ describe('relations', function () {
Picture = db.define('Picture', { name: String });
Author = db.define('Author', {
username: { type: String, id: true, generated: true },
name: String
name: String,
});
Reader = db.define('Reader', {
username: { type: String, id: true, generated: true },
name: String
name: String,
});
db.automigrate(['Picture', 'Author', 'Reader'], done);
@ -1728,23 +1728,23 @@ describe('relations', function () {
as: 'avatar',
polymorphic: {
foreignKey: 'oid',
discriminator: 'type'
}
discriminator: 'type',
},
});
Reader.hasOne(Picture, {
as: 'mugshot',
polymorphic: {
foreignKey: 'oid',
discriminator: 'type'
}
discriminator: 'type',
},
});
Picture.belongsTo('owner', {
idName: 'username',
polymorphic: {
idType: Author.definition.properties.username.type,
foreignKey: 'oid',
discriminator: 'type'
}
discriminator: 'type',
},
});
db.automigrate(['Picture', 'Author', 'Reader'], done);
});
@ -1880,7 +1880,7 @@ describe('relations', function () {
Author.hasMany(Picture, { polymorphic: 'imageable' });
Reader.hasMany(Picture, { polymorphic: { // alt syntax
as: 'imageable', foreignKey: 'imageableId',
discriminator: 'imageableType'
discriminator: 'imageableType',
}});
Picture.belongsTo('imageable', { polymorphic: true });
@ -1895,8 +1895,8 @@ describe('relations', function () {
polymorphic: {
as: 'imageable',
foreignKey: 'imageableId',
discriminator: 'imageableType'
}
discriminator: 'imageableType',
},
});
Picture.relations['imageable'].toJSON().should.eql({
@ -1910,8 +1910,8 @@ describe('relations', function () {
polymorphic: {
as: 'imageable',
foreignKey: 'imageableId',
discriminator: 'imageableType'
}
discriminator: 'imageableType',
},
});
db.automigrate(['Picture', 'Author', 'Reader'], done);
@ -2320,7 +2320,7 @@ describe('relations', function () {
it('should create polymorphic through model - new author', function(done) {
PictureLink.findOne({ where: {
pictureId: anotherPicture.id, imageableId: author.id, imageableType: 'Author'
pictureId: anotherPicture.id, imageableId: author.id, imageableType: 'Author',
}}, function(err, link) {
should.not.exist(err);
link.pictureId.should.eql(anotherPicture.id);
@ -2361,7 +2361,7 @@ describe('relations', function () {
// syntax 2 (new)
Fear.belongsTo('mind', {
methods: { check: function() { return true; } }
methods: { check: function() { return true; } },
});
Object.keys((new Fear).toObject()).should.containEql('mindId');
@ -2373,7 +2373,7 @@ describe('relations', function () {
var rel = Fear.relations['mind'];
rel.defineMethod('other', function() {
return true;
})
});
});
it('should have setup a custom method on accessor', function() {
@ -2435,7 +2435,7 @@ describe('relations', function () {
.then(function(list) {
listId = list.id;
should.exist(list);
return list.todos.create({name: 'Item 1'})
return list.todos.create({ name: 'Item 1' });
})
.then(function(todo) {
itemId = todo.id;
@ -2561,7 +2561,7 @@ describe('relations', function () {
Passport = db.define('Passport', { name: String, notes: String });
Passport.belongsTo(Person, {
properties: { notes: 'passportNotes' },
scope: { fields: { id: true, name: true } }
scope: { fields: { id: true, name: true }},
});
db.automigrate(['Person', 'Passport'], done);
});
@ -2600,7 +2600,7 @@ describe('relations', function () {
p.personId.should.equal(person.id);
person.name.should.equal('Fred');
person.passportNotes.should.equal('Some notes...');
return p.save()
return p.save();
})
.then(function(passport) {
done();
@ -2612,7 +2612,7 @@ describe('relations', function () {
Passport.findOne()
.then(function(p) {
p.personId.should.eql(personCreated.id);
return p.person.getAsync()
return p.person.getAsync();
})
.then(function(person) {
person.name.should.equal('Fred');
@ -2636,7 +2636,7 @@ describe('relations', function () {
Passport = db.define('Passport', { name: String, notes: String });
Passport.belongsTo(Person, {
properties: ['name'],
options: { embedsProperties: true, invertProperties: true }
options: { embedsProperties: true, invertProperties: true },
});
db.automigrate(['Person', 'Passport'], done);
});
@ -2690,7 +2690,7 @@ describe('relations', function () {
it('can be declared using hasOne method', function() {
Supplier.hasOne(Account, {
properties: { name: 'supplierName' },
methods: { check: function() { return true; } }
methods: { check: function() { return true; } },
});
Object.keys((new Account()).toObject()).should.containEql('supplierId');
(new Supplier()).account.should.be.an.instanceOf(Function);
@ -2700,7 +2700,7 @@ describe('relations', function () {
var rel = Supplier.relations['account'];
rel.defineMethod('other', function() {
return true;
})
});
});
it('should have setup a custom method on accessor', function() {
@ -2761,7 +2761,7 @@ describe('relations', function () {
should.exist(supplier);
return supplier.account.create({ accountNo: 'a01' })
.then(function(account) {
return supplier.account.getAsync()
return supplier.account.getAsync();
})
.then(function(act) {
accountId = act.id;
@ -2770,7 +2770,7 @@ describe('relations', function () {
supplier.account().id.should.equal(act.id);
act.supplierName.should.equal(supplier.name);
done();
})
});
})
.catch(done);
});
@ -2796,7 +2796,7 @@ describe('relations', function () {
Supplier.findById(supplierId)
.then(function(supplier) {
should.exist(supplier);
return supplier.account.update({supplierName: 'Supplier B'})
return supplier.account.update({ supplierName: 'Supplier B' });
})
.then(function(act) {
act.supplierName.should.equal('Supplier B');
@ -2840,7 +2840,7 @@ describe('relations', function () {
Supplier.findById(supplierId)
.then(function(supplier) {
should.exist(supplier);
return supplier.account.getAsync()
return supplier.account.getAsync();
})
.then(function(act) {
should.exist(act);
@ -2867,7 +2867,7 @@ describe('relations', function () {
should.exist(supplier);
return supplier.account.create({ accountNo: 'a01' })
.then(function(account) {
return supplier.account.destroy()
return supplier.account.destroy();
})
.then(function(err) {
done();
@ -2892,7 +2892,7 @@ describe('relations', function () {
Supplier.findById(supplierId)
.then(function(supplier) {
should.exist(supplier);
return supplier.account.getAsync()
return supplier.account.getAsync();
})
.then(function(act) {
should.not.exist(act);
@ -2987,7 +2987,7 @@ describe('relations', function () {
should.exist(supplier);
return supplier.account.create({ accountNo: 'a01', block: false })
.then(function(account) {
return supplier.account.getAsync()
return supplier.account.getAsync();
})
.then(function(act) {
accountId = act.id;
@ -3007,10 +3007,10 @@ describe('relations', function () {
it('should find record that match scope with promises', function(done) {
Account.updateAll({ block: true })
.then(function() {
return Supplier.findById(supplierId)
return Supplier.findById(supplierId);
})
.then(function(supplier) {
return supplier.account.getAsync()
return supplier.account.getAsync();
})
.then(function(account) {
should.not.exist(account);
@ -3031,24 +3031,24 @@ describe('relations', function () {
sid: {
type: String,
id: true,
generated: true
generated: true,
},
name: String
name: String,
});
Account = db.define('Account', {
accid: {
type: String,
id: true,
generated: false
generated: false,
},
supplierName: String
supplierName: String,
});
});
it('can be declared with non standard foreignKey', function() {
Supplier.hasOne(Account, {
properties: { name: 'supplierName' },
foreignKey: 'sid'
foreignKey: 'sid',
});
Object.keys((new Account()).toObject()).should.containEql('sid');
(new Supplier()).account.should.be.an.instanceOf(Function);
@ -3116,12 +3116,12 @@ describe('relations', function () {
db = getSchema();
CompanyBoard = db.define('CompanyBoard', {
membersNumber: Number,
companyId: String
companyId: String,
});
Boss = db.define('Boss', {
id: { type: String, id: true, generated: false },
boardMembersNumber: Number,
companyId: String
companyId: String,
});
});
@ -3129,7 +3129,7 @@ describe('relations', function () {
CompanyBoard.hasOne(Boss, {
properties: { membersNumber: 'boardMembersNumber' },
primaryKey: 'companyId',
foreignKey: 'companyId'
foreignKey: 'companyId',
});
Object.keys((new Boss()).toObject()).should.containEql('companyId');
(new CompanyBoard()).boss.should.be.an.instanceOf(Function);
@ -3184,7 +3184,7 @@ describe('relations', function () {
describe('hasMany with primaryKey different from model PK', function() {
var Employee, Boss;
var COMPANY_ID = "Company1";
var COMPANY_ID = 'Company1';
before(function() {
db = getSchema();
@ -3195,7 +3195,7 @@ describe('relations', function () {
it('relation can be declared with primaryKey', function() {
Boss.hasMany(Employee, {
primaryKey: 'companyId',
foreignKey: 'companyId'
foreignKey: 'companyId',
});
(new Boss()).employees.should.be.an.instanceOf(Function);
});
@ -3217,7 +3217,7 @@ describe('relations', function () {
employee.should.be.an.instanceOf(Employee);
employee.companyId.should.be.eql(boss.companyId);
return employees;
})
});
});
});
});
@ -3233,7 +3233,7 @@ describe('relations', function () {
}).then(function(employees) {
should.exists(employees);
employees.length.should.equal(1);
})
});
});
});
});
@ -3242,7 +3242,7 @@ describe('relations', function () {
describe('belongsTo with primaryKey different from model PK', function() {
var Employee, Boss;
var COMPANY_ID = "Company1";
var COMPANY_ID = 'Company1';
var bossId;
before(function() {
@ -3254,7 +3254,7 @@ describe('relations', function () {
it('relation can be declared with primaryKey', function() {
Employee.belongsTo(Boss, {
primaryKey: 'companyId',
foreignKey: 'companyId'
foreignKey: 'companyId',
});
(new Employee()).boss.should.be.an.instanceOf(Function);
});
@ -3264,7 +3264,7 @@ describe('relations', function () {
return Boss.create({ address: 'testAddress', companyId: COMPANY_ID })
.then(function(boss) {
bossId = boss.id;
return Employee.create({name: 'a', companyId: COMPANY_ID})
return Employee.create({ name: 'a', companyId: COMPANY_ID });
})
.then(function(employee) {
should.exists(employee);
@ -3390,7 +3390,7 @@ describe('relations', function () {
at.articleId.should.eql(article.id);
done();
});
})
});
})
.catch(done);
});
@ -3404,7 +3404,7 @@ describe('relations', function () {
tags.should.not.be.empty;
return article.tagNames.remove(tags[0])
.then(function() {
return article.tagNames.getAsync()
return article.tagNames.getAsync();
})
.then(function(tags) {
tags.should.have.lengthOf(len - 1);
@ -3494,7 +3494,7 @@ describe('relations', function () {
it('can be declared using embedsOne method', function(done) {
Person.embedsOne(Passport, {
default: { name: 'Anonymous' }, // a bit contrived
methods: { check: function() { return true; } }
methods: { check: function() { return true; } },
});
Person.embedsOne(Address); // all by default
db.automigrate(['Person'], done);
@ -3513,7 +3513,7 @@ describe('relations', function () {
var rel = Person.relations['passportItem'];
rel.defineMethod('other', function() {
return true;
})
});
});
it('should have setup a custom method on accessor', function() {
@ -3781,7 +3781,7 @@ describe('relations', function () {
it('can be declared using embedsOne method', function(done) {
Person.embedsOne(Passport, {
options: {persistent: true}
options: { persistent: true },
});
db.automigrate(['Person', 'Passport'], done);
});
@ -4098,7 +4098,7 @@ describe('relations', function () {
Person = db.define('Person', { name: String });
Address = tmp.define('Address', {
id: { type: Number, id:true },
street: String
street: String,
});
db.automigrate(['Person'], done);
@ -4215,7 +4215,7 @@ describe('relations', function () {
Person.create({ name: 'Wilma', addresses: addresses }, function(err, p) {
err.name.should.equal('ValidationError');
err.details.messages.addresses.should.eql([
'contains invalid item: `work` (`street` can\'t be blank)'
'contains invalid item: `work` (`street` can\'t be blank)',
]);
done();
});
@ -4261,7 +4261,7 @@ describe('relations', function () {
it('should create embedded from attributes - property name', function(done) {
var addresses = [
{ id: 'home', street: 'Home Street' },
{id: 'work', street: 'Work Street'}
{ id: 'work', street: 'Work Street' },
];
Person.create({ name: 'Wilma', addresses: addresses }, function(err, p) {
should.not.exist(err);
@ -4274,7 +4274,7 @@ describe('relations', function () {
it('should not create embedded from attributes - relation name', function(done) {
var addresses = [
{ id: 'home', street: 'Home Street' },
{id: 'work', street: 'Work Street'}
{ id: 'work', street: 'Work Street' },
];
Person.create({ name: 'Wilma', addressList: addresses }, function(err, p) {
should.not.exist(err);
@ -4319,7 +4319,7 @@ describe('relations', function () {
// persistent: true
Person.embedsMany(Address, {
scope: { order: 'street' },
options: {persistent: true}
options: { persistent: true },
});
db.automigrate(['Person', 'Address'], done);
});
@ -4437,12 +4437,12 @@ describe('relations', function () {
Category.embedsMany(Link, {
as: 'items', // rename
scope: { include: 'job' }, // always include
options: { belongsTo: 'job' } // optional, for add()/remove()
options: { belongsTo: 'job' }, // optional, for add()/remove()
});
Link.belongsTo(Job, {
foreignKey: 'id', // re-use the actual job id
properties: { id: 'id', name: 'name' }, // denormalize, transfer id
options: { invertProperties: true }
options: { invertProperties: true },
});
db.automigrate(['Category', 'Job', 'Link'], function() {
Job.create({ name: 'Job 0' }, done); // offset ids for tests
@ -4601,7 +4601,7 @@ describe('relations', function () {
Category.findById(category.id, function(err, cat) {
cat.name.should.equal('Category B');
cat.links.toObject().should.eql([
{id: jobId, name: 'Job 1', notes: 'Some notes...'}
{ id: jobId, name: 'Job 1', notes: 'Some notes...' },
]);
cat.items.at(0).should.equal(cat.links[0]);
cat.items(function(err, items) { // alternative access
@ -4629,7 +4629,7 @@ describe('relations', function () {
Category.findById(category.id, function(err, cat) {
cat.name.should.equal('Category B');
cat.links.toObject().should.eql([
{id: jobId, name: 'Job 1', notes: 'Updated notes...'}
{ id: jobId, name: 'Job 1', notes: 'Updated notes...' },
]);
done();
});
@ -4668,7 +4668,7 @@ describe('relations', function () {
Link = tmp.define('Link', {
id: { type: Number, id: true },
name: String, notes: String
name: String, notes: String,
}); // generic model
Link.validatesPresenceOf('linkedId');
Link.validatesPresenceOf('linkedType');
@ -4681,12 +4681,12 @@ describe('relations', function () {
Book.embedsMany(Link, { as: 'people',
polymorphic: 'linked',
scope: { include: 'linked' }
scope: { include: 'linked' },
});
Link.belongsTo('linked', {
polymorphic: { idType: idType }, // native type
properties: { name: 'name' }, // denormalized
options: { invertProperties: true }
options: { invertProperties: true },
});
db.automigrate(['Book', 'Author', 'Reader'], done);
});
@ -4819,7 +4819,7 @@ describe('relations', function () {
reverse.http = { verb: 'put', path: '/jobs/reverse' };
Category.referencesMany(Job, { scopeMethods: {
reverse: reverse
reverse: reverse,
}});
Category.prototype['__reverse__jobs'].should.be.a.function;
@ -5007,10 +5007,10 @@ describe('relations', function () {
categories[0].jobs({ order: 'name DESC' }, function(err, jobs) {
should.not.exist(err);
jobs.should.have.length(2);
jobs[0].id.should.eql(job3.id)
jobs[1].id.should.eql(job2.id)
jobs[0].id.should.eql(job3.id);
jobs[1].id.should.eql(job2.id);
done();
})
});
});
});
@ -5022,7 +5022,7 @@ describe('relations', function () {
cat.jobIds.should.eql(expected);
done();
});
})
});
});
it('should include related items from scope', function(done) {
@ -5071,7 +5071,7 @@ describe('relations', function () {
return Job.create({ name: 'Job 1' })
.then(function(p) {
job1 = p;
return Job.create({ name: 'Job 3' })
return Job.create({ name: 'Job 3' });
})
.then(function(p) {
job3 = p;
@ -5102,7 +5102,7 @@ describe('relations', function () {
Category.findOne()
.then(function(cat) {
cat.jobIds = [job2.id, job2.id];
cat.save()
cat.save();
})
.then(function(p) {
should.not.exist(p);
@ -5120,7 +5120,7 @@ describe('relations', function () {
Category.findOne()
.then(function(cat) {
cat.jobIds.should.eql([job2.id]);
return cat.jobs.getAsync()
return cat.jobs.getAsync();
})
.then(function(jobs) {
var p = jobs[0];
@ -5135,7 +5135,7 @@ describe('relations', function () {
Category.findOne()
.then(function(cat) {
cat.jobIds.should.eql([job2.id]);
return cat.jobs.findById(job2.id)
return cat.jobs.findById(job2.id);
})
.then(function(p) {
p.should.be.instanceof(Job);
@ -5165,7 +5165,7 @@ describe('relations', function () {
.then(function(p) {
p.name.should.equal(attrs.name);
done();
})
});
})
.catch(done);
});
@ -5173,7 +5173,7 @@ describe('relations', function () {
it('should get a record by index with promises - at', function(done) {
Category.findOne()
.then(function(cat) {
return cat.jobs.at(0)
return cat.jobs.at(0);
})
.then(function(p) {
p.should.be.instanceof(Job);
@ -5216,7 +5216,7 @@ describe('relations', function () {
it('should find items on scope with promises - findById', function(done) {
Category.findOne()
.then(function(cat) {
return cat.jobs.findById(job3.id)
return cat.jobs.findById(job3.id);
})
.then(function(p) {
p.id.should.eql(job3.id);
@ -5230,7 +5230,7 @@ describe('relations', function () {
Category.findOne()
.then(function(cat) {
var filter = { where: { name: 'Job 1' }};
return cat.jobs.getAsync(filter)
return cat.jobs.getAsync(filter);
})
.then(function(jobs) {
jobs.should.have.length(1);
@ -5261,7 +5261,7 @@ describe('relations', function () {
.then(function(cat) {
var expected = [job2.id, job3.id];
cat.jobIds.should.eql(expected);
return cat.jobs.getAsync()
return cat.jobs.getAsync();
})
.then(function(jobs) {
jobs.should.have.length(2);
@ -5276,7 +5276,7 @@ describe('relations', function () {
Category.find()
.then(function(categories) {
categories.should.have.length(1);
return categories[0].jobs.getAsync({order: 'name DESC'})
return categories[0].jobs.getAsync({ order: 'name DESC' });
})
.then(function(jobs) {
jobs.should.have.length(2);
@ -5321,7 +5321,7 @@ describe('relations', function () {
.then(function() {
var expected = [job3.id];
cat.jobIds.should.eql(expected);
return Job.exists(job2.id)
return Job.exists(job2.id);
})
.then(function(exists) {
should.exist(exists);
@ -5337,7 +5337,7 @@ describe('relations', function () {
.then(function(cat) {
var expected = [job3.id];
cat.jobIds.should.eql(expected);
return cat.jobs.getAsync()
return cat.jobs.getAsync();
})
.then(function(jobs) {
jobs.should.have.length(1);
@ -5398,14 +5398,14 @@ describe('relations', function () {
cat.jobs.create({ name: 'Job 2' }, function(err, p) {
done();
});
})
});
});
});
it('should allow custom scope methods - summarize', function(done) {
var expected = [
{ name: 'Job 1', categoryId: categoryId, categoryName: 'Category A' },
{ name: 'Job 2', categoryId: categoryId, categoryName: 'Category A' }
{ name: 'Job 2', categoryId: categoryId, categoryName: 'Category A' },
];
Category.findOne(function(err, cat) {
@ -5418,18 +5418,18 @@ describe('relations', function () {
result.should.eql(expected);
done();
});
})
});
});
it('should allow custom scope methods with promises - summarize', function(done) {
var expected = [
{ name: 'Job 1', categoryId: categoryId, categoryName: 'Category A' },
{ name: 'Job 2', categoryId: categoryId, categoryName: 'Category A' }
{ name: 'Job 2', categoryId: categoryId, categoryName: 'Category A' },
];
Category.findOne()
.then(function(cat) {
return cat.jobs.summarize()
return cat.jobs.summarize();
})
.then(function(summary) {
var result = summary.map(function(item) {

View File

@ -13,22 +13,22 @@ describe('scope', function () {
before(function() {
db = getSchema();
Railway = db.define('Railway', {
URID: {type: String, index: true}
URID: { type: String, index: true },
}, {
scopes: {
highSpeed: {
where: {
highSpeed: true
}
}
}
highSpeed: true,
},
},
},
});
Station = db.define('Station', {
USID: { type: String, index: true },
capacity: { type: Number, index: true },
thoughput: { type: Number, index: true },
isActive: { type: Boolean, index: true },
isUndeground: {type: Boolean, index: true}
isUndeground: { type: Boolean, index: true },
});
});
@ -64,7 +64,7 @@ describe('scope', function () {
station.isActive.should.be.true;
station.isUndeground.should.be.true;
done();
})
});
});
it('should query all', function(done) {
@ -111,7 +111,7 @@ describe('scope - order', function () {
db = getSchema();
Station = db.define('Station', {
name: { type: String, index: true },
order: {type: Number, index: true}
order: { type: Number, index: true },
});
Station.scope('reverse', { order: 'order DESC' });
});
@ -168,7 +168,7 @@ describe('scope - filtered count, updateAll and destroyAll', function () {
name: { type: String, index: true },
order: { type: Number, index: true },
active: { type: Boolean, index: true, default: true },
flagged: {type: Boolean, index: true, default: false}
flagged: { type: Boolean, index: true, default: false },
});
Station.scope('ordered', { order: 'order' });
Station.scope('active', { where: { active: true }});
@ -350,7 +350,7 @@ describe('scope - dynamic target class', function () {
Collection.destroyAll(function() {
Image.destroyAll(function() {
Video.destroyAll(done);
})
});
});
});
@ -425,13 +425,13 @@ describe('scope - dynamic function', function () {
Item.scope('dynamicQuery', function() {
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:2, creator:2 }, done);
});
});
it('should deduce item by runtime creator', function(done) {
@ -442,7 +442,7 @@ describe('scope - dynamic function', function () {
should.not.exist(err);
secondQuery.title.should.equal(2);
done();
})
})
})
});
});
});
});

View File

@ -33,7 +33,7 @@ function context(name, tests) {
},
after: function(f) {
it('tearDown', f);
}
},
});
group_name = false;
}

View File

@ -26,7 +26,7 @@ describe('Transient connector', function () {
Widget = db.define('Widget', { name: String });
Item = db.define('Item', {
id: {type: Number, id: true}, name: String
id: { type: Number, id: true }, name: String,
});
});

View File

@ -18,7 +18,7 @@ describe('util.fieldsToArray', function () {
return {
expect: function(arr) {
should.deepEqual(fieldsToArray(fields, properties, excludeUnknown), arr);
}
},
};
}
@ -76,7 +76,7 @@ describe('util.removeUndefined', function () {
should.deepEqual(removeUndefined(q5, 'nullify'), { where: { x: 1, y: null }});
var q6 = { where: { x: 1, y: undefined }};
(function(){ removeUndefined(q6, 'throw') }).should.throw(/`undefined` in query/);
(function() { removeUndefined(q6, 'throw'); }).should.throw(/`undefined` in query/);
});
});
@ -163,7 +163,7 @@ describe('mergeSettings', function () {
{ permission: 'ALLOW',
property: 'findById',
principalType: 'ROLE',
principalId: '$owner' }
principalId: '$owner' },
] };
var tgt = { strict: false,
acls: [
@ -174,7 +174,7 @@ describe('mergeSettings', function () {
{ principalType: 'ROLE',
principalId: '$owner',
permission: 'ALLOW',
property: 'removeById' }
property: 'removeById' },
],
maxTTL: 31556926,
ttl: 1209600 };
@ -203,7 +203,7 @@ describe('mergeSettings', function () {
{ permission: 'ALLOW',
property: 'findById',
principalType: 'ROLE',
principalId: '$owner' }
principalId: '$owner' },
],
maxTTL: 31556926,
ttl: 1209600,
@ -224,7 +224,7 @@ describe('sortObjectsByIds', function () {
{ id: 3, name: 'c' },
{ id: 4, name: 'd' },
{ id: 5, name: 'e' },
{ id: 6, name: 'f' }
{ id: 6, name: 'f' },
];
it('should sort', function() {
@ -260,7 +260,7 @@ describe('util.mergeIncludes', function () {
var updateInclude = 'relation2';
var expectedInclude = [
{ relation2: true },
{relation1: true}
{ relation1: true },
];
checkInputOutput(baseInclude, updateInclude, expectedInclude);
});
@ -270,7 +270,7 @@ describe('util.mergeIncludes', function () {
var updateInclude = ['relation2'];
var expectedInclude = [
{ relation2: true },
{relation1: true}
{ relation1: true },
];
checkInputOutput(baseInclude, updateInclude, expectedInclude);
});
@ -280,7 +280,7 @@ describe('util.mergeIncludes', function () {
var updateInclude = { relation2: 'relation2Include' };
var expectedInclude = [
{ relation2: 'relation2Include' },
{relation1: true}
{ relation1: true },
];
checkInputOutput(baseInclude, updateInclude, expectedInclude);
});
@ -290,7 +290,7 @@ describe('util.mergeIncludes', function () {
var updateInclude = ['relation2'];
var expectedInclude = [
{ relation2: true },
{relation1: true}
{ relation1: true },
];
checkInputOutput(baseInclude, updateInclude, expectedInclude);
});
@ -300,7 +300,7 @@ describe('util.mergeIncludes', function () {
var updateInclude = { relation2: 'relation2Include' };
var expectedInclude = [
{ relation2: 'relation2Include' },
{relation1: true}
{ relation1: true },
];
checkInputOutput(baseInclude, updateInclude, expectedInclude);
});
@ -310,7 +310,7 @@ describe('util.mergeIncludes', function () {
var updateInclude = { relation2: 'relation2Include' };
var expectedInclude = [
{ relation2: 'relation2Include' },
{relation1: 'relation1Include'}
{ relation1: 'relation1Include' },
];
checkInputOutput(baseInclude, updateInclude, expectedInclude);
});
@ -319,7 +319,7 @@ describe('util.mergeIncludes', function () {
var baseInclude = { relation1: 'baseValue' };
var updateInclude = { relation1: 'updateValue' };
var expectedInclude = [
{relation1: 'updateValue'}
{ relation1: 'updateValue' },
];
checkInputOutput(baseInclude, updateInclude, expectedInclude);
});
@ -329,7 +329,7 @@ describe('util.mergeIncludes', function () {
var baseInclude = 'relation1';
var updateInclude = { relation: 'relation1' };
var expectedInclude = [
{relation: 'relation1'}
{ relation: 'relation1' },
];
checkInputOutput(baseInclude, updateInclude, expectedInclude);
});
@ -338,10 +338,10 @@ describe('util.mergeIncludes', function () {
var baseInclude = 'relation1';
var updateInclude = {
relation: 'relation1',
scope: {include: 'relation2'}
scope: { include: 'relation2' },
};
var expectedInclude = [
{relation: 'relation1', scope: {include: 'relation2'}}
{ relation: 'relation1', scope: { include: 'relation2' }},
];
checkInputOutput(baseInclude, updateInclude, expectedInclude);
});
@ -352,11 +352,11 @@ describe('util.mergeIncludes', function () {
var baseInclude = ['relation2'];
var updateInclude = {
relation: 'relation1',
scope: {include: 'relation2'}
scope: { include: 'relation2' },
};
var expectedInclude = [{
relation: 'relation1',
scope: {include: 'relation2'}
scope: { include: 'relation2' },
}, { relation2: true }];
checkInputOutput(baseInclude, updateInclude, expectedInclude);
@ -377,7 +377,7 @@ describe('util.mergeIncludes', function () {
it('Merge includes with mixture of strings, arrays & objects properly', function() {
var baseInclude = ['relation1', { relation2: true },
{ relation: 'relation3', scope: { where: { id: 'some id' }}},
{relation: 'relation5', scope: {where: {id: 'some id'}}}
{ relation: 'relation5', scope: { where: { id: 'some id' }}},
];
var updateInclude = ['relation4', { relation3: true },
{ relation: 'relation2', scope: { where: { id: 'some id' }}}];

View File

@ -18,7 +18,7 @@ function getValidAttributes() {
age: 26,
gender: 'male',
createdByAdmin: false,
createdByScript: true
createdByScript: true,
};
}
@ -39,11 +39,11 @@ describe('validations', function () {
pendingPeriod: Number,
createdByAdmin: Boolean,
createdByScript: Boolean,
updatedAt: Date
updatedAt: Date,
});
Entry = db.define('Entry', {
id: { type: 'string', id: true, generated: false },
name: { type: 'string' }
name: { type: 'string' },
});
Entry.validatesUniquenessOf('id');
db.automigrate(done);
@ -192,7 +192,7 @@ describe('validations', function () {
should.not.exist(e);
done();
});
})
});
});
});
@ -327,7 +327,7 @@ describe('validations', function () {
it('should skip validation by property (if/unless)', function() {
User.validatesPresenceOf('domain', { unless: 'createdByScript' });
var user = new User(getValidAttributes())
var user = new User(getValidAttributes());
user.isValid().should.be.true;
user.createdByScript = false;
@ -390,7 +390,7 @@ describe('validations', function () {
var EMAIL = 'user@xample.com';
var SiteUser = db.define('SiteUser', {
siteId: String,
email: String
email: String,
});
SiteUser.validatesUniquenessOf('email', { scopedTo: ['siteId'] });
async.waterfall([
@ -413,7 +413,7 @@ describe('validations', function () {
valid.should.be.false;
next();
});
}
},
], function(err) {
if (err && err.name == 'ValidationError') {
console.error('ValidationError:', err.details.messages);
@ -440,7 +440,7 @@ describe('validations', function () {
it('should work with if/unless', function(done) {
User.validatesUniquenessOf('email', {
if: function() { return true; },
unless: function() { return false; }
unless: function() { return false; },
});
var u = new User({ email: 'hello' });
Boolean(u.isValid(function(valid) {
@ -542,7 +542,7 @@ describe('validations', function () {
process.nextTick(next);
}, {
if: function() { return true; },
unless: function() { return false; }
unless: function() { return false; },
});
var u = new User({ email: 'hello' });
Boolean(u.isValid(function(valid) {
@ -611,7 +611,7 @@ describe('validations', function () {
var obj = {
errors: errorVal,
toJSON: function() { return jsonVal; }
toJSON: function() { return jsonVal; },
};
return new ValidationError(obj);
}