不要怂,就是干,撸起袖子干!

Commit 2874c549 by Simon Schick Committed by Sushant

chore(lint): enforce consistent spacing (#10193)

1 parent 227da630
Showing with 804 additions and 802 deletions
...@@ -23,6 +23,8 @@ ...@@ -23,6 +23,8 @@
"comma-spacing": "error", "comma-spacing": "error",
"key-spacing": "error", "key-spacing": "error",
"keyword-spacing": "error", "keyword-spacing": "error",
"object-curly-spacing": ["error", "always"],
"func-call-spacing": ["error", "never"],
"no-console": "off", "no-console": "off",
"no-extra-parens": "error", "no-extra-parens": "error",
......
...@@ -561,7 +561,7 @@ class BelongsToMany extends Association { ...@@ -561,7 +561,7 @@ class BelongsToMany extends Association {
where[foreignIdentifier] = newObj.get(targetKey); where[foreignIdentifier] = newObj.get(targetKey);
if (Object.keys(attributes).length) { if (Object.keys(attributes).length) {
promises.push(association.through.model.update(attributes, Object.assign(options, {where}))); promises.push(association.through.model.update(attributes, Object.assign(options, { where })));
} }
} }
} }
...@@ -571,7 +571,7 @@ class BelongsToMany extends Association { ...@@ -571,7 +571,7 @@ class BelongsToMany extends Association {
where[identifier] = sourceInstance.get(sourceKey); where[identifier] = sourceInstance.get(sourceKey);
where[foreignIdentifier] = obsoleteAssociations.map(obsoleteAssociation => obsoleteAssociation[foreignIdentifier]); where[foreignIdentifier] = obsoleteAssociations.map(obsoleteAssociation => obsoleteAssociation[foreignIdentifier]);
where = Object.assign(where, association.through.scope); where = Object.assign(where, association.through.scope);
promises.push(association.through.model.destroy(_.defaults({where}, options))); promises.push(association.through.model.destroy(_.defaults({ where }, options)));
} }
if (unassociatedObjects.length > 0) { if (unassociatedObjects.length > 0) {
...@@ -595,7 +595,7 @@ class BelongsToMany extends Association { ...@@ -595,7 +595,7 @@ class BelongsToMany extends Association {
return Utils.Promise.all(promises); return Utils.Promise.all(promises);
}; };
return association.through.model.findAll(_.defaults({where, raw: true}, options)) return association.through.model.findAll(_.defaults({ where, raw: true }, options))
.then(currentRows => updateAssociations(currentRows)) .then(currentRows => updateAssociations(currentRows))
.catch(error => { .catch(error => {
if (error instanceof EmptyResultError) return updateAssociations([]); if (error instanceof EmptyResultError) return updateAssociations([]);
...@@ -683,13 +683,13 @@ class BelongsToMany extends Association { ...@@ -683,13 +683,13 @@ class BelongsToMany extends Association {
where[identifier] = sourceInstance.get(sourceKey); where[identifier] = sourceInstance.get(sourceKey);
where[foreignIdentifier] = assoc.get(targetKey); where[foreignIdentifier] = assoc.get(targetKey);
promises.push(association.through.model.update(attributes, Object.assign(options, {where}))); promises.push(association.through.model.update(attributes, Object.assign(options, { where })));
} }
return Utils.Promise.all(promises); return Utils.Promise.all(promises);
}; };
return association.through.model.findAll(_.defaults({where, raw: true}, options)) return association.through.model.findAll(_.defaults({ where, raw: true }, options))
.then(currentRows => updateAssociations(currentRows)) .then(currentRows => updateAssociations(currentRows))
.then(([associations]) => associations) .then(([associations]) => associations)
.catch(error => { .catch(error => {
...@@ -718,7 +718,7 @@ class BelongsToMany extends Association { ...@@ -718,7 +718,7 @@ class BelongsToMany extends Association {
where[association.identifier] = sourceInstance.get(association.source.primaryKeyAttribute); where[association.identifier] = sourceInstance.get(association.source.primaryKeyAttribute);
where[association.foreignIdentifier] = oldAssociatedObjects.map(newInstance => newInstance.get(association.target.primaryKeyAttribute)); where[association.foreignIdentifier] = oldAssociatedObjects.map(newInstance => newInstance.get(association.target.primaryKeyAttribute));
return association.through.model.destroy(_.defaults({where}, options)); return association.through.model.destroy(_.defaults({ where }, options));
} }
/** /**
......
...@@ -159,18 +159,18 @@ class BelongsTo extends Association { ...@@ -159,18 +159,18 @@ class BelongsTo extends Association {
} }
options.where = options.where ? options.where = options.where ?
{[Op.and]: [where, options.where]} : { [Op.and]: [where, options.where] } :
where; where;
if (instances) { if (instances) {
return Target.findAll(options).then(results => { return Target.findAll(options).then(results => {
const result = {}; const result = {};
for (const instance of instances) { for (const instance of instances) {
result[instance.get(this.foreignKey, {raw: true})] = null; result[instance.get(this.foreignKey, { raw: true })] = null;
} }
for (const instance of results) { for (const instance of results) {
result[instance.get(this.targetKey, {raw: true})] = instance; result[instance.get(this.targetKey, { raw: true })] = instance;
} }
return result; return result;
......
...@@ -323,7 +323,7 @@ class HasMany extends Association { ...@@ -323,7 +323,7 @@ class HasMany extends Association {
targetInstances = this.toInstanceArray(targetInstances); targetInstances = this.toInstanceArray(targetInstances);
} }
return this.get(sourceInstance, _.defaults({scope: false, raw: true}, options)).then(oldAssociations => { return this.get(sourceInstance, _.defaults({ scope: false, raw: true }, options)).then(oldAssociations => {
const promises = []; const promises = [];
const obsoleteAssociations = oldAssociations.filter(old => const obsoleteAssociations = oldAssociations.filter(old =>
!targetInstances.find(obj => !targetInstances.find(obj =>
...@@ -404,7 +404,7 @@ class HasMany extends Association { ...@@ -404,7 +404,7 @@ class HasMany extends Association {
unassociatedObject.get(this.target.primaryKeyAttribute) unassociatedObject.get(this.target.primaryKeyAttribute)
); );
return this.target.unscoped().update(update, _.defaults({where}, options)).return(sourceInstance); return this.target.unscoped().update(update, _.defaults({ where }, options)).return(sourceInstance);
} }
/** /**
...@@ -429,7 +429,7 @@ class HasMany extends Association { ...@@ -429,7 +429,7 @@ class HasMany extends Association {
targetInstance.get(this.target.primaryKeyAttribute) targetInstance.get(this.target.primaryKeyAttribute)
); );
return this.target.unscoped().update(update, _.defaults({where}, options)).return(this); return this.target.unscoped().update(update, _.defaults({ where }, options)).return(this);
} }
/** /**
......
...@@ -159,18 +159,18 @@ class HasOne extends Association { ...@@ -159,18 +159,18 @@ class HasOne extends Association {
} }
options.where = options.where ? options.where = options.where ?
{[Op.and]: [where, options.where]} : { [Op.and]: [where, options.where] } :
where; where;
if (instances) { if (instances) {
return Target.findAll(options).then(results => { return Target.findAll(options).then(results => {
const result = {}; const result = {};
for (const instance of instances) { for (const instance of instances) {
result[instance.get(this.sourceKey, {raw: true})] = null; result[instance.get(this.sourceKey, { raw: true })] = null;
} }
for (const instance of results) { for (const instance of results) {
result[instance.get(this.foreignKey, {raw: true})] = instance; result[instance.get(this.foreignKey, { raw: true })] = instance;
} }
return result; return result;
...@@ -199,7 +199,7 @@ class HasOne extends Association { ...@@ -199,7 +199,7 @@ class HasOne extends Association {
return sourceInstance[this.accessors.get](options).then(oldInstance => { return sourceInstance[this.accessors.get](options).then(oldInstance => {
// TODO Use equals method once #5605 is resolved // TODO Use equals method once #5605 is resolved
alreadyAssociated = oldInstance && associatedInstance && _.every(this.target.primaryKeyAttributes, attribute => alreadyAssociated = oldInstance && associatedInstance && _.every(this.target.primaryKeyAttributes, attribute =>
oldInstance.get(attribute, {raw: true}) === (associatedInstance.get ? associatedInstance.get(attribute, {raw: true}) : associatedInstance) oldInstance.get(attribute, { raw: true }) === (associatedInstance.get ? associatedInstance.get(attribute, { raw: true }) : associatedInstance)
); );
if (oldInstance && !alreadyAssociated) { if (oldInstance && !alreadyAssociated) {
......
...@@ -27,7 +27,7 @@ const Mixin = { ...@@ -27,7 +27,7 @@ const Mixin = {
options = Object.assign(options, _.omit(source.options, ['hooks'])); options = Object.assign(options, _.omit(source.options, ['hooks']));
if (options.useHooks) { if (options.useHooks) {
this.runHooks('beforeAssociate', {source, target, type: HasMany}, options); this.runHooks('beforeAssociate', { source, target, type: HasMany }, options);
} }
// the id is in the foreign table or in a connecting table // the id is in the foreign table or in a connecting table
...@@ -38,7 +38,7 @@ const Mixin = { ...@@ -38,7 +38,7 @@ const Mixin = {
association.mixin(source.prototype); association.mixin(source.prototype);
if (options.useHooks) { if (options.useHooks) {
this.runHooks('afterAssociate', {source, target, type: HasMany, association}, options); this.runHooks('afterAssociate', { source, target, type: HasMany, association }, options);
} }
return association; return association;
...@@ -58,7 +58,7 @@ const Mixin = { ...@@ -58,7 +58,7 @@ const Mixin = {
options = Object.assign(options, _.omit(source.options, ['hooks', 'timestamps', 'scopes', 'defaultScope'])); options = Object.assign(options, _.omit(source.options, ['hooks', 'timestamps', 'scopes', 'defaultScope']));
if (options.useHooks) { if (options.useHooks) {
this.runHooks('beforeAssociate', {source, target, type: BelongsToMany}, options); this.runHooks('beforeAssociate', { source, target, type: BelongsToMany }, options);
} }
// the id is in the foreign table or in a connecting table // the id is in the foreign table or in a connecting table
const association = new BelongsToMany(source, target, options); const association = new BelongsToMany(source, target, options);
...@@ -68,7 +68,7 @@ const Mixin = { ...@@ -68,7 +68,7 @@ const Mixin = {
association.mixin(source.prototype); association.mixin(source.prototype);
if (options.useHooks) { if (options.useHooks) {
this.runHooks('afterAssociate', {source, target, type: BelongsToMany, association}, options); this.runHooks('afterAssociate', { source, target, type: BelongsToMany, association }, options);
} }
return association; return association;
...@@ -98,7 +98,7 @@ function singleLinked(Type) { ...@@ -98,7 +98,7 @@ function singleLinked(Type) {
options.useHooks = options.hooks; options.useHooks = options.hooks;
if (options.useHooks) { if (options.useHooks) {
this.runHooks('beforeAssociate', {source, target, type: Type}, options); this.runHooks('beforeAssociate', { source, target, type: Type }, options);
} }
// the id is in the foreign table // the id is in the foreign table
const association = new Type(source, target, Object.assign(options, source.options)); const association = new Type(source, target, Object.assign(options, source.options));
...@@ -108,7 +108,7 @@ function singleLinked(Type) { ...@@ -108,7 +108,7 @@ function singleLinked(Type) {
association.mixin(source.prototype); association.mixin(source.prototype);
if (options.useHooks) { if (options.useHooks) {
this.runHooks('afterAssociate', {source, target, type: Type, association}, options); this.runHooks('afterAssociate', { source, target, type: Type, association }, options);
} }
return association; return association;
......
...@@ -51,7 +51,7 @@ ABSTRACT.prototype.bindParam = function bindParam(value, options) { ...@@ -51,7 +51,7 @@ ABSTRACT.prototype.bindParam = function bindParam(value, options) {
* *
*/ */
function STRING(length, binary) { function STRING(length, binary) {
const options = typeof length === 'object' && length || {length, binary}; const options = typeof length === 'object' && length || { length, binary };
if (!(this instanceof STRING)) return new STRING(options); if (!(this instanceof STRING)) return new STRING(options);
...@@ -92,7 +92,7 @@ Object.defineProperty(STRING.prototype, 'BINARY', { ...@@ -92,7 +92,7 @@ Object.defineProperty(STRING.prototype, 'BINARY', {
* @namespace DataTypes.CHAR * @namespace DataTypes.CHAR
*/ */
function CHAR(length, binary) { function CHAR(length, binary) {
const options = typeof length === 'object' && length || {length, binary}; const options = typeof length === 'object' && length || { length, binary };
if (!(this instanceof CHAR)) return new CHAR(options); if (!(this instanceof CHAR)) return new CHAR(options);
STRING.apply(this, arguments); STRING.apply(this, arguments);
...@@ -112,7 +112,7 @@ CHAR.prototype.toSql = function toSql() { ...@@ -112,7 +112,7 @@ CHAR.prototype.toSql = function toSql() {
* @namespace DataTypes.TEXT * @namespace DataTypes.TEXT
*/ */
function TEXT(length) { function TEXT(length) {
const options = typeof length === 'object' && length || {length}; const options = typeof length === 'object' && length || { length };
if (!(this instanceof TEXT)) return new TEXT(options); if (!(this instanceof TEXT)) return new TEXT(options);
this.options = options; this.options = options;
this._length = options.length || ''; this._length = options.length || '';
...@@ -237,7 +237,7 @@ Object.defineProperty(NUMBER.prototype, 'ZEROFILL', { ...@@ -237,7 +237,7 @@ Object.defineProperty(NUMBER.prototype, 'ZEROFILL', {
* @namespace DataTypes.INTEGER * @namespace DataTypes.INTEGER
*/ */
function INTEGER(length) { function INTEGER(length) {
const options = typeof length === 'object' && length || {length}; const options = typeof length === 'object' && length || { length };
if (!(this instanceof INTEGER)) return new INTEGER(options); if (!(this instanceof INTEGER)) return new INTEGER(options);
NUMBER.call(this, options); NUMBER.call(this, options);
} }
...@@ -260,7 +260,7 @@ INTEGER.prototype.validate = function validate(value) { ...@@ -260,7 +260,7 @@ INTEGER.prototype.validate = function validate(value) {
* @namespace DataTypes.TINYINT * @namespace DataTypes.TINYINT
*/ */
function TINYINT(length) { function TINYINT(length) {
const options = typeof length === 'object' && length || {length}; const options = typeof length === 'object' && length || { length };
if (!(this instanceof TINYINT)) return new TINYINT(options); if (!(this instanceof TINYINT)) return new TINYINT(options);
NUMBER.call(this, options); NUMBER.call(this, options);
} }
...@@ -276,7 +276,7 @@ TINYINT.prototype.key = TINYINT.key = 'TINYINT'; ...@@ -276,7 +276,7 @@ TINYINT.prototype.key = TINYINT.key = 'TINYINT';
* @namespace DataTypes.SMALLINT * @namespace DataTypes.SMALLINT
*/ */
function SMALLINT(length) { function SMALLINT(length) {
const options = typeof length === 'object' && length || {length}; const options = typeof length === 'object' && length || { length };
if (!(this instanceof SMALLINT)) return new SMALLINT(options); if (!(this instanceof SMALLINT)) return new SMALLINT(options);
NUMBER.call(this, options); NUMBER.call(this, options);
} }
...@@ -292,7 +292,7 @@ SMALLINT.prototype.key = SMALLINT.key = 'SMALLINT'; ...@@ -292,7 +292,7 @@ SMALLINT.prototype.key = SMALLINT.key = 'SMALLINT';
* @namespace DataTypes.MEDIUMINT * @namespace DataTypes.MEDIUMINT
*/ */
function MEDIUMINT(length) { function MEDIUMINT(length) {
const options = typeof length === 'object' && length || {length}; const options = typeof length === 'object' && length || { length };
if (!(this instanceof MEDIUMINT)) return new MEDIUMINT(options); if (!(this instanceof MEDIUMINT)) return new MEDIUMINT(options);
NUMBER.call(this, options); NUMBER.call(this, options);
} }
...@@ -308,7 +308,7 @@ MEDIUMINT.prototype.key = MEDIUMINT.key = 'MEDIUMINT'; ...@@ -308,7 +308,7 @@ MEDIUMINT.prototype.key = MEDIUMINT.key = 'MEDIUMINT';
* @namespace DataTypes.BIGINT * @namespace DataTypes.BIGINT
*/ */
function BIGINT(length) { function BIGINT(length) {
const options = typeof length === 'object' && length || {length}; const options = typeof length === 'object' && length || { length };
if (!(this instanceof BIGINT)) return new BIGINT(options); if (!(this instanceof BIGINT)) return new BIGINT(options);
NUMBER.call(this, options); NUMBER.call(this, options);
} }
...@@ -325,7 +325,7 @@ BIGINT.prototype.key = BIGINT.key = 'BIGINT'; ...@@ -325,7 +325,7 @@ BIGINT.prototype.key = BIGINT.key = 'BIGINT';
* @namespace DataTypes.FLOAT * @namespace DataTypes.FLOAT
*/ */
function FLOAT(length, decimals) { function FLOAT(length, decimals) {
const options = typeof length === 'object' && length || {length, decimals}; const options = typeof length === 'object' && length || { length, decimals };
if (!(this instanceof FLOAT)) return new FLOAT(options); if (!(this instanceof FLOAT)) return new FLOAT(options);
NUMBER.call(this, options); NUMBER.call(this, options);
} }
...@@ -349,7 +349,7 @@ FLOAT.prototype.validate = function validate(value) { ...@@ -349,7 +349,7 @@ FLOAT.prototype.validate = function validate(value) {
* @namespace DataTypes.REAL * @namespace DataTypes.REAL
*/ */
function REAL(length, decimals) { function REAL(length, decimals) {
const options = typeof length === 'object' && length || {length, decimals}; const options = typeof length === 'object' && length || { length, decimals };
if (!(this instanceof REAL)) return new REAL(options); if (!(this instanceof REAL)) return new REAL(options);
NUMBER.call(this, options); NUMBER.call(this, options);
} }
...@@ -366,7 +366,7 @@ REAL.prototype.key = REAL.key = 'REAL'; ...@@ -366,7 +366,7 @@ REAL.prototype.key = REAL.key = 'REAL';
* @namespace DataTypes.DOUBLE * @namespace DataTypes.DOUBLE
*/ */
function DOUBLE(length, decimals) { function DOUBLE(length, decimals) {
const options = typeof length === 'object' && length || {length, decimals}; const options = typeof length === 'object' && length || { length, decimals };
if (!(this instanceof DOUBLE)) return new DOUBLE(options); if (!(this instanceof DOUBLE)) return new DOUBLE(options);
NUMBER.call(this, options); NUMBER.call(this, options);
} }
...@@ -383,7 +383,7 @@ DOUBLE.prototype.key = DOUBLE.key = 'DOUBLE PRECISION'; ...@@ -383,7 +383,7 @@ DOUBLE.prototype.key = DOUBLE.key = 'DOUBLE PRECISION';
* @namespace DataTypes.DECIMAL * @namespace DataTypes.DECIMAL
*/ */
function DECIMAL(precision, scale) { function DECIMAL(precision, scale) {
const options = typeof precision === 'object' && precision || {precision, scale}; const options = typeof precision === 'object' && precision || { precision, scale };
if (!(this instanceof DECIMAL)) return new DECIMAL(options); if (!(this instanceof DECIMAL)) return new DECIMAL(options);
NUMBER.call(this, options); NUMBER.call(this, options);
} }
...@@ -498,7 +498,7 @@ TIME.prototype.toSql = function toSql() { ...@@ -498,7 +498,7 @@ TIME.prototype.toSql = function toSql() {
* @namespace DataTypes.DATE * @namespace DataTypes.DATE
*/ */
function DATE(length) { function DATE(length) {
const options = typeof length === 'object' && length || {length}; const options = typeof length === 'object' && length || { length };
if (!(this instanceof DATE)) return new DATE(options); if (!(this instanceof DATE)) return new DATE(options);
...@@ -675,7 +675,7 @@ NOW.prototype.key = NOW.key = 'NOW'; ...@@ -675,7 +675,7 @@ NOW.prototype.key = NOW.key = 'NOW';
* *
*/ */
function BLOB(length) { function BLOB(length) {
const options = typeof length === 'object' && length || {length}; const options = typeof length === 'object' && length || { length };
if (!(this instanceof BLOB)) return new BLOB(options); if (!(this instanceof BLOB)) return new BLOB(options);
this.options = options; this.options = options;
this._length = options.length || ''; this._length = options.length || '';
...@@ -741,7 +741,7 @@ BLOB.prototype._bindParam = function _bindParam(value, options) { ...@@ -741,7 +741,7 @@ BLOB.prototype._bindParam = function _bindParam(value, options) {
* @namespace DataTypes.RANGE * @namespace DataTypes.RANGE
*/ */
function RANGE(subtype) { function RANGE(subtype) {
const options = _.isPlainObject(subtype) ? subtype : {subtype}; const options = _.isPlainObject(subtype) ? subtype : { subtype };
if (!options.subtype) options.subtype = new INTEGER(); if (!options.subtype) options.subtype = new INTEGER();
...@@ -931,7 +931,7 @@ ENUM.prototype.validate = function validate(value) { ...@@ -931,7 +931,7 @@ ENUM.prototype.validate = function validate(value) {
* @namespace DataTypes.ARRAY * @namespace DataTypes.ARRAY
*/ */
function ARRAY(type) { function ARRAY(type) {
const options = _.isPlainObject(type) ? type : {type}; const options = _.isPlainObject(type) ? type : { type };
if (!(this instanceof ARRAY)) return new ARRAY(options); if (!(this instanceof ARRAY)) return new ARRAY(options);
this.type = typeof options.type === 'function' ? new options.type() : options.type; this.type = typeof options.type === 'function' ? new options.type() : options.type;
} }
...@@ -1002,7 +1002,7 @@ ARRAY.is = function is(obj, type) { ...@@ -1002,7 +1002,7 @@ ARRAY.is = function is(obj, type) {
* @namespace DataTypes.GEOMETRY * @namespace DataTypes.GEOMETRY
*/ */
function GEOMETRY(type, srid) { function GEOMETRY(type, srid) {
const options = _.isPlainObject(type) ? type : {type, srid}; const options = _.isPlainObject(type) ? type : { type, srid };
if (!(this instanceof GEOMETRY)) return new GEOMETRY(options); if (!(this instanceof GEOMETRY)) return new GEOMETRY(options);
...@@ -1049,7 +1049,7 @@ GEOMETRY.prototype._bindParam = function _bindParam(value, options) { ...@@ -1049,7 +1049,7 @@ GEOMETRY.prototype._bindParam = function _bindParam(value, options) {
* @namespace DataTypes.GEOGRAPHY * @namespace DataTypes.GEOGRAPHY
*/ */
function GEOGRAPHY(type, srid) { function GEOGRAPHY(type, srid) {
const options = _.isPlainObject(type) ? type : {type, srid}; const options = _.isPlainObject(type) ? type : { type, srid };
if (!(this instanceof GEOGRAPHY)) return new GEOGRAPHY(options); if (!(this instanceof GEOGRAPHY)) return new GEOGRAPHY(options);
......
...@@ -248,7 +248,7 @@ class ConnectionManager { ...@@ -248,7 +248,7 @@ class ConnectionManager {
.then(connection => { .then(connection => {
const _options = {}; const _options = {};
_options.transaction = {connection}; // Cheat .query to use our private connection _options.transaction = { connection }; // Cheat .query to use our private connection
_options.logging = () => {}; _options.logging = () => {};
_options.logging.__testLoggingFn = true; _options.logging.__testLoggingFn = true;
......
...@@ -399,9 +399,9 @@ class QueryGenerator { ...@@ -399,9 +399,9 @@ class QueryGenerator {
const value = attrValueHash[key]; const value = attrValueHash[key];
if (value instanceof Utils.SequelizeMethod || options.bindParam === false) { if (value instanceof Utils.SequelizeMethod || options.bindParam === false) {
values.push(`${this.quoteIdentifier(key)}=${this.escape(value, modelAttributeMap && modelAttributeMap[key] || undefined, { context: 'UPDATE'})}`); values.push(`${this.quoteIdentifier(key)}=${this.escape(value, modelAttributeMap && modelAttributeMap[key] || undefined, { context: 'UPDATE' })}`);
} else { } else {
values.push(`${this.quoteIdentifier(key)}=${this.format(value, modelAttributeMap && modelAttributeMap[key] || undefined, { context: 'UPDATE'}, bindParam)}`); values.push(`${this.quoteIdentifier(key)}=${this.format(value, modelAttributeMap && modelAttributeMap[key] || undefined, { context: 'UPDATE' }, bindParam)}`);
} }
} }
...@@ -1840,7 +1840,7 @@ class QueryGenerator { ...@@ -1840,7 +1840,7 @@ class QueryGenerator {
* are preserved. * are preserved.
*/ */
_getRequiredClosure(include) { _getRequiredClosure(include) {
const copy = Object.assign({}, include, {attributes: [], include: []}); const copy = Object.assign({}, include, { attributes: [], include: [] });
if (Array.isArray(include.include)) { if (Array.isArray(include.include)) {
copy.include = include.include copy.include = include.include
...@@ -1895,7 +1895,7 @@ class QueryGenerator { ...@@ -1895,7 +1895,7 @@ class QueryGenerator {
throw new Error('Order must be type of array or instance of a valid sequelize method.'); throw new Error('Order must be type of array or instance of a valid sequelize method.');
} }
return {mainQueryOrder, subQueryOrder}; return { mainQueryOrder, subQueryOrder };
} }
selectFromTableFragment(options, model, attributes, tables, mainTableAs) { selectFromTableFragment(options, model, attributes, tables, mainTableAs) {
...@@ -2056,7 +2056,7 @@ class QueryGenerator { ...@@ -2056,7 +2056,7 @@ class QueryGenerator {
const tmp = {}; const tmp = {};
const field = options.model.rawAttributes[keyParts[0]]; const field = options.model.rawAttributes[keyParts[0]];
_.set(tmp, keyParts.slice(1), value); _.set(tmp, keyParts.slice(1), value);
return this.whereItemQuery(field.field || keyParts[0], tmp, Object.assign({field}, options)); return this.whereItemQuery(field.field || keyParts[0], tmp, Object.assign({ field }, options));
} }
} }
...@@ -2194,7 +2194,7 @@ class QueryGenerator { ...@@ -2194,7 +2194,7 @@ class QueryGenerator {
if (_.isPlainObject(value)) { if (_.isPlainObject(value)) {
value = Utils.getComplexKeys(value).map(prop => { value = Utils.getComplexKeys(value).map(prop => {
const item = value[prop]; const item = value[prop];
return this.whereItemQuery(key, {[prop]: item}, options); return this.whereItemQuery(key, { [prop]: item }, options);
}); });
} else { } else {
value = value.map(item => this.whereItemQuery(key, item, options)); value = value.map(item => this.whereItemQuery(key, item, options));
...@@ -2219,7 +2219,7 @@ class QueryGenerator { ...@@ -2219,7 +2219,7 @@ class QueryGenerator {
Utils.getOperators(value).forEach(op => { Utils.getOperators(value).forEach(op => {
const where = {}; const where = {};
where[op] = value[op]; where[op] = value[op];
items.push(this.whereItemQuery(key, where, Object.assign({}, options, {json: false}))); items.push(this.whereItemQuery(key, where, Object.assign({}, options, { json: false })));
}); });
_.forOwn(value, (item, prop) => { _.forOwn(value, (item, prop) => {
...@@ -2244,7 +2244,7 @@ class QueryGenerator { ...@@ -2244,7 +2244,7 @@ class QueryGenerator {
if (_.isPlainObject(item)) { if (_.isPlainObject(item)) {
Utils.getOperators(item).forEach(op => { Utils.getOperators(item).forEach(op => {
const value = this._toJSONValue(item[op]); const value = this._toJSONValue(item[op]);
items.push(this.whereItemQuery(this._castKey(pathKey, value, cast), {[op]: value})); items.push(this.whereItemQuery(this._castKey(pathKey, value, cast), { [op]: value }));
}); });
_.forOwn(item, (value, itemProp) => { _.forOwn(item, (value, itemProp) => {
this._traverseJSON(items, baseKey, itemProp, value, path.concat([itemProp])); this._traverseJSON(items, baseKey, itemProp, value, path.concat([itemProp]));
...@@ -2254,7 +2254,7 @@ class QueryGenerator { ...@@ -2254,7 +2254,7 @@ class QueryGenerator {
} }
item = this._toJSONValue(item); item = this._toJSONValue(item);
items.push(this.whereItemQuery(this._castKey(pathKey, item, cast), {[Op.eq]: item})); items.push(this.whereItemQuery(this._castKey(pathKey, item, cast), { [Op.eq]: item }));
} }
_toJSONValue(value) { _toJSONValue(value) {
......
...@@ -152,7 +152,7 @@ class Query extends AbstractQuery { ...@@ -152,7 +152,7 @@ class Query extends AbstractQuery {
result = new Array(data.affectedRows); result = new Array(data.affectedRows);
const pkField = this.model.rawAttributes[this.model.primaryKeyAttribute].field; const pkField = this.model.rawAttributes[this.model.primaryKeyAttribute].field;
for (let i = 0; i < data.affectedRows; i++) { for (let i = 0; i < data.affectedRows; i++) {
result[i] = {[pkField]: startId + i}; result[i] = { [pkField]: startId + i };
} }
return [result, data.affectedRows]; return [result, data.affectedRows];
} }
...@@ -292,7 +292,7 @@ class Query extends AbstractQuery { ...@@ -292,7 +292,7 @@ class Query extends AbstractQuery {
}); });
return new sequelizeErrors.UniqueConstraintError( return new sequelizeErrors.UniqueConstraintError(
{message, errors, parent: err, fields}); { message, errors, parent: err, fields });
} }
case ER_ROW_IS_REFERENCED: case ER_ROW_IS_REFERENCED:
......
...@@ -29,7 +29,7 @@ class Query extends AbstractQuery { ...@@ -29,7 +29,7 @@ class Query extends AbstractQuery {
} }
getSQLTypeFromJsType(value, TYPES) { getSQLTypeFromJsType(value, TYPES) {
const paramType = {type: TYPES.VarChar, typeOptions: {} }; const paramType = { type: TYPES.VarChar, typeOptions: {} };
paramType.type = TYPES.NVarChar; paramType.type = TYPES.NVarChar;
if (typeof value === 'number') { if (typeof value === 'number') {
if (Number.isInteger(value)) { if (Number.isInteger(value)) {
...@@ -37,7 +37,7 @@ class Query extends AbstractQuery { ...@@ -37,7 +37,7 @@ class Query extends AbstractQuery {
} else { } else {
paramType.type = TYPES.Numeric; paramType.type = TYPES.Numeric;
//Default to a reasonable numeric precision/scale pending more sophisticated logic //Default to a reasonable numeric precision/scale pending more sophisticated logic
paramType.typeOptions = {precision: 30, scale: 15}; paramType.typeOptions = { precision: 30, scale: 15 };
} }
} }
if (Buffer.isBuffer(value)) { if (Buffer.isBuffer(value)) {
......
...@@ -95,7 +95,7 @@ class ConnectionManager extends AbstractConnectionManager { ...@@ -95,7 +95,7 @@ class ConnectionManager extends AbstractConnectionManager {
connection.on('error', errorHandler); connection.on('error', errorHandler);
connection.once('connect', connectHandler); connection.once('connect', connectHandler);
}) })
.tap (() => { debug('connection acquired'); }) .tap(() => { debug('connection acquired'); })
.then(connection => { .then(connection => {
connection.on('error', error => { connection.on('error', error => {
switch (error.code) { switch (error.code) {
......
...@@ -357,7 +357,7 @@ class MySQLQueryGenerator extends AbstractQueryGenerator { ...@@ -357,7 +357,7 @@ class MySQLQueryGenerator extends AbstractQueryGenerator {
}; };
} }
const attributeString = attribute.type.toString({escape: this.escape.bind(this)}); const attributeString = attribute.type.toString({ escape: this.escape.bind(this) });
let template = attributeString; let template = attributeString;
if (attribute.allowNull === false) { if (attribute.allowNull === false) {
......
...@@ -28,7 +28,7 @@ function removeColumn(tableName, columnName, options) { ...@@ -28,7 +28,7 @@ function removeColumn(tableName, columnName, options) {
tableName, tableName,
schema: this.sequelize.config.database schema: this.sequelize.config.database
}, columnName), }, columnName),
Object.assign({raw: true}, options) Object.assign({ raw: true }, options)
) )
.then(([results]) => { .then(([results]) => {
//Exclude primary key constraint //Exclude primary key constraint
...@@ -38,12 +38,12 @@ function removeColumn(tableName, columnName, options) { ...@@ -38,12 +38,12 @@ function removeColumn(tableName, columnName, options) {
} }
return Promise.map(results, constraint => this.sequelize.query( return Promise.map(results, constraint => this.sequelize.query(
this.QueryGenerator.dropForeignKeyQuery(tableName, constraint.constraint_name), this.QueryGenerator.dropForeignKeyQuery(tableName, constraint.constraint_name),
Object.assign({raw: true}, options) Object.assign({ raw: true }, options)
)); ));
}) })
.then(() => this.sequelize.query( .then(() => this.sequelize.query(
this.QueryGenerator.removeColumnQuery(tableName, columnName), this.QueryGenerator.removeColumnQuery(tableName, columnName),
Object.assign({raw: true}, options) Object.assign({ raw: true }, options)
)); ));
} }
...@@ -55,7 +55,7 @@ function removeConstraint(tableName, constraintName, options) { ...@@ -55,7 +55,7 @@ function removeConstraint(tableName, constraintName, options) {
}, constraintName); }, constraintName);
return this.sequelize.query(sql, Object.assign({}, options, return this.sequelize.query(sql, Object.assign({}, options,
{type: this.sequelize.QueryTypes.SHOWCONSTRAINTS})) { type: this.sequelize.QueryTypes.SHOWCONSTRAINTS }))
.then(constraints => { .then(constraints => {
const constraint = constraints[0]; const constraint = constraints[0];
let query; let query;
......
...@@ -239,7 +239,7 @@ class Query extends AbstractQuery { ...@@ -239,7 +239,7 @@ class Query extends AbstractQuery {
)); ));
}); });
return new sequelizeErrors.UniqueConstraintError({message, errors, parent: err, fields}); return new sequelizeErrors.UniqueConstraintError({ message, errors, parent: err, fields });
} }
case 1451: case 1451:
......
...@@ -29,7 +29,7 @@ class ConnectionManager extends AbstractConnectionManager { ...@@ -29,7 +29,7 @@ class ConnectionManager extends AbstractConnectionManager {
return value => this.lib.types.arrayParser.create(value, parser).parse(); return value => this.lib.types.arrayParser.create(value, parser).parse();
}; };
const rangeParserBuilder = parser => { const rangeParserBuilder = parser => {
return value => dataType.parse(value, {parser}); return value => dataType.parse(value, { parser });
}; };
// Set range parsers // Set range parsers
...@@ -252,7 +252,7 @@ class ConnectionManager extends AbstractConnectionManager { ...@@ -252,7 +252,7 @@ class ConnectionManager extends AbstractConnectionManager {
} }
const newNameOidMap = {}; const newNameOidMap = {};
const newEnumOids = {oids: [], arrayOids: []}; const newEnumOids = { oids: [], arrayOids: [] };
for (const row of result.rows) { for (const row of result.rows) {
// Mapping enums, handled separatedly // Mapping enums, handled separatedly
...@@ -263,7 +263,7 @@ class ConnectionManager extends AbstractConnectionManager { ...@@ -263,7 +263,7 @@ class ConnectionManager extends AbstractConnectionManager {
} }
// Mapping base types and their arrays // Mapping base types and their arrays
newNameOidMap[row.typname] = {oid: row.oid}; newNameOidMap[row.typname] = { oid: row.oid };
if (row.typarray) newNameOidMap[row.typname].arrayOid = row.typarray; if (row.typarray) newNameOidMap[row.typname].arrayOid = row.typarray;
// Mapping ranges(of base types) and their arrays // Mapping ranges(of base types) and their arrays
...@@ -283,7 +283,7 @@ class ConnectionManager extends AbstractConnectionManager { ...@@ -283,7 +283,7 @@ class ConnectionManager extends AbstractConnectionManager {
_clearDynamicOIDs() { _clearDynamicOIDs() {
this.nameOidMap = {}; this.nameOidMap = {};
this.enumOids = {oids: [], arrayOids: []}; this.enumOids = { oids: [], arrayOids: [] };
} }
} }
......
...@@ -473,7 +473,7 @@ module.exports = BaseTypes => { ...@@ -473,7 +473,7 @@ module.exports = BaseTypes => {
inherits(RANGE, BaseTypes.RANGE); inherits(RANGE, BaseTypes.RANGE);
const range = require('./range'); const range = require('./range');
RANGE.parse = function parse(value, options = {parser: val => val}) { RANGE.parse = function parse(value, options = { parser: val => val }) {
return range.parse(value, options.parser); return range.parse(value, options.parser);
}; };
......
'use strict'; 'use strict';
const hstore = require('pg-hstore')({sanitize: true}); const hstore = require('pg-hstore')({ sanitize: true });
function stringify(data) { function stringify(data) {
if (data === null) return null; if (data === null) return null;
......
...@@ -732,7 +732,7 @@ class PostgresQueryGenerator extends AbstractQueryGenerator { ...@@ -732,7 +732,7 @@ class PostgresQueryGenerator extends AbstractQueryGenerator {
const tableDetails = this.extractTableDetails(tableName, options); const tableDetails = this.extractTableDetails(tableName, options);
if (tableDetails.tableName && attrName) { if (tableDetails.tableName && attrName) {
enumName = ` AND t.typname=${this.pgEnumName(tableDetails.tableName, attrName, { schema: false}).replace(/"/g, "'")}`; enumName = ` AND t.typname=${this.pgEnumName(tableDetails.tableName, attrName, { schema: false }).replace(/"/g, "'")}`;
} }
return 'SELECT t.typname enum_name, array_agg(e.enumlabel ORDER BY enumsortorder) enum_value FROM pg_type t ' + return 'SELECT t.typname enum_name, array_agg(e.enumlabel ORDER BY enumsortorder) enum_value FROM pg_type t ' +
......
...@@ -302,7 +302,7 @@ class Query extends AbstractQuery { ...@@ -302,7 +302,7 @@ class Query extends AbstractQuery {
table = errMessage.match(/on table \"(.+?)\"/); table = errMessage.match(/on table \"(.+?)\"/);
table = table ? table[1] : undefined; table = table ? table[1] : undefined;
return new sequelizeErrors.ForeignKeyConstraintError({message: errMessage, fields: null, index, table, parent: err}); return new sequelizeErrors.ForeignKeyConstraintError({ message: errMessage, fields: null, index, table, parent: err });
case '23505': case '23505':
// there are multiple different formats of error messages for this error code // there are multiple different formats of error messages for this error code
// this regex should check at least two // this regex should check at least two
...@@ -331,7 +331,7 @@ class Query extends AbstractQuery { ...@@ -331,7 +331,7 @@ class Query extends AbstractQuery {
}); });
} }
return new sequelizeErrors.UniqueConstraintError({message, errors, parent: err, fields}); return new sequelizeErrors.UniqueConstraintError({ message, errors, parent: err, fields });
} }
return new sequelizeErrors.UniqueConstraintError({ return new sequelizeErrors.UniqueConstraintError({
......
...@@ -239,9 +239,9 @@ class SQLiteQueryGenerator extends MySqlQueryGenerator { ...@@ -239,9 +239,9 @@ class SQLiteQueryGenerator extends MySqlQueryGenerator {
const value = attrValueHash[key]; const value = attrValueHash[key];
if (value instanceof Utils.SequelizeMethod || options.bindParam === false) { if (value instanceof Utils.SequelizeMethod || options.bindParam === false) {
values.push(`${this.quoteIdentifier(key)}=${this.escape(value, modelAttributeMap && modelAttributeMap[key] || undefined, { context: 'UPDATE'})}`); values.push(`${this.quoteIdentifier(key)}=${this.escape(value, modelAttributeMap && modelAttributeMap[key] || undefined, { context: 'UPDATE' })}`);
} else { } else {
values.push(`${this.quoteIdentifier(key)}=${this.format(value, modelAttributeMap && modelAttributeMap[key] || undefined, { context: 'UPDATE'}, bindParam)}`); values.push(`${this.quoteIdentifier(key)}=${this.format(value, modelAttributeMap && modelAttributeMap[key] || undefined, { context: 'UPDATE' }, bindParam)}`);
} }
} }
......
...@@ -35,7 +35,7 @@ function removeColumn(tableName, attributeName, options) { ...@@ -35,7 +35,7 @@ function removeColumn(tableName, attributeName, options) {
const sql = this.QueryGenerator.removeColumnQuery(tableName, fields); const sql = this.QueryGenerator.removeColumnQuery(tableName, fields);
const subQueries = sql.split(';').filter(q => q !== ''); const subQueries = sql.split(';').filter(q => q !== '');
return Promise.each(subQueries, subQuery => this.sequelize.query(`${subQuery};`, Object.assign({raw: true}, options))); return Promise.each(subQueries, subQuery => this.sequelize.query(`${subQuery};`, Object.assign({ raw: true }, options)));
}); });
} }
exports.removeColumn = removeColumn; exports.removeColumn = removeColumn;
...@@ -63,7 +63,7 @@ function changeColumn(tableName, attributes, options) { ...@@ -63,7 +63,7 @@ function changeColumn(tableName, attributes, options) {
const sql = this.QueryGenerator.removeColumnQuery(tableName, fields); const sql = this.QueryGenerator.removeColumnQuery(tableName, fields);
const subQueries = sql.split(';').filter(q => q !== ''); const subQueries = sql.split(';').filter(q => q !== '');
return Promise.each(subQueries, subQuery => this.sequelize.query(`${subQuery};`, Object.assign({raw: true}, options))); return Promise.each(subQueries, subQuery => this.sequelize.query(`${subQuery};`, Object.assign({ raw: true }, options)));
}); });
} }
exports.changeColumn = changeColumn; exports.changeColumn = changeColumn;
...@@ -92,7 +92,7 @@ function renameColumn(tableName, attrNameBefore, attrNameAfter, options) { ...@@ -92,7 +92,7 @@ function renameColumn(tableName, attrNameBefore, attrNameAfter, options) {
const sql = this.QueryGenerator.renameColumnQuery(tableName, attrNameBefore, attrNameAfter, fields); const sql = this.QueryGenerator.renameColumnQuery(tableName, attrNameBefore, attrNameAfter, fields);
const subQueries = sql.split(';').filter(q => q !== ''); const subQueries = sql.split(';').filter(q => q !== '');
return Promise.each(subQueries, subQuery => this.sequelize.query(`${subQuery};`, Object.assign({raw: true}, options))); return Promise.each(subQueries, subQuery => this.sequelize.query(`${subQuery};`, Object.assign({ raw: true }, options)));
}); });
} }
exports.renameColumn = renameColumn; exports.renameColumn = renameColumn;
...@@ -133,7 +133,7 @@ function removeConstraint(tableName, constraintName, options) { ...@@ -133,7 +133,7 @@ function removeConstraint(tableName, constraintName, options) {
const sql = this.QueryGenerator._alterConstraintQuery(tableName, fields, createTableSql); const sql = this.QueryGenerator._alterConstraintQuery(tableName, fields, createTableSql);
const subQueries = sql.split(';').filter(q => q !== ''); const subQueries = sql.split(';').filter(q => q !== '');
return Promise.each(subQueries, subQuery => this.sequelize.query(`${subQuery};`, Object.assign({raw: true}, options))); return Promise.each(subQueries, subQuery => this.sequelize.query(`${subQuery};`, Object.assign({ raw: true }, options)));
}); });
} }
exports.removeConstraint = removeConstraint; exports.removeConstraint = removeConstraint;
...@@ -157,7 +157,7 @@ function addConstraint(tableName, options) { ...@@ -157,7 +157,7 @@ function addConstraint(tableName, options) {
const sql = this.QueryGenerator._alterConstraintQuery(tableName, fields, createTableSql); const sql = this.QueryGenerator._alterConstraintQuery(tableName, fields, createTableSql);
const subQueries = sql.split(';').filter(q => q !== ''); const subQueries = sql.split(';').filter(q => q !== '');
return Promise.each(subQueries, subQuery => this.sequelize.query(`${subQuery};`, Object.assign({raw: true}, options))); return Promise.each(subQueries, subQuery => this.sequelize.query(`${subQuery};`, Object.assign({ raw: true }, options)));
}); });
} }
exports.addConstraint = addConstraint; exports.addConstraint = addConstraint;
......
...@@ -432,7 +432,7 @@ class Query extends AbstractQuery { ...@@ -432,7 +432,7 @@ class Query extends AbstractQuery {
}); });
} }
return new sequelizeErrors.UniqueConstraintError({message, errors, parent: err, fields}); return new sequelizeErrors.UniqueConstraintError({ message, errors, parent: err, fields });
} }
case 'SQLITE_BUSY': case 'SQLITE_BUSY':
return new sequelizeErrors.TimeoutError(err); return new sequelizeErrors.TimeoutError(err);
......
...@@ -7,46 +7,46 @@ const Promise = require('./promise'); ...@@ -7,46 +7,46 @@ const Promise = require('./promise');
const debug = logger.getLogger().debugContext('hooks'); const debug = logger.getLogger().debugContext('hooks');
const hookTypes = { const hookTypes = {
beforeValidate: {params: 2}, beforeValidate: { params: 2 },
afterValidate: {params: 2}, afterValidate: { params: 2 },
validationFailed: {params: 3}, validationFailed: { params: 3 },
beforeCreate: {params: 2}, beforeCreate: { params: 2 },
afterCreate: {params: 2}, afterCreate: { params: 2 },
beforeDestroy: {params: 2}, beforeDestroy: { params: 2 },
afterDestroy: {params: 2}, afterDestroy: { params: 2 },
beforeRestore: {params: 2}, beforeRestore: { params: 2 },
afterRestore: {params: 2}, afterRestore: { params: 2 },
beforeUpdate: {params: 2}, beforeUpdate: { params: 2 },
afterUpdate: {params: 2}, afterUpdate: { params: 2 },
beforeSave: {params: 2, proxies: ['beforeUpdate', 'beforeCreate']}, beforeSave: { params: 2, proxies: ['beforeUpdate', 'beforeCreate'] },
afterSave: {params: 2, proxies: ['afterUpdate', 'afterCreate']}, afterSave: { params: 2, proxies: ['afterUpdate', 'afterCreate'] },
beforeUpsert: {params: 2}, beforeUpsert: { params: 2 },
afterUpsert: {params: 2}, afterUpsert: { params: 2 },
beforeBulkCreate: {params: 2}, beforeBulkCreate: { params: 2 },
afterBulkCreate: {params: 2}, afterBulkCreate: { params: 2 },
beforeBulkDestroy: {params: 1}, beforeBulkDestroy: { params: 1 },
afterBulkDestroy: {params: 1}, afterBulkDestroy: { params: 1 },
beforeBulkRestore: {params: 1}, beforeBulkRestore: { params: 1 },
afterBulkRestore: {params: 1}, afterBulkRestore: { params: 1 },
beforeBulkUpdate: {params: 1}, beforeBulkUpdate: { params: 1 },
afterBulkUpdate: {params: 1}, afterBulkUpdate: { params: 1 },
beforeFind: {params: 1}, beforeFind: { params: 1 },
beforeFindAfterExpandIncludeAll: {params: 1}, beforeFindAfterExpandIncludeAll: { params: 1 },
beforeFindAfterOptions: {params: 1}, beforeFindAfterOptions: { params: 1 },
afterFind: {params: 2}, afterFind: { params: 2 },
beforeCount: {params: 1}, beforeCount: { params: 1 },
beforeDefine: {params: 2, sync: true}, beforeDefine: { params: 2, sync: true },
afterDefine: {params: 1, sync: true}, afterDefine: { params: 1, sync: true },
beforeInit: {params: 2, sync: true}, beforeInit: { params: 2, sync: true },
afterInit: {params: 1, sync: true}, afterInit: { params: 1, sync: true },
beforeAssociate: {params: 2, sync: true}, beforeAssociate: { params: 2, sync: true },
afterAssociate: {params: 2, sync: true}, afterAssociate: { params: 2, sync: true },
beforeConnect: {params: 1}, beforeConnect: { params: 1 },
afterConnect: {params: 2}, afterConnect: { params: 2 },
beforeSync: {params: 1}, beforeSync: { params: 1 },
afterSync: {params: 1}, afterSync: { params: 1 },
beforeBulkSync: {params: 1}, beforeBulkSync: { params: 1 },
afterBulkSync: {params: 1} afterBulkSync: { params: 1 }
}; };
exports.hooks = hookTypes; exports.hooks = hookTypes;
...@@ -151,7 +151,7 @@ const Hooks = { ...@@ -151,7 +151,7 @@ const Hooks = {
_.each(hookType, type => { _.each(hookType, type => {
this.options.hooks[type] = getHooks.call(this, type); this.options.hooks[type] = getHooks.call(this, type);
this.options.hooks[type].push(name ? {name, fn} : fn); this.options.hooks[type].push(name ? { name, fn } : fn);
}); });
return this; return this;
......
...@@ -286,7 +286,7 @@ class InstanceValidator { ...@@ -286,7 +286,7 @@ class InstanceValidator {
const validatorArgs = this._extractValidatorArgs(test, validatorType, field); const validatorArgs = this._extractValidatorArgs(test, validatorType, field);
if (!validator[validatorType].apply(validator, [valueString, ...validatorArgs])) { if (!validator[validatorType].apply(validator, [valueString, ...validatorArgs])) {
throw Object.assign(new Error(test.msg || `Validation ${validatorType} on ${field} failed`), { validatorName: validatorType, validatorArgs}); throw Object.assign(new Error(test.msg || `Validation ${validatorType} on ${field} failed`), { validatorName: validatorType, validatorArgs });
} }
}); });
} }
......
...@@ -438,7 +438,7 @@ class Model { ...@@ -438,7 +438,7 @@ class Model {
const model = association.target; const model = association.target;
const as = association.options.as; const as = association.options.as;
const predicate = {model}; const predicate = { model };
if (as) { if (as) {
// We only add 'as' to the predicate if it actually exists // We only add 'as' to the predicate if it actually exists
predicate.as = as; predicate.as = as;
...@@ -619,7 +619,7 @@ class Model { ...@@ -619,7 +619,7 @@ class Model {
if (through.scope) { if (through.scope) {
include.through.where = include.through.where ? { [Op.and]: [include.through.where, through.scope]} : through.scope; include.through.where = include.through.where ? { [Op.and]: [include.through.where, through.scope] } : through.scope;
} }
include.include.push(include.through); include.include.push(include.through);
...@@ -921,7 +921,7 @@ class Model { ...@@ -921,7 +921,7 @@ class Model {
this.sequelize.runHooks('beforeDefine', attributes, options); this.sequelize.runHooks('beforeDefine', attributes, options);
if (options.modelName !== this.name) { if (options.modelName !== this.name) {
Object.defineProperty(this, 'name', {value: options.modelName}); Object.defineProperty(this, 'name', { value: options.modelName });
} }
delete options.modelName; delete options.modelName;
...@@ -1385,7 +1385,7 @@ class Model { ...@@ -1385,7 +1385,7 @@ class Model {
static schema(schema, options) { // testhint options:none static schema(schema, options) { // testhint options:none
const clone = class extends this {}; const clone = class extends this {};
Object.defineProperty(clone, 'name', {value: this.name}); Object.defineProperty(clone, 'name', { value: this.name });
clone._schema = schema; clone._schema = schema;
...@@ -1806,7 +1806,7 @@ class Model { ...@@ -1806,7 +1806,7 @@ class Model {
Object.assign( Object.assign(
{}, {},
_.omit(options, 'include', 'attributes', 'order', 'where', 'limit', 'offset', 'plain', 'scope'), _.omit(options, 'include', 'attributes', 'order', 'where', 'limit', 'offset', 'plain', 'scope'),
{include: include.include || []} { include: include.include || [] }
) )
); );
} }
...@@ -2263,7 +2263,7 @@ class Model { ...@@ -2263,7 +2263,7 @@ class Model {
transaction = t; transaction = t;
options.transaction = t; options.transaction = t;
return this.findOne(Utils.defaults({transaction}, options)); return this.findOne(Utils.defaults({ transaction }, options));
}).then(instance => { }).then(instance => {
if (instance !== null) { if (instance !== null) {
return [instance, false]; return [instance, false];
...@@ -2516,7 +2516,7 @@ class Model { ...@@ -2516,7 +2516,7 @@ class Model {
const updatedAtAttr = this._timestampAttributes.updatedAt; const updatedAtAttr = this._timestampAttributes.updatedAt;
const now = Utils.now(this.sequelize.options.dialect); const now = Utils.now(this.sequelize.options.dialect);
let instances = records.map(values => this.build(values, {isNewRecord: true})); let instances = records.map(values => this.build(values, { isNewRecord: true }));
return Promise.try(() => { return Promise.try(() => {
// Run before hook // Run before hook
...@@ -2701,7 +2701,7 @@ class Model { ...@@ -2701,7 +2701,7 @@ class Model {
}).then(() => { }).then(() => {
// Get daos and run beforeDestroy hook on each record individually // Get daos and run beforeDestroy hook on each record individually
if (options.individualHooks) { if (options.individualHooks) {
return this.findAll({where: options.where, transaction: options.transaction, logging: options.logging, benchmark: options.benchmark}) return this.findAll({ where: options.where, transaction: options.transaction, logging: options.logging, benchmark: options.benchmark })
.map(instance => this.runHooks('beforeDestroy', instance, options).then(() => instance)) .map(instance => this.runHooks('beforeDestroy', instance, options).then(() => instance))
.then(_instances => { .then(_instances => {
instances = _instances; instances = _instances;
...@@ -2774,7 +2774,7 @@ class Model { ...@@ -2774,7 +2774,7 @@ class Model {
}).then(() => { }).then(() => {
// Get daos and run beforeRestore hook on each record individually // Get daos and run beforeRestore hook on each record individually
if (options.individualHooks) { if (options.individualHooks) {
return this.findAll({where: options.where, transaction: options.transaction, logging: options.logging, benchmark: options.benchmark, paranoid: false}) return this.findAll({ where: options.where, transaction: options.transaction, logging: options.logging, benchmark: options.benchmark, paranoid: false })
.map(instance => this.runHooks('beforeRestore', instance, options).then(() => instance)) .map(instance => this.runHooks('beforeRestore', instance, options).then(() => instance))
.then(_instances => { .then(_instances => {
instances = _instances; instances = _instances;
...@@ -2906,7 +2906,7 @@ class Model { ...@@ -2906,7 +2906,7 @@ class Model {
// Get instances and run beforeUpdate hook on each record individually // Get instances and run beforeUpdate hook on each record individually
if (options.individualHooks) { if (options.individualHooks) {
return this.findAll({where: options.where, transaction: options.transaction, logging: options.logging, benchmark: options.benchmark}).then(_instances => { return this.findAll({ where: options.where, transaction: options.transaction, logging: options.logging, benchmark: options.benchmark }).then(_instances => {
instances = _instances; instances = _instances;
if (!instances.length) { if (!instances.length) {
return []; return [];
...@@ -3021,7 +3021,7 @@ class Model { ...@@ -3021,7 +3021,7 @@ class Model {
* @returns {Promise} hash of attributes and their types * @returns {Promise} hash of attributes and their types
*/ */
static describe(schema, options) { static describe(schema, options) {
return this.QueryInterface.describeTable(this.tableName, Object.assign({schema: schema || this._schema || undefined}, options)); return this.QueryInterface.describeTable(this.tableName, Object.assign({ schema: schema || this._schema || undefined }, options));
} }
static _getDefaultTimestamp(attr) { static _getDefaultTimestamp(attr) {
...@@ -3196,7 +3196,7 @@ class Model { ...@@ -3196,7 +3196,7 @@ class Model {
*/ */
where(checkVersion) { where(checkVersion) {
const where = this.constructor.primaryKeyAttributes.reduce((result, attribute) => { const where = this.constructor.primaryKeyAttributes.reduce((result, attribute) => {
result[attribute] = this.get(attribute, {raw: true}); result[attribute] = this.get(attribute, { raw: true });
return result; return result;
}, {}); }, {});
...@@ -3205,7 +3205,7 @@ class Model { ...@@ -3205,7 +3205,7 @@ class Model {
} }
const versionAttr = this.constructor._versionAttribute; const versionAttr = this.constructor._versionAttribute;
if (checkVersion && versionAttr) { if (checkVersion && versionAttr) {
where[versionAttr] = this.get(versionAttr, {raw: true}); where[versionAttr] = this.get(versionAttr, { raw: true });
} }
return Utils.mapWhereFieldNames(where, this.constructor); return Utils.mapWhereFieldNames(where, this.constructor);
} }
...@@ -3619,7 +3619,7 @@ class Model { ...@@ -3619,7 +3619,7 @@ class Model {
options.fields.push(versionAttr); options.fields.push(versionAttr);
} }
if (options.silent === true && !(this.isNewRecord && this.get(updatedAtAttr, {raw: true}))) { if (options.silent === true && !(this.isNewRecord && this.get(updatedAtAttr, { raw: true }))) {
// UpdateAtAttr might have been added as a result of Object.keys(Model.rawAttributes). In that case we have to remove it again // UpdateAtAttr might have been added as a result of Object.keys(Model.rawAttributes). In that case we have to remove it again
_.remove(options.fields, val => val === updatedAtAttr); _.remove(options.fields, val => val === updatedAtAttr);
updatedAtAttr = false; updatedAtAttr = false;
...@@ -3636,7 +3636,7 @@ class Model { ...@@ -3636,7 +3636,7 @@ class Model {
} }
if (this.isNewRecord === false) { if (this.isNewRecord === false) {
if (primaryKeyName && this.get(primaryKeyName, {raw: true}) === undefined) { if (primaryKeyName && this.get(primaryKeyName, { raw: true }) === undefined) {
throw new Error('You attempted to save an instance with no primary key, this is not allowed since it would result in a global update'); throw new Error('You attempted to save an instance with no primary key, this is not allowed since it would result in a global update');
} }
} }
...@@ -3711,7 +3711,7 @@ class Model { ...@@ -3711,7 +3711,7 @@ class Model {
parentRecord: this parentRecord: this
}).value(); }).value();
return instance.save(includeOptions).then(() => this[include.association.accessors.set](instance, {save: false, logging: options.logging})); return instance.save(includeOptions).then(() => this[include.association.accessors.set](instance, { save: false, logging: options.logging }));
}); });
}).then(() => { }).then(() => {
const realFields = options.fields.filter(field => !this.constructor._virtualAttributes.has(field)); const realFields = options.fields.filter(field => !this.constructor._virtualAttributes.has(field));
...@@ -3793,8 +3793,8 @@ class Model { ...@@ -3793,8 +3793,8 @@ class Model {
if (include.association instanceof BelongsToMany) { if (include.association instanceof BelongsToMany) {
return instance.save(includeOptions).then(() => { return instance.save(includeOptions).then(() => {
const values = {}; const values = {};
values[include.association.foreignKey] = this.get(this.constructor.primaryKeyAttribute, {raw: true}); values[include.association.foreignKey] = this.get(this.constructor.primaryKeyAttribute, { raw: true });
values[include.association.otherKey] = instance.get(instance.constructor.primaryKeyAttribute, {raw: true}); values[include.association.otherKey] = instance.get(instance.constructor.primaryKeyAttribute, { raw: true });
// Include values defined in the association // Include values defined in the association
Object.assign(values, include.association.through.scope); Object.assign(values, include.association.through.scope);
...@@ -3813,7 +3813,7 @@ class Model { ...@@ -3813,7 +3813,7 @@ class Model {
return include.association.throughModel.create(values, includeOptions); return include.association.throughModel.create(values, includeOptions);
}); });
} }
instance.set(include.association.foreignKey, this.get(include.association.sourceKey || this.constructor.primaryKeyAttribute, {raw: true})); instance.set(include.association.foreignKey, this.get(include.association.sourceKey || this.constructor.primaryKeyAttribute, { raw: true }));
Object.assign(instance, include.association.scope); Object.assign(instance, include.association.scope);
return instance.save(includeOptions); return instance.save(includeOptions);
}); });
...@@ -3909,7 +3909,7 @@ class Model { ...@@ -3909,7 +3909,7 @@ class Model {
const changedBefore = this.changed() || []; const changedBefore = this.changed() || [];
options = options || {}; options = options || {};
if (Array.isArray(options)) options = {fields: options}; if (Array.isArray(options)) options = { fields: options };
options = Utils.cloneDeep(options); options = Utils.cloneDeep(options);
const setOptions = Utils.cloneDeep(options); const setOptions = Utils.cloneDeep(options);
...@@ -4033,7 +4033,7 @@ class Model { ...@@ -4033,7 +4033,7 @@ class Model {
const deletedAtDefaultValue = deletedAtAttribute.hasOwnProperty('defaultValue') ? deletedAtAttribute.defaultValue : null; const deletedAtDefaultValue = deletedAtAttribute.hasOwnProperty('defaultValue') ? deletedAtAttribute.defaultValue : null;
this.setDataValue(deletedAtCol, deletedAtDefaultValue); this.setDataValue(deletedAtCol, deletedAtDefaultValue);
return this.save(Object.assign({}, options, {hooks: false, omitNull: false})); return this.save(Object.assign({}, options, { hooks: false, omitNull: false }));
}).tap(() => { }).tap(() => {
// Run after hook // Run after hook
if (options.hooks) { if (options.hooks) {
...@@ -4134,7 +4134,7 @@ class Model { ...@@ -4134,7 +4134,7 @@ class Model {
return false; return false;
} }
return _.every(this.constructor.primaryKeyAttributes, attribute => this.get(attribute, {raw: true}) === other.get(attribute, {raw: true})); return _.every(this.constructor.primaryKeyAttributes, attribute => this.get(attribute, { raw: true }) === other.get(attribute, { raw: true }));
} }
/** /**
......
...@@ -140,7 +140,7 @@ class Sequelize { ...@@ -140,7 +140,7 @@ class Sequelize {
} else { } else {
// new Sequelize(database, username, password, { ... options }) // new Sequelize(database, username, password, { ... options })
options = options || {}; options = options || {};
config = {database, username, password}; config = { database, username, password };
} }
Sequelize.runHooks('beforeInit', config, options); Sequelize.runHooks('beforeInit', config, options);
...@@ -1183,7 +1183,7 @@ Sequelize.prototype.validate = Sequelize.prototype.authenticate; ...@@ -1183,7 +1183,7 @@ Sequelize.prototype.validate = Sequelize.prototype.authenticate;
*/ */
Sequelize.version = require('../package.json').version; Sequelize.version = require('../package.json').version;
Sequelize.options = {hooks: {}}; Sequelize.options = { hooks: {} };
/** /**
* @private * @private
......
...@@ -57,7 +57,7 @@ function escape(val, timeZone, dialect, format) { ...@@ -57,7 +57,7 @@ function escape(val, timeZone, dialect, format) {
if (Array.isArray(val)) { if (Array.isArray(val)) {
const partialEscape = _.partial(escape, _, timeZone, dialect, format); const partialEscape = _.partial(escape, _, timeZone, dialect, format);
if (dialect === 'postgres' && !format) { if (dialect === 'postgres' && !format) {
return dataTypes.ARRAY.prototype.stringify(val, {escape: partialEscape}); return dataTypes.ARRAY.prototype.stringify(val, { escape: partialEscape });
} }
return arrayToList(val, timeZone, dialect, format); return arrayToList(val, timeZone, dialect, format);
} }
......
...@@ -24,8 +24,8 @@ describe(Support.getTestDialectTeaser('Alias'), () => { ...@@ -24,8 +24,8 @@ describe(Support.getTestDialectTeaser('Alias'), () => {
expect(task.getOwner).to.be.ok; expect(task.getOwner).to.be.ok;
return Promise.all([ return Promise.all([
User.findOne({ where: { id: 1 }, include: [{model: Task, as: 'assignments'}] }), User.findOne({ where: { id: 1 }, include: [{ model: Task, as: 'assignments' }] }),
Task.findOne({ where: { id: 1 }, include: [{model: User, as: 'owner'}] }) Task.findOne({ where: { id: 1 }, include: [{ model: User, as: 'owner' }] })
]); ]);
}).then(([user, task]) => { }).then(([user, task]) => {
expect(user.assignments).to.be.ok; expect(user.assignments).to.be.ok;
...@@ -50,8 +50,8 @@ describe(Support.getTestDialectTeaser('Alias'), () => { ...@@ -50,8 +50,8 @@ describe(Support.getTestDialectTeaser('Alias'), () => {
expect(task.getOWNER).to.be.ok; expect(task.getOWNER).to.be.ok;
return Promise.all([ return Promise.all([
User.findOne({ where: { id: 1 }, include: [{model: Task, as: 'ASSIGNMENTS'}] }), User.findOne({ where: { id: 1 }, include: [{ model: Task, as: 'ASSIGNMENTS' }] }),
Task.findOne({ where: { id: 1 }, include: [{model: User, as: 'OWNER'}] }) Task.findOne({ where: { id: 1 }, include: [{ model: User, as: 'OWNER' }] })
]); ]);
}).then(([user, task]) => { }).then(([user, task]) => {
expect(user.ASSIGNMENTS).to.be.ok; expect(user.ASSIGNMENTS).to.be.ok;
...@@ -63,7 +63,7 @@ describe(Support.getTestDialectTeaser('Alias'), () => { ...@@ -63,7 +63,7 @@ describe(Support.getTestDialectTeaser('Alias'), () => {
const User = this.sequelize.define('user', {}), const User = this.sequelize.define('user', {}),
Task = this.sequelize.define('task', {}); Task = this.sequelize.define('task', {});
User.hasMany(Task, { as: { singular: 'task', plural: 'taskz'} }); User.hasMany(Task, { as: { singular: 'task', plural: 'taskz' } });
return this.sequelize.sync({ force: true }).then(() => { return this.sequelize.sync({ force: true }).then(() => {
return User.create({ id: 1 }); return User.create({ id: 1 });
...@@ -72,7 +72,7 @@ describe(Support.getTestDialectTeaser('Alias'), () => { ...@@ -72,7 +72,7 @@ describe(Support.getTestDialectTeaser('Alias'), () => {
expect(user.addTask).to.be.ok; expect(user.addTask).to.be.ok;
expect(user.addTaskz).to.be.ok; expect(user.addTaskz).to.be.ok;
}).then(() => { }).then(() => {
return User.findOne({ where: { id: 1 }, include: [{model: Task, as: 'taskz'}] }); return User.findOne({ where: { id: 1 }, include: [{ model: Task, as: 'taskz' }] });
}).then(user => { }).then(user => {
expect(user.taskz).to.be.ok; expect(user.taskz).to.be.ok;
}); });
......
...@@ -7,8 +7,8 @@ const chai = require('chai'), ...@@ -7,8 +7,8 @@ const chai = require('chai'),
describe(Support.getTestDialectTeaser('Multiple Level Filters'), () => { describe(Support.getTestDialectTeaser('Multiple Level Filters'), () => {
it('can filter through belongsTo', function() { it('can filter through belongsTo', function() {
const User = this.sequelize.define('User', {username: DataTypes.STRING }), const User = this.sequelize.define('User', { username: DataTypes.STRING }),
Task = this.sequelize.define('Task', {title: DataTypes.STRING }), Task = this.sequelize.define('Task', { title: DataTypes.STRING }),
Project = this.sequelize.define('Project', { title: DataTypes.STRING }); Project = this.sequelize.define('Project', { title: DataTypes.STRING });
Project.belongsTo(User); Project.belongsTo(User);
...@@ -48,7 +48,7 @@ describe(Support.getTestDialectTeaser('Multiple Level Filters'), () => { ...@@ -48,7 +48,7 @@ describe(Support.getTestDialectTeaser('Multiple Level Filters'), () => {
{ {
model: Project, model: Project,
include: [ include: [
{model: User, where: {username: 'leia'}} { model: User, where: { username: 'leia' } }
], ],
required: true required: true
} }
...@@ -66,8 +66,8 @@ describe(Support.getTestDialectTeaser('Multiple Level Filters'), () => { ...@@ -66,8 +66,8 @@ describe(Support.getTestDialectTeaser('Multiple Level Filters'), () => {
}); });
it('avoids duplicated tables in query', function() { it('avoids duplicated tables in query', function() {
const User = this.sequelize.define('User', {username: DataTypes.STRING }), const User = this.sequelize.define('User', { username: DataTypes.STRING }),
Task = this.sequelize.define('Task', {title: DataTypes.STRING }), Task = this.sequelize.define('Task', { title: DataTypes.STRING }),
Project = this.sequelize.define('Project', { title: DataTypes.STRING }); Project = this.sequelize.define('Project', { title: DataTypes.STRING });
Project.belongsTo(User); Project.belongsTo(User);
...@@ -107,10 +107,10 @@ describe(Support.getTestDialectTeaser('Multiple Level Filters'), () => { ...@@ -107,10 +107,10 @@ describe(Support.getTestDialectTeaser('Multiple Level Filters'), () => {
{ {
model: Project, model: Project,
include: [ include: [
{model: User, where: { { model: User, where: {
username: 'leia', username: 'leia',
id: 1 id: 1
}} } }
], ],
required: true required: true
} }
...@@ -127,8 +127,8 @@ describe(Support.getTestDialectTeaser('Multiple Level Filters'), () => { ...@@ -127,8 +127,8 @@ describe(Support.getTestDialectTeaser('Multiple Level Filters'), () => {
}); });
it('can filter through hasMany', function() { it('can filter through hasMany', function() {
const User = this.sequelize.define('User', {username: DataTypes.STRING }), const User = this.sequelize.define('User', { username: DataTypes.STRING }),
Task = this.sequelize.define('Task', {title: DataTypes.STRING }), Task = this.sequelize.define('Task', { title: DataTypes.STRING }),
Project = this.sequelize.define('Project', { title: DataTypes.STRING }); Project = this.sequelize.define('Project', { title: DataTypes.STRING });
Project.belongsTo(User); Project.belongsTo(User);
...@@ -168,7 +168,7 @@ describe(Support.getTestDialectTeaser('Multiple Level Filters'), () => { ...@@ -168,7 +168,7 @@ describe(Support.getTestDialectTeaser('Multiple Level Filters'), () => {
{ {
model: Project, model: Project,
include: [ include: [
{model: Task, where: {title: 'fight empire'}} { model: Task, where: { title: 'fight empire' } }
], ],
required: true required: true
} }
...@@ -184,11 +184,11 @@ describe(Support.getTestDialectTeaser('Multiple Level Filters'), () => { ...@@ -184,11 +184,11 @@ describe(Support.getTestDialectTeaser('Multiple Level Filters'), () => {
}); });
it('can filter through hasMany connector', function() { it('can filter through hasMany connector', function() {
const User = this.sequelize.define('User', {username: DataTypes.STRING }), const User = this.sequelize.define('User', { username: DataTypes.STRING }),
Project = this.sequelize.define('Project', { title: DataTypes.STRING }); Project = this.sequelize.define('Project', { title: DataTypes.STRING });
Project.belongsToMany(User, {through: 'user_project'}); Project.belongsToMany(User, { through: 'user_project' });
User.belongsToMany(Project, {through: 'user_project'}); User.belongsToMany(Project, { through: 'user_project' });
return this.sequelize.sync({ force: true }).then(() => { return this.sequelize.sync({ force: true }).then(() => {
return User.bulkCreate([{ return User.bulkCreate([{
...@@ -209,7 +209,7 @@ describe(Support.getTestDialectTeaser('Multiple Level Filters'), () => { ...@@ -209,7 +209,7 @@ describe(Support.getTestDialectTeaser('Multiple Level Filters'), () => {
return user.setProjects([project]).then(() => { return user.setProjects([project]).then(() => {
return User.findAll({ return User.findAll({
include: [ include: [
{model: Project, where: {title: 'republic'}} { model: Project, where: { title: 'republic' } }
] ]
}).then(users => { }).then(users => {
expect(users.length).to.be.equal(1); expect(users.length).to.be.equal(1);
......
...@@ -98,7 +98,7 @@ describe(Support.getTestDialectTeaser('associations'), () => { ...@@ -98,7 +98,7 @@ describe(Support.getTestDialectTeaser('associations'), () => {
describe('1:1', () => { describe('1:1', () => {
it('should create, find and include associations with scope values', function() { it('should create, find and include associations with scope values', function() {
return this.sequelize.sync({force: true}).then(() => { return this.sequelize.sync({ force: true }).then(() => {
return Promise.join( return Promise.join(
this.Post.create(), this.Post.create(),
this.Comment.create({ this.Comment.create({
...@@ -148,13 +148,13 @@ describe(Support.getTestDialectTeaser('associations'), () => { ...@@ -148,13 +148,13 @@ describe(Support.getTestDialectTeaser('associations'), () => {
}); });
}); });
it('should create included association with scope values', function() { it('should create included association with scope values', function() {
return this.sequelize.sync({force: true}).then(() => { return this.sequelize.sync({ force: true }).then(() => {
return this.Post.create({ return this.Post.create({
mainComment: { mainComment: {
title: 'I am a main comment created with a post' title: 'I am a main comment created with a post'
} }
}, { }, {
include: [{model: this.Comment, as: 'mainComment'}] include: [{ model: this.Comment, as: 'mainComment' }]
}); });
}).then(post => { }).then(post => {
expect(post.mainComment.get('commentable')).to.equal('post'); expect(post.mainComment.get('commentable')).to.equal('post');
...@@ -169,7 +169,7 @@ describe(Support.getTestDialectTeaser('associations'), () => { ...@@ -169,7 +169,7 @@ describe(Support.getTestDialectTeaser('associations'), () => {
describe('1:M', () => { describe('1:M', () => {
it('should create, find and include associations with scope values', function() { it('should create, find and include associations with scope values', function() {
return this.sequelize.sync({force: true}).then(() => { return this.sequelize.sync({ force: true }).then(() => {
return Promise.join( return Promise.join(
this.Post.create(), this.Post.create(),
this.Image.create(), this.Image.create(),
...@@ -254,7 +254,7 @@ describe(Support.getTestDialectTeaser('associations'), () => { ...@@ -254,7 +254,7 @@ describe(Support.getTestDialectTeaser('associations'), () => {
logs.push(log.substring(log.indexOf(':') + 1)); logs.push(log.substring(log.indexOf(':') + 1));
}; };
return this.sequelize.sync({force: true}).then(() => { return this.sequelize.sync({ force: true }).then(() => {
return this.Post.create(); return this.Post.create();
}).then(post => { }).then(post => {
return post.createComment({ return post.createComment({
...@@ -273,7 +273,7 @@ describe(Support.getTestDialectTeaser('associations'), () => { ...@@ -273,7 +273,7 @@ describe(Support.getTestDialectTeaser('associations'), () => {
}); });
}); });
it('should created included association with scope values', function() { it('should created included association with scope values', function() {
return this.sequelize.sync({force: true}).then(() => { return this.sequelize.sync({ force: true }).then(() => {
return this.Post.create({ return this.Post.create({
comments: [{ comments: [{
title: 'I am a comment created with a post' title: 'I am a comment created with a post'
...@@ -281,7 +281,7 @@ describe(Support.getTestDialectTeaser('associations'), () => { ...@@ -281,7 +281,7 @@ describe(Support.getTestDialectTeaser('associations'), () => {
title: 'I am a second comment created with a post' title: 'I am a second comment created with a post'
}] }]
}, { }, {
include: [{model: this.Comment, as: 'comments'}] include: [{ model: this.Comment, as: 'comments' }]
}); });
}).then(post => { }).then(post => {
this.post = post; this.post = post;
...@@ -297,7 +297,7 @@ describe(Support.getTestDialectTeaser('associations'), () => { ...@@ -297,7 +297,7 @@ describe(Support.getTestDialectTeaser('associations'), () => {
}); });
}); });
it('should include associations with operator scope values', function() { it('should include associations with operator scope values', function() {
return this.sequelize.sync({force: true}).then(() => { return this.sequelize.sync({ force: true }).then(() => {
return Promise.join( return Promise.join(
this.Post.create(), this.Post.create(),
this.Comment.create({ this.Comment.create({
...@@ -342,26 +342,26 @@ describe(Support.getTestDialectTeaser('associations'), () => { ...@@ -342,26 +342,26 @@ describe(Support.getTestDialectTeaser('associations'), () => {
}); });
this.PostTag = this.sequelize.define('post_tag'); this.PostTag = this.sequelize.define('post_tag');
this.Tag.belongsToMany(this.Post, {through: this.PostTag}); this.Tag.belongsToMany(this.Post, { through: this.PostTag });
this.Post.belongsToMany(this.Tag, {as: 'categories', through: this.PostTag, scope: { type: 'category' }}); this.Post.belongsToMany(this.Tag, { as: 'categories', through: this.PostTag, scope: { type: 'category' } });
this.Post.belongsToMany(this.Tag, {as: 'tags', through: this.PostTag, scope: { type: 'tag' }}); this.Post.belongsToMany(this.Tag, { as: 'tags', through: this.PostTag, scope: { type: 'tag' } });
}); });
it('should create, find and include associations with scope values', function() { it('should create, find and include associations with scope values', function() {
return Promise.join( return Promise.join(
this.Post.sync({force: true}), this.Post.sync({ force: true }),
this.Tag.sync({force: true}) this.Tag.sync({ force: true })
).then(() => { ).then(() => {
return this.PostTag.sync({force: true}); return this.PostTag.sync({ force: true });
}).then(() => { }).then(() => {
return Promise.join( return Promise.join(
this.Post.create(), this.Post.create(),
this.Post.create(), this.Post.create(),
this.Post.create(), this.Post.create(),
this.Tag.create({type: 'category'}), this.Tag.create({ type: 'category' }),
this.Tag.create({type: 'category'}), this.Tag.create({ type: 'category' }),
this.Tag.create({type: 'tag'}), this.Tag.create({ type: 'tag' }),
this.Tag.create({type: 'tag'}) this.Tag.create({ type: 'tag' })
); );
}).then(([postA, postB, postC, categoryA, categoryB, tagA, tagB]) => { }).then(([postA, postB, postC, categoryA, categoryB, tagA, tagB]) => {
this.postA = postA; this.postA = postA;
...@@ -406,8 +406,8 @@ describe(Support.getTestDialectTeaser('associations'), () => { ...@@ -406,8 +406,8 @@ describe(Support.getTestDialectTeaser('associations'), () => {
id: this.postA.get('id') id: this.postA.get('id')
}, },
include: [ include: [
{model: this.Tag, as: 'tags'}, { model: this.Tag, as: 'tags' },
{model: this.Tag, as: 'categories'} { model: this.Tag, as: 'categories' }
] ]
}), }),
this.Post.findOne({ this.Post.findOne({
...@@ -415,8 +415,8 @@ describe(Support.getTestDialectTeaser('associations'), () => { ...@@ -415,8 +415,8 @@ describe(Support.getTestDialectTeaser('associations'), () => {
id: this.postB.get('id') id: this.postB.get('id')
}, },
include: [ include: [
{model: this.Tag, as: 'tags'}, { model: this.Tag, as: 'tags' },
{model: this.Tag, as: 'categories'} { model: this.Tag, as: 'categories' }
] ]
}), }),
this.Post.findOne({ this.Post.findOne({
...@@ -424,8 +424,8 @@ describe(Support.getTestDialectTeaser('associations'), () => { ...@@ -424,8 +424,8 @@ describe(Support.getTestDialectTeaser('associations'), () => {
id: this.postC.get('id') id: this.postC.get('id')
}, },
include: [ include: [
{model: this.Tag, as: 'tags'}, { model: this.Tag, as: 'tags' },
{model: this.Tag, as: 'categories'} { model: this.Tag, as: 'categories' }
] ]
}) })
); );
...@@ -537,20 +537,20 @@ describe(Support.getTestDialectTeaser('associations'), () => { ...@@ -537,20 +537,20 @@ describe(Support.getTestDialectTeaser('associations'), () => {
it('should create, find and include associations with scope values', function() { it('should create, find and include associations with scope values', function() {
return Promise.join( return Promise.join(
this.Post.sync({force: true}), this.Post.sync({ force: true }),
this.Image.sync({force: true}), this.Image.sync({ force: true }),
this.Question.sync({force: true}), this.Question.sync({ force: true }),
this.Tag.sync({force: true}) this.Tag.sync({ force: true })
).then(() => { ).then(() => {
return this.ItemTag.sync({force: true}); return this.ItemTag.sync({ force: true });
}).then(() => { }).then(() => {
return Promise.join( return Promise.join(
this.Post.create(), this.Post.create(),
this.Image.create(), this.Image.create(),
this.Question.create(), this.Question.create(),
this.Tag.create({name: 'tagA'}), this.Tag.create({ name: 'tagA' }),
this.Tag.create({name: 'tagB'}), this.Tag.create({ name: 'tagB' }),
this.Tag.create({name: 'tagC'}) this.Tag.create({ name: 'tagC' })
); );
}).then(([post, image, question, tagA, tagB, tagC]) => { }).then(([post, image, question, tagA, tagB, tagC]) => {
this.post = post; this.post = post;
...@@ -559,19 +559,19 @@ describe(Support.getTestDialectTeaser('associations'), () => { ...@@ -559,19 +559,19 @@ describe(Support.getTestDialectTeaser('associations'), () => {
return Promise.join( return Promise.join(
post.setTags([tagA]).then(() => { post.setTags([tagA]).then(() => {
return Promise.join( return Promise.join(
post.createTag({name: 'postTag'}), post.createTag({ name: 'postTag' }),
post.addTag(tagB) post.addTag(tagB)
); );
}), }),
image.setTags([tagB]).then(() => { image.setTags([tagB]).then(() => {
return Promise.join( return Promise.join(
image.createTag({name: 'imageTag'}), image.createTag({ name: 'imageTag' }),
image.addTag(tagC) image.addTag(tagC)
); );
}), }),
question.setTags([tagC]).then(() => { question.setTags([tagC]).then(() => {
return Promise.join( return Promise.join(
question.createTag({name: 'questionTag'}), question.createTag({ name: 'questionTag' }),
question.addTag(tagA) question.addTag(tagA)
); );
}) })
......
...@@ -18,7 +18,7 @@ describe(Support.getTestDialectTeaser('Self'), () => { ...@@ -18,7 +18,7 @@ describe(Support.getTestDialectTeaser('Self'), () => {
}); });
Group.belongsTo(Group, { as: 'Parent', foreignKey: 'parent_id' }); Group.belongsTo(Group, { as: 'Parent', foreignKey: 'parent_id' });
return Group.sync({force: true}).then(() => { return Group.sync({ force: true }).then(() => {
return Group.findAll({ return Group.findAll({
include: [{ include: [{
model: Group, model: Group,
...@@ -31,11 +31,11 @@ describe(Support.getTestDialectTeaser('Self'), () => { ...@@ -31,11 +31,11 @@ describe(Support.getTestDialectTeaser('Self'), () => {
it('can handle 1:m associations', function() { it('can handle 1:m associations', function() {
const Person = this.sequelize.define('Person', { name: DataTypes.STRING }); const Person = this.sequelize.define('Person', { name: DataTypes.STRING });
Person.hasMany(Person, { as: 'Children', foreignKey: 'parent_id'}); Person.hasMany(Person, { as: 'Children', foreignKey: 'parent_id' });
expect(Person.rawAttributes.parent_id).to.be.ok; expect(Person.rawAttributes.parent_id).to.be.ok;
return this.sequelize.sync({force: true}).then(() => { return this.sequelize.sync({ force: true }).then(() => {
return Promise.all([ return Promise.all([
Person.create({ name: 'Mary' }), Person.create({ name: 'Mary' }),
Person.create({ name: 'John' }), Person.create({ name: 'John' }),
......
...@@ -157,7 +157,7 @@ if (current.dialect.supports.transactions) { ...@@ -157,7 +157,7 @@ if (current.dialect.supports.transactions) {
it('promises returned by sequelize.query are correctly patched', function() { it('promises returned by sequelize.query are correctly patched', function() {
return this.sequelize.transaction(t => return this.sequelize.transaction(t =>
this.sequelize.query('select 1', {type: Sequelize.QueryTypes.SELECT}) this.sequelize.query('select 1', { type: Sequelize.QueryTypes.SELECT })
.then(() => expect(this.ns.get('transaction')).to.equal(t)) .then(() => expect(this.ns.get('transaction')).to.equal(t))
); );
}); });
......
...@@ -16,7 +16,7 @@ if (dialect === 'sqlite') { ...@@ -16,7 +16,7 @@ if (dialect === 'sqlite') {
describe(Support.getTestDialectTeaser('Configuration'), () => { describe(Support.getTestDialectTeaser('Configuration'), () => {
describe('Connections problems should fail with a nice message', () => { describe('Connections problems should fail with a nice message', () => {
it('when we don\'t have the correct server details', () => { it('when we don\'t have the correct server details', () => {
const seq = new Sequelize(config[dialect].database, config[dialect].username, config[dialect].password, {storage: '/path/to/no/where/land', logging: false, host: '0.0.0.1', port: config[dialect].port, dialect}); const seq = new Sequelize(config[dialect].database, config[dialect].username, config[dialect].password, { storage: '/path/to/no/where/land', logging: false, host: '0.0.0.1', port: config[dialect].port, dialect });
if (dialect === 'sqlite') { if (dialect === 'sqlite') {
// SQLite doesn't have a breakdown of error codes, so we are unable to discern between the different types of errors. // SQLite doesn't have a breakdown of error codes, so we are unable to discern between the different types of errors.
return expect(seq.query('select 1 as hello')).to.eventually.be.rejectedWith(Sequelize.ConnectionError, 'SQLITE_CANTOPEN: unable to open database file'); return expect(seq.query('select 1 as hello')).to.eventually.be.rejectedWith(Sequelize.ConnectionError, 'SQLITE_CANTOPEN: unable to open database file');
...@@ -32,7 +32,7 @@ describe(Support.getTestDialectTeaser('Configuration'), () => { ...@@ -32,7 +32,7 @@ describe(Support.getTestDialectTeaser('Configuration'), () => {
return; return;
} }
const seq = new Sequelize(config[dialect].database, config[dialect].username, 'fakepass123', {logging: false, host: config[dialect].host, port: 1, dialect}); const seq = new Sequelize(config[dialect].database, config[dialect].username, 'fakepass123', { logging: false, host: config[dialect].host, port: 1, dialect });
if (dialect === 'sqlite') { if (dialect === 'sqlite') {
// SQLite doesn't require authentication and `select 1 as hello` is a valid query, so this should be fulfilled not rejected for it. // SQLite doesn't require authentication and `select 1 as hello` is a valid query, so this should be fulfilled not rejected for it.
return expect(seq.query('select 1 as hello')).to.eventually.be.fulfilled; return expect(seq.query('select 1 as hello')).to.eventually.be.fulfilled;
...@@ -42,7 +42,7 @@ describe(Support.getTestDialectTeaser('Configuration'), () => { ...@@ -42,7 +42,7 @@ describe(Support.getTestDialectTeaser('Configuration'), () => {
it('when we don\'t have a valid dialect.', () => { it('when we don\'t have a valid dialect.', () => {
expect(() => { expect(() => {
new Sequelize(config[dialect].database, config[dialect].username, config[dialect].password, {host: '0.0.0.1', port: config[dialect].port, dialect: 'some-fancy-dialect'}); new Sequelize(config[dialect].database, config[dialect].username, config[dialect].password, { host: '0.0.0.1', port: config[dialect].port, dialect: 'some-fancy-dialect' });
}).to.throw(Error, 'The dialect some-fancy-dialect is not supported. Supported dialects: mssql, mariadb, mysql, postgres, and sqlite.'); }).to.throw(Error, 'The dialect some-fancy-dialect is not supported. Supported dialects: mssql, mariadb, mysql, postgres, and sqlite.');
}); });
}); });
......
...@@ -117,7 +117,7 @@ describe(Support.getTestDialectTeaser('DataTypes'), () => { ...@@ -117,7 +117,7 @@ describe(Support.getTestDialectTeaser('DataTypes'), () => {
it('calls parse and stringify for JSON', () => { it('calls parse and stringify for JSON', () => {
const Type = new Sequelize.JSON(); const Type = new Sequelize.JSON();
return testSuccess(Type, { test: 42, nested: { foo: 'bar' }}); return testSuccess(Type, { test: 42, nested: { foo: 'bar' } });
}); });
} }
...@@ -125,7 +125,7 @@ describe(Support.getTestDialectTeaser('DataTypes'), () => { ...@@ -125,7 +125,7 @@ describe(Support.getTestDialectTeaser('DataTypes'), () => {
it('calls parse and stringify for JSONB', () => { it('calls parse and stringify for JSONB', () => {
const Type = new Sequelize.JSONB(); const Type = new Sequelize.JSONB();
return testSuccess(Type, { test: 42, nested: { foo: 'bar' }}); return testSuccess(Type, { test: 42, nested: { foo: 'bar' } });
}); });
} }
...@@ -622,7 +622,7 @@ describe(Support.getTestDialectTeaser('DataTypes'), () => { ...@@ -622,7 +622,7 @@ describe(Support.getTestDialectTeaser('DataTypes'), () => {
const testDate = moment().format('YYYY-MM-DD'); const testDate = moment().format('YYYY-MM-DD');
const newDate = new Date(); const newDate = new Date();
return Model.sync({ force: true}) return Model.sync({ force: true })
.then(() => Model.create({ stamp: testDate })) .then(() => Model.create({ stamp: testDate }))
.then(record => { .then(record => {
expect(typeof record.stamp).to.be.eql('string'); expect(typeof record.stamp).to.be.eql('string');
...@@ -662,7 +662,7 @@ describe(Support.getTestDialectTeaser('DataTypes'), () => { ...@@ -662,7 +662,7 @@ describe(Support.getTestDialectTeaser('DataTypes'), () => {
}); });
const testDate = moment().format('YYYY-MM-DD'); const testDate = moment().format('YYYY-MM-DD');
return Model.sync({ force: true}) return Model.sync({ force: true })
.then(() => Model.create({ stamp: testDate })) .then(() => Model.create({ stamp: testDate }))
.then(record => { .then(record => {
expect(typeof record.stamp).to.be.eql('string'); expect(typeof record.stamp).to.be.eql('string');
......
...@@ -12,15 +12,15 @@ describe('[MariaDB Specific] Associations', () => { ...@@ -12,15 +12,15 @@ describe('[MariaDB Specific] Associations', () => {
describe('many-to-many', () => { describe('many-to-many', () => {
describe('where tables have the same prefix', () => { describe('where tables have the same prefix', () => {
it('should create a table wp_table1wp_table2s', function() { it('should create a table wp_table1wp_table2s', function() {
const Table2 = this.sequelize.define('wp_table2', {foo: DataTypes.STRING}), const Table2 = this.sequelize.define('wp_table2', { foo: DataTypes.STRING }),
Table1 = this.sequelize.define('wp_table1', Table1 = this.sequelize.define('wp_table1',
{foo: DataTypes.STRING}), { foo: DataTypes.STRING }),
self = this; self = this;
Table1.belongsToMany(Table2, {through: 'wp_table1swp_table2s'}); Table1.belongsToMany(Table2, { through: 'wp_table1swp_table2s' });
Table2.belongsToMany(Table1, {through: 'wp_table1swp_table2s'}); Table2.belongsToMany(Table1, { through: 'wp_table1swp_table2s' });
return Table1.sync({force: true}).then(() => { return Table1.sync({ force: true }).then(() => {
return Table2.sync({force: true}).then(() => { return Table2.sync({ force: true }).then(() => {
expect(self.sequelize.modelManager.getModel( expect(self.sequelize.modelManager.getModel(
'wp_table1swp_table2s')).to.exist; 'wp_table1swp_table2s')).to.exist;
}); });
...@@ -30,14 +30,14 @@ describe('[MariaDB Specific] Associations', () => { ...@@ -30,14 +30,14 @@ describe('[MariaDB Specific] Associations', () => {
describe('when join table name is specified', () => { describe('when join table name is specified', () => {
beforeEach(function() { beforeEach(function() {
const Table2 = this.sequelize.define('ms_table1', {foo: DataTypes.STRING}), const Table2 = this.sequelize.define('ms_table1', { foo: DataTypes.STRING }),
Table1 = this.sequelize.define('ms_table2', Table1 = this.sequelize.define('ms_table2',
{foo: DataTypes.STRING}); { foo: DataTypes.STRING });
Table1.belongsToMany(Table2, {through: 'table1_to_table2'}); Table1.belongsToMany(Table2, { through: 'table1_to_table2' });
Table2.belongsToMany(Table1, {through: 'table1_to_table2'}); Table2.belongsToMany(Table1, { through: 'table1_to_table2' });
return Table1.sync({force: true}).then(() => { return Table1.sync({ force: true }).then(() => {
return Table2.sync({force: true}); return Table2.sync({ force: true });
}); });
}); });
...@@ -53,27 +53,27 @@ describe('[MariaDB Specific] Associations', () => { ...@@ -53,27 +53,27 @@ describe('[MariaDB Specific] Associations', () => {
describe('HasMany', () => { describe('HasMany', () => {
beforeEach(function() { beforeEach(function() {
//prevent periods from occurring in the table name since they are used to delimit (table.column) //prevent periods from occurring in the table name since they are used to delimit (table.column)
this.User = this.sequelize.define(`User${Math.ceil(Math.random() * 10000000)}`, {name: DataTypes.STRING}); this.User = this.sequelize.define(`User${Math.ceil(Math.random() * 10000000)}`, { name: DataTypes.STRING });
this.Task = this.sequelize.define(`Task${Math.ceil(Math.random() * 10000000)}`, {name: DataTypes.STRING}); this.Task = this.sequelize.define(`Task${Math.ceil(Math.random() * 10000000)}`, { name: DataTypes.STRING });
this.users = null; this.users = null;
this.tasks = null; this.tasks = null;
this.User.belongsToMany(this.Task, {as: 'Tasks', through: 'UserTasks'}); this.User.belongsToMany(this.Task, { as: 'Tasks', through: 'UserTasks' });
this.Task.belongsToMany(this.User, {as: 'Users', through: 'UserTasks'}); this.Task.belongsToMany(this.User, { as: 'Users', through: 'UserTasks' });
const self = this, const self = this,
users = [], users = [],
tasks = []; tasks = [];
for (let i = 0; i < 5; ++i) { for (let i = 0; i < 5; ++i) {
users[users.length] = {name: `User${Math.random()}`}; users[users.length] = { name: `User${Math.random()}` };
} }
for (let x = 0; x < 5; ++x) { for (let x = 0; x < 5; ++x) {
tasks[tasks.length] = {name: `Task${Math.random()}`}; tasks[tasks.length] = { name: `Task${Math.random()}` };
} }
return this.sequelize.sync({force: true}) return this.sequelize.sync({ force: true })
.then(() => self.User.bulkCreate(users)) .then(() => self.User.bulkCreate(users))
.then(() => self.Task.bulkCreate(tasks)); .then(() => self.Task.bulkCreate(tasks));
......
...@@ -15,10 +15,10 @@ describe('[MARIADB Specific] Connection Manager', () => { ...@@ -15,10 +15,10 @@ describe('[MARIADB Specific] Connection Manager', () => {
it('has existing init SQL', () => { it('has existing init SQL', () => {
const sequelize = Support.createSequelizeInstance( const sequelize = Support.createSequelizeInstance(
{dialectOptions: {initSql: 'SET @myUserVariable=\'myValue\''}}); { dialectOptions: { initSql: 'SET @myUserVariable=\'myValue\'' } });
return sequelize.query('SELECT @myUserVariable') return sequelize.query('SELECT @myUserVariable')
.then(res => { .then(res => {
expect(res[0]).to.deep.equal([{'@myUserVariable': 'myValue'}]); expect(res[0]).to.deep.equal([{ '@myUserVariable': 'myValue' }]);
sequelize.close(); sequelize.close();
}); });
}); });
...@@ -34,7 +34,7 @@ describe('[MARIADB Specific] Connection Manager', () => { ...@@ -34,7 +34,7 @@ describe('[MARIADB Specific] Connection Manager', () => {
return sequelize.query('SELECT @myUserVariable1, @myUserVariable2') return sequelize.query('SELECT @myUserVariable1, @myUserVariable2')
.then(res => { .then(res => {
expect(res[0]).to.deep.equal( expect(res[0]).to.deep.equal(
[{'@myUserVariable1': 'myValue', '@myUserVariable2': 'myValue'}]); [{ '@myUserVariable1': 'myValue', '@myUserVariable2': 'myValue' }]);
sequelize.close(); sequelize.close();
}); });
}); });
...@@ -45,12 +45,12 @@ describe('[MARIADB Specific] Connection Manager', () => { ...@@ -45,12 +45,12 @@ describe('[MARIADB Specific] Connection Manager', () => {
const testHost = env.MARIADB_PORT_3306_TCP_ADDR || env.SEQ_MARIADB_HOST || env.SEQ_HOST || '127.0.0.1'; const testHost = env.MARIADB_PORT_3306_TCP_ADDR || env.SEQ_MARIADB_HOST || env.SEQ_HOST || '127.0.0.1';
it('Connection timeout', () => { it('Connection timeout', () => {
const sequelize = Support.createSequelizeInstance({ host: testHost, port: 65535, dialectOptions: {connectTimeout: 500}}); const sequelize = Support.createSequelizeInstance({ host: testHost, port: 65535, dialectOptions: { connectTimeout: 500 } });
return expect(sequelize.connectionManager.getConnection()).to.have.been.rejectedWith(Sequelize.SequelizeConnectionError); return expect(sequelize.connectionManager.getConnection()).to.have.been.rejectedWith(Sequelize.SequelizeConnectionError);
}); });
it('ECONNREFUSED', () => { it('ECONNREFUSED', () => {
const sequelize = Support.createSequelizeInstance({ host: testHost, port: 65535}); const sequelize = Support.createSequelizeInstance({ host: testHost, port: 65535 });
return expect(sequelize.connectionManager.getConnection()).to.have.been.rejectedWith(Sequelize.ConnectionRefusedError); return expect(sequelize.connectionManager.getConnection()).to.have.been.rejectedWith(Sequelize.ConnectionRefusedError);
}); });
......
...@@ -12,8 +12,8 @@ describe('[MariaDB Specific] DAOFactory', () => { ...@@ -12,8 +12,8 @@ describe('[MariaDB Specific] DAOFactory', () => {
describe('constructor', () => { describe('constructor', () => {
it('handles extended attributes (unique)', function() { it('handles extended attributes (unique)', function() {
const User = this.sequelize.define(`User${config.rand()}`, { const User = this.sequelize.define(`User${config.rand()}`, {
username: {type: DataTypes.STRING, unique: true} username: { type: DataTypes.STRING, unique: true }
}, {timestamps: false}); }, { timestamps: false });
expect( expect(
this.sequelize.getQueryInterface().QueryGenerator.attributesToSQL( this.sequelize.getQueryInterface().QueryGenerator.attributesToSQL(
...@@ -25,8 +25,8 @@ describe('[MariaDB Specific] DAOFactory', () => { ...@@ -25,8 +25,8 @@ describe('[MariaDB Specific] DAOFactory', () => {
it('handles extended attributes (default)', function() { it('handles extended attributes (default)', function() {
const User = this.sequelize.define(`User${config.rand()}`, { const User = this.sequelize.define(`User${config.rand()}`, {
username: {type: DataTypes.STRING, defaultValue: 'foo'} username: { type: DataTypes.STRING, defaultValue: 'foo' }
}, {timestamps: false}); }, { timestamps: false });
expect( expect(
this.sequelize.getQueryInterface().QueryGenerator.attributesToSQL( this.sequelize.getQueryInterface().QueryGenerator.attributesToSQL(
User.rawAttributes)).to.deep.equal({ User.rawAttributes)).to.deep.equal({
...@@ -37,8 +37,8 @@ describe('[MariaDB Specific] DAOFactory', () => { ...@@ -37,8 +37,8 @@ describe('[MariaDB Specific] DAOFactory', () => {
it('handles extended attributes (null)', function() { it('handles extended attributes (null)', function() {
const User = this.sequelize.define(`User${config.rand()}`, { const User = this.sequelize.define(`User${config.rand()}`, {
username: {type: DataTypes.STRING, allowNull: false} username: { type: DataTypes.STRING, allowNull: false }
}, {timestamps: false}); }, { timestamps: false });
expect( expect(
this.sequelize.getQueryInterface().QueryGenerator.attributesToSQL( this.sequelize.getQueryInterface().QueryGenerator.attributesToSQL(
User.rawAttributes)).to.deep.equal({ User.rawAttributes)).to.deep.equal({
...@@ -49,18 +49,18 @@ describe('[MariaDB Specific] DAOFactory', () => { ...@@ -49,18 +49,18 @@ describe('[MariaDB Specific] DAOFactory', () => {
it('handles extended attributes (primaryKey)', function() { it('handles extended attributes (primaryKey)', function() {
const User = this.sequelize.define(`User${config.rand()}`, { const User = this.sequelize.define(`User${config.rand()}`, {
username: {type: DataTypes.STRING, primaryKey: true} username: { type: DataTypes.STRING, primaryKey: true }
}, {timestamps: false}); }, { timestamps: false });
expect( expect(
this.sequelize.getQueryInterface().QueryGenerator.attributesToSQL( this.sequelize.getQueryInterface().QueryGenerator.attributesToSQL(
User.rawAttributes)).to.deep.equal( User.rawAttributes)).to.deep.equal(
{username: 'VARCHAR(255) PRIMARY KEY'}); { username: 'VARCHAR(255) PRIMARY KEY' });
}); });
it('adds timestamps', function() { it('adds timestamps', function() {
const User1 = this.sequelize.define(`User${config.rand()}`, {}); const User1 = this.sequelize.define(`User${config.rand()}`, {});
const User2 = this.sequelize.define(`User${config.rand()}`, {}, const User2 = this.sequelize.define(`User${config.rand()}`, {},
{timestamps: true}); { timestamps: true });
expect( expect(
this.sequelize.getQueryInterface().QueryGenerator.attributesToSQL( this.sequelize.getQueryInterface().QueryGenerator.attributesToSQL(
...@@ -80,7 +80,7 @@ describe('[MariaDB Specific] DAOFactory', () => { ...@@ -80,7 +80,7 @@ describe('[MariaDB Specific] DAOFactory', () => {
it('adds deletedAt if paranoid', function() { it('adds deletedAt if paranoid', function() {
const User = this.sequelize.define(`User${config.rand()}`, {}, const User = this.sequelize.define(`User${config.rand()}`, {},
{paranoid: true}); { paranoid: true });
expect( expect(
this.sequelize.getQueryInterface().QueryGenerator.attributesToSQL( this.sequelize.getQueryInterface().QueryGenerator.attributesToSQL(
User.rawAttributes)).to.deep.equal({ User.rawAttributes)).to.deep.equal({
...@@ -93,7 +93,7 @@ describe('[MariaDB Specific] DAOFactory', () => { ...@@ -93,7 +93,7 @@ describe('[MariaDB Specific] DAOFactory', () => {
it('underscores timestamps if underscored', function() { it('underscores timestamps if underscored', function() {
const User = this.sequelize.define(`User${config.rand()}`, {}, const User = this.sequelize.define(`User${config.rand()}`, {},
{paranoid: true, underscored: true}); { paranoid: true, underscored: true });
expect( expect(
this.sequelize.getQueryInterface().QueryGenerator.attributesToSQL( this.sequelize.getQueryInterface().QueryGenerator.attributesToSQL(
User.rawAttributes)).to.deep.equal({ User.rawAttributes)).to.deep.equal({
...@@ -106,13 +106,13 @@ describe('[MariaDB Specific] DAOFactory', () => { ...@@ -106,13 +106,13 @@ describe('[MariaDB Specific] DAOFactory', () => {
it('omits text fields with defaultValues', function() { it('omits text fields with defaultValues', function() {
const User = this.sequelize.define(`User${config.rand()}`, const User = this.sequelize.define(`User${config.rand()}`,
{name: {type: DataTypes.TEXT, defaultValue: 'helloworld'}}); { name: { type: DataTypes.TEXT, defaultValue: 'helloworld' } });
expect(User.rawAttributes.name.type.toString()).to.equal('TEXT'); expect(User.rawAttributes.name.type.toString()).to.equal('TEXT');
}); });
it('omits blobs fields with defaultValues', function() { it('omits blobs fields with defaultValues', function() {
const User = this.sequelize.define(`User${config.rand()}`, const User = this.sequelize.define(`User${config.rand()}`,
{name: {type: DataTypes.STRING.BINARY, defaultValue: 'helloworld'}}); { name: { type: DataTypes.STRING.BINARY, defaultValue: 'helloworld' } });
expect(User.rawAttributes.name.type.toString()).to.equal( expect(User.rawAttributes.name.type.toString()).to.equal(
'VARCHAR(255) BINARY'); 'VARCHAR(255) BINARY');
}); });
...@@ -121,13 +121,13 @@ describe('[MariaDB Specific] DAOFactory', () => { ...@@ -121,13 +121,13 @@ describe('[MariaDB Specific] DAOFactory', () => {
describe('primaryKeys', () => { describe('primaryKeys', () => {
it('determines the correct primaryKeys', function() { it('determines the correct primaryKeys', function() {
const User = this.sequelize.define(`User${config.rand()}`, { const User = this.sequelize.define(`User${config.rand()}`, {
foo: {type: DataTypes.STRING, primaryKey: true}, foo: { type: DataTypes.STRING, primaryKey: true },
bar: DataTypes.STRING bar: DataTypes.STRING
}); });
expect( expect(
this.sequelize.getQueryInterface().QueryGenerator.attributesToSQL( this.sequelize.getQueryInterface().QueryGenerator.attributesToSQL(
User.primaryKeys)).to.deep.equal( User.primaryKeys)).to.deep.equal(
{'foo': 'VARCHAR(255) PRIMARY KEY'}); { 'foo': 'VARCHAR(255) PRIMARY KEY' });
}); });
}); });
}); });
......
...@@ -15,7 +15,7 @@ describe('[MariaDB Specific] DAO', () => { ...@@ -15,7 +15,7 @@ describe('[MariaDB Specific] DAO', () => {
email: DataTypes.STRING, email: DataTypes.STRING,
location: DataTypes.GEOMETRY() location: DataTypes.GEOMETRY()
}); });
return this.User.sync({force: true}); return this.User.sync({ force: true });
}); });
afterEach(function() { afterEach(function() {
...@@ -29,15 +29,15 @@ describe('[MariaDB Specific] DAO', () => { ...@@ -29,15 +29,15 @@ describe('[MariaDB Specific] DAO', () => {
aNumber: DataTypes.INTEGER aNumber: DataTypes.INTEGER
}); });
return this.User.sync({force: true}); return this.User.sync({ force: true });
}); });
it('positive', function() { it('positive', function() {
const User = this.User; const User = this.User;
return User.create({aNumber: 2147483647}).then(user => { return User.create({ aNumber: 2147483647 }).then(user => {
expect(user.aNumber).to.equal(2147483647); expect(user.aNumber).to.equal(2147483647);
return User.findOne({where: {aNumber: 2147483647}}).then(_user => { return User.findOne({ where: { aNumber: 2147483647 } }).then(_user => {
expect(_user.aNumber).to.equal(2147483647); expect(_user.aNumber).to.equal(2147483647);
}); });
}); });
...@@ -46,9 +46,9 @@ describe('[MariaDB Specific] DAO', () => { ...@@ -46,9 +46,9 @@ describe('[MariaDB Specific] DAO', () => {
it('negative', function() { it('negative', function() {
const User = this.User; const User = this.User;
return User.create({aNumber: -2147483647}).then(user => { return User.create({ aNumber: -2147483647 }).then(user => {
expect(user.aNumber).to.equal(-2147483647); expect(user.aNumber).to.equal(-2147483647);
return User.findOne({where: {aNumber: -2147483647}}).then(_user => { return User.findOne({ where: { aNumber: -2147483647 } }).then(_user => {
expect(_user.aNumber).to.equal(-2147483647); expect(_user.aNumber).to.equal(-2147483647);
}); });
}); });
...@@ -61,15 +61,15 @@ describe('[MariaDB Specific] DAO', () => { ...@@ -61,15 +61,15 @@ describe('[MariaDB Specific] DAO', () => {
aNumber: DataTypes.BIGINT aNumber: DataTypes.BIGINT
}); });
return this.User.sync({force: true}); return this.User.sync({ force: true });
}); });
it('positive', function() { it('positive', function() {
const User = this.User; const User = this.User;
return User.create({aNumber: '9223372036854775807'}).then(user => { return User.create({ aNumber: '9223372036854775807' }).then(user => {
expect(user.aNumber).to.equal('9223372036854775807'); expect(user.aNumber).to.equal('9223372036854775807');
return User.findOne({where: {aNumber: '9223372036854775807'}}).then( return User.findOne({ where: { aNumber: '9223372036854775807' } }).then(
_user => { _user => {
return expect(_user.aNumber.toString()).to.equal( return expect(_user.aNumber.toString()).to.equal(
'9223372036854775807'); '9223372036854775807');
...@@ -80,10 +80,10 @@ describe('[MariaDB Specific] DAO', () => { ...@@ -80,10 +80,10 @@ describe('[MariaDB Specific] DAO', () => {
it('negative', function() { it('negative', function() {
const User = this.User; const User = this.User;
return User.create({aNumber: '-9223372036854775807'}).then(user => { return User.create({ aNumber: '-9223372036854775807' }).then(user => {
expect(user.aNumber).to.equal('-9223372036854775807'); expect(user.aNumber).to.equal('-9223372036854775807');
return User.findOne( return User.findOne(
{where: {aNumber: '-9223372036854775807'}}).then(_user => { { where: { aNumber: '-9223372036854775807' } }).then(_user => {
return expect(_user.aNumber.toString()).to.equal( return expect(_user.aNumber.toString()).to.equal(
'-9223372036854775807'); '-9223372036854775807');
}); });
...@@ -93,9 +93,9 @@ describe('[MariaDB Specific] DAO', () => { ...@@ -93,9 +93,9 @@ describe('[MariaDB Specific] DAO', () => {
}); });
it('should save geometry correctly', function() { it('should save geometry correctly', function() {
const point = {type: 'Point', coordinates: [39.807222, -76.984722]}; const point = { type: 'Point', coordinates: [39.807222, -76.984722] };
return this.User.create( return this.User.create(
{username: 'user', email: 'foo@bar.com', location: point}).then( { username: 'user', email: 'foo@bar.com', location: point }).then(
newUser => { newUser => {
expect(newUser.location).to.deep.eql(point); expect(newUser.location).to.deep.eql(point);
}); });
...@@ -103,15 +103,15 @@ describe('[MariaDB Specific] DAO', () => { ...@@ -103,15 +103,15 @@ describe('[MariaDB Specific] DAO', () => {
it('should update geometry correctly', function() { it('should update geometry correctly', function() {
const User = this.User; const User = this.User;
const point1 = {type: 'Point', coordinates: [39.807222, -76.984722]}; const point1 = { type: 'Point', coordinates: [39.807222, -76.984722] };
const point2 = {type: 'Point', coordinates: [39.828333, -77.232222]}; const point2 = { type: 'Point', coordinates: [39.828333, -77.232222] };
return User.create( return User.create(
{username: 'user', email: 'foo@bar.com', location: point1}) { username: 'user', email: 'foo@bar.com', location: point1 })
.then(oldUser => { .then(oldUser => {
return User.update({location: point2}, return User.update({ location: point2 },
{where: {username: oldUser.username}}) { where: { username: oldUser.username } })
.then(() => { .then(() => {
return User.findOne({where: {username: oldUser.username}}); return User.findOne({ where: { username: oldUser.username } });
}) })
.then(updatedUser => { .then(updatedUser => {
expect(updatedUser.location).to.deep.eql(point2); expect(updatedUser.location).to.deep.eql(point2);
...@@ -121,12 +121,12 @@ describe('[MariaDB Specific] DAO', () => { ...@@ -121,12 +121,12 @@ describe('[MariaDB Specific] DAO', () => {
it('should read geometry correctly', function() { it('should read geometry correctly', function() {
const User = this.User; const User = this.User;
const point = {type: 'Point', coordinates: [39.807222, -76.984722]}; const point = { type: 'Point', coordinates: [39.807222, -76.984722] };
return User.create( return User.create(
{username: 'user', email: 'foo@bar.com', location: point}).then( { username: 'user', email: 'foo@bar.com', location: point }).then(
user => { user => {
return User.findOne({where: {username: user.username}}); return User.findOne({ where: { username: user.username } });
}).then(user => { }).then(user => {
expect(user.location).to.deep.eql(point); expect(user.location).to.deep.eql(point);
}); });
......
...@@ -19,28 +19,28 @@ describe('[MariaDB Specific] Errors', () => { ...@@ -19,28 +19,28 @@ describe('[MariaDB Specific] Errors', () => {
describe('ForeignKeyConstraintError', () => { describe('ForeignKeyConstraintError', () => {
beforeEach(function() { beforeEach(function() {
this.Task = this.sequelize.define('task', {title: DataTypes.STRING}); this.Task = this.sequelize.define('task', { title: DataTypes.STRING });
this.User = this.sequelize.define('user', {username: DataTypes.STRING}); this.User = this.sequelize.define('user', { username: DataTypes.STRING });
this.UserTasks = this.sequelize.define('tasksusers', this.UserTasks = this.sequelize.define('tasksusers',
{userId: DataTypes.INTEGER, taskId: DataTypes.INTEGER}); { userId: DataTypes.INTEGER, taskId: DataTypes.INTEGER });
this.User.belongsToMany(this.Task, this.User.belongsToMany(this.Task,
{onDelete: 'RESTRICT', through: 'tasksusers'}); { onDelete: 'RESTRICT', through: 'tasksusers' });
this.Task.belongsToMany(this.User, this.Task.belongsToMany(this.User,
{onDelete: 'RESTRICT', through: 'tasksusers'}); { onDelete: 'RESTRICT', through: 'tasksusers' });
this.Task.belongsTo(this.User, this.Task.belongsTo(this.User,
{foreignKey: 'primaryUserId', as: 'primaryUsers'}); { foreignKey: 'primaryUserId', as: 'primaryUsers' });
}); });
it('in context of DELETE restriction', function() { it('in context of DELETE restriction', function() {
const self = this, const self = this,
ForeignKeyConstraintError = this.sequelize.ForeignKeyConstraintError; ForeignKeyConstraintError = this.sequelize.ForeignKeyConstraintError;
return this.sequelize.sync({force: true}).bind({}).then(() => { return this.sequelize.sync({ force: true }).bind({}).then(() => {
return Promise.all([ return Promise.all([
self.User.create({id: 67, username: 'foo'}), self.User.create({ id: 67, username: 'foo' }),
self.Task.create({id: 52, title: 'task'}) self.Task.create({ id: 52, title: 'task' })
]); ]);
}).spread(function(user1, task1) { }).spread(function(user1, task1) {
this.user1 = user1; this.user1 = user1;
...@@ -70,8 +70,8 @@ describe('[MariaDB Specific] Errors', () => { ...@@ -70,8 +70,8 @@ describe('[MariaDB Specific] Errors', () => {
const self = this, const self = this,
ForeignKeyConstraintError = this.sequelize.ForeignKeyConstraintError; ForeignKeyConstraintError = this.sequelize.ForeignKeyConstraintError;
return this.sequelize.sync({force: true}).then(() => return this.sequelize.sync({ force: true }).then(() =>
validateError(self.Task.create({title: 'task', primaryUserId: 5}), validateError(self.Task.create({ title: 'task', primaryUserId: 5 }),
ForeignKeyConstraintError, { ForeignKeyConstraintError, {
fields: ['primaryUserId'], fields: ['primaryUserId'],
table: 'users', table: 'users',
......
...@@ -15,7 +15,7 @@ if (dialect.match(/^mssql/)) { ...@@ -15,7 +15,7 @@ if (dialect.match(/^mssql/)) {
}); });
return this.sequelize.sync({ force: true }).then(() => { return this.sequelize.sync({ force: true }).then(() => {
return User.create({ username: 'John'}); return User.create({ username: 'John' });
}); });
}); });
......
...@@ -11,8 +11,8 @@ if (dialect === 'mysql') { ...@@ -11,8 +11,8 @@ if (dialect === 'mysql') {
describe('many-to-many', () => { describe('many-to-many', () => {
describe('where tables have the same prefix', () => { describe('where tables have the same prefix', () => {
it('should create a table wp_table1wp_table2s', function() { it('should create a table wp_table1wp_table2s', function() {
const Table2 = this.sequelize.define('wp_table2', {foo: DataTypes.STRING}), const Table2 = this.sequelize.define('wp_table2', { foo: DataTypes.STRING }),
Table1 = this.sequelize.define('wp_table1', {foo: DataTypes.STRING}); Table1 = this.sequelize.define('wp_table1', { foo: DataTypes.STRING });
Table1.belongsToMany(Table2, { through: 'wp_table1swp_table2s' }); Table1.belongsToMany(Table2, { through: 'wp_table1swp_table2s' });
Table2.belongsToMany(Table1, { through: 'wp_table1swp_table2s' }); Table2.belongsToMany(Table1, { through: 'wp_table1swp_table2s' });
...@@ -26,11 +26,11 @@ if (dialect === 'mysql') { ...@@ -26,11 +26,11 @@ if (dialect === 'mysql') {
describe('when join table name is specified', () => { describe('when join table name is specified', () => {
beforeEach(function() { beforeEach(function() {
const Table2 = this.sequelize.define('ms_table1', {foo: DataTypes.STRING}), const Table2 = this.sequelize.define('ms_table1', { foo: DataTypes.STRING }),
Table1 = this.sequelize.define('ms_table2', {foo: DataTypes.STRING}); Table1 = this.sequelize.define('ms_table2', { foo: DataTypes.STRING });
Table1.belongsToMany(Table2, {through: 'table1_to_table2'}); Table1.belongsToMany(Table2, { through: 'table1_to_table2' });
Table2.belongsToMany(Table1, {through: 'table1_to_table2'}); Table2.belongsToMany(Table1, { through: 'table1_to_table2' });
return Table1.sync({ force: true }).then(() => { return Table1.sync({ force: true }).then(() => {
return Table2.sync({ force: true }); return Table2.sync({ force: true });
}); });
...@@ -46,23 +46,23 @@ if (dialect === 'mysql') { ...@@ -46,23 +46,23 @@ if (dialect === 'mysql') {
describe('HasMany', () => { describe('HasMany', () => {
beforeEach(function() { beforeEach(function() {
//prevent periods from occurring in the table name since they are used to delimit (table.column) //prevent periods from occurring in the table name since they are used to delimit (table.column)
this.User = this.sequelize.define(`User${Math.ceil(Math.random() * 10000000)}`, { name: DataTypes.STRING}); this.User = this.sequelize.define(`User${Math.ceil(Math.random() * 10000000)}`, { name: DataTypes.STRING });
this.Task = this.sequelize.define(`Task${Math.ceil(Math.random() * 10000000)}`, { name: DataTypes.STRING}); this.Task = this.sequelize.define(`Task${Math.ceil(Math.random() * 10000000)}`, { name: DataTypes.STRING });
this.users = null; this.users = null;
this.tasks = null; this.tasks = null;
this.User.belongsToMany(this.Task, {as: 'Tasks', through: 'UserTasks'}); this.User.belongsToMany(this.Task, { as: 'Tasks', through: 'UserTasks' });
this.Task.belongsToMany(this.User, {as: 'Users', through: 'UserTasks'}); this.Task.belongsToMany(this.User, { as: 'Users', through: 'UserTasks' });
const users = [], const users = [],
tasks = []; tasks = [];
for (let i = 0; i < 5; ++i) { for (let i = 0; i < 5; ++i) {
users[users.length] = {name: `User${Math.random()}`}; users[users.length] = { name: `User${Math.random()}` };
} }
for (let x = 0; x < 5; ++x) { for (let x = 0; x < 5; ++x) {
tasks[tasks.length] = {name: `Task${Math.random()}`}; tasks[tasks.length] = { name: `Task${Math.random()}` };
} }
return this.sequelize.sync({ force: true }).then(() => { return this.sequelize.sync({ force: true }).then(() => {
......
...@@ -9,12 +9,12 @@ const DataTypes = require('../../../../lib/data-types'); ...@@ -9,12 +9,12 @@ const DataTypes = require('../../../../lib/data-types');
if (dialect === 'mysql') { if (dialect === 'mysql') {
describe('[MYSQL Specific] Connection Manager', () => { describe('[MYSQL Specific] Connection Manager', () => {
it('-FOUND_ROWS can be suppressed to get back legacy behavior', () => { it('-FOUND_ROWS can be suppressed to get back legacy behavior', () => {
const sequelize = Support.createSequelizeInstance({ dialectOptions: { flags: '' }}); const sequelize = Support.createSequelizeInstance({ dialectOptions: { flags: '' } });
const User = sequelize.define('User', { username: DataTypes.STRING }); const User = sequelize.define('User', { username: DataTypes.STRING });
return User.sync({force: true}) return User.sync({ force: true })
.then(() => User.create({ id: 1, username: 'jozef' })) .then(() => User.create({ id: 1, username: 'jozef' }))
.then(() => User.update({ username: 'jozef'}, { .then(() => User.update({ username: 'jozef' }, {
where: { where: {
id: 1 id: 1
} }
...@@ -24,7 +24,7 @@ if (dialect === 'mysql') { ...@@ -24,7 +24,7 @@ if (dialect === 'mysql') {
}); });
it('should acquire a valid connection when keepDefaultTimezone is true', () => { it('should acquire a valid connection when keepDefaultTimezone is true', () => {
const sequelize = Support.createSequelizeInstance({keepDefaultTimezone: true, pool: {min: 1, max: 1, handleDisconnects: true, idle: 5000}}); const sequelize = Support.createSequelizeInstance({ keepDefaultTimezone: true, pool: { min: 1, max: 1, handleDisconnects: true, idle: 5000 } });
const cm = sequelize.connectionManager; const cm = sequelize.connectionManager;
return sequelize return sequelize
.sync() .sync()
......
...@@ -15,55 +15,55 @@ if (dialect === 'mysql') { ...@@ -15,55 +15,55 @@ if (dialect === 'mysql') {
username: { type: DataTypes.STRING, unique: true } username: { type: DataTypes.STRING, unique: true }
}, { timestamps: false }); }, { timestamps: false });
expect(this.sequelize.getQueryInterface().QueryGenerator.attributesToSQL(User.rawAttributes)).to.deep.equal({username: 'VARCHAR(255) UNIQUE', id: 'INTEGER NOT NULL auto_increment PRIMARY KEY'}); expect(this.sequelize.getQueryInterface().QueryGenerator.attributesToSQL(User.rawAttributes)).to.deep.equal({ username: 'VARCHAR(255) UNIQUE', id: 'INTEGER NOT NULL auto_increment PRIMARY KEY' });
}); });
it('handles extended attributes (default)', function() { it('handles extended attributes (default)', function() {
const User = this.sequelize.define(`User${config.rand()}`, { const User = this.sequelize.define(`User${config.rand()}`, {
username: {type: DataTypes.STRING, defaultValue: 'foo'} username: { type: DataTypes.STRING, defaultValue: 'foo' }
}, { timestamps: false }); }, { timestamps: false });
expect(this.sequelize.getQueryInterface().QueryGenerator.attributesToSQL(User.rawAttributes)).to.deep.equal({username: "VARCHAR(255) DEFAULT 'foo'", id: 'INTEGER NOT NULL auto_increment PRIMARY KEY'}); expect(this.sequelize.getQueryInterface().QueryGenerator.attributesToSQL(User.rawAttributes)).to.deep.equal({ username: "VARCHAR(255) DEFAULT 'foo'", id: 'INTEGER NOT NULL auto_increment PRIMARY KEY' });
}); });
it('handles extended attributes (null)', function() { it('handles extended attributes (null)', function() {
const User = this.sequelize.define(`User${config.rand()}`, { const User = this.sequelize.define(`User${config.rand()}`, {
username: {type: DataTypes.STRING, allowNull: false} username: { type: DataTypes.STRING, allowNull: false }
}, { timestamps: false }); }, { timestamps: false });
expect(this.sequelize.getQueryInterface().QueryGenerator.attributesToSQL(User.rawAttributes)).to.deep.equal({username: 'VARCHAR(255) NOT NULL', id: 'INTEGER NOT NULL auto_increment PRIMARY KEY'}); expect(this.sequelize.getQueryInterface().QueryGenerator.attributesToSQL(User.rawAttributes)).to.deep.equal({ username: 'VARCHAR(255) NOT NULL', id: 'INTEGER NOT NULL auto_increment PRIMARY KEY' });
}); });
it('handles extended attributes (primaryKey)', function() { it('handles extended attributes (primaryKey)', function() {
const User = this.sequelize.define(`User${config.rand()}`, { const User = this.sequelize.define(`User${config.rand()}`, {
username: {type: DataTypes.STRING, primaryKey: true} username: { type: DataTypes.STRING, primaryKey: true }
}, { timestamps: false }); }, { timestamps: false });
expect(this.sequelize.getQueryInterface().QueryGenerator.attributesToSQL(User.rawAttributes)).to.deep.equal({username: 'VARCHAR(255) PRIMARY KEY'}); expect(this.sequelize.getQueryInterface().QueryGenerator.attributesToSQL(User.rawAttributes)).to.deep.equal({ username: 'VARCHAR(255) PRIMARY KEY' });
}); });
it('adds timestamps', function() { it('adds timestamps', function() {
const User1 = this.sequelize.define(`User${config.rand()}`, {}); const User1 = this.sequelize.define(`User${config.rand()}`, {});
const User2 = this.sequelize.define(`User${config.rand()}`, {}, { timestamps: true}); const User2 = this.sequelize.define(`User${config.rand()}`, {}, { timestamps: true });
expect(this.sequelize.getQueryInterface().QueryGenerator.attributesToSQL(User1.rawAttributes)).to.deep.equal({id: 'INTEGER NOT NULL auto_increment PRIMARY KEY', updatedAt: 'DATETIME NOT NULL', createdAt: 'DATETIME NOT NULL'}); expect(this.sequelize.getQueryInterface().QueryGenerator.attributesToSQL(User1.rawAttributes)).to.deep.equal({ id: 'INTEGER NOT NULL auto_increment PRIMARY KEY', updatedAt: 'DATETIME NOT NULL', createdAt: 'DATETIME NOT NULL' });
expect(this.sequelize.getQueryInterface().QueryGenerator.attributesToSQL(User2.rawAttributes)).to.deep.equal({id: 'INTEGER NOT NULL auto_increment PRIMARY KEY', updatedAt: 'DATETIME NOT NULL', createdAt: 'DATETIME NOT NULL'}); expect(this.sequelize.getQueryInterface().QueryGenerator.attributesToSQL(User2.rawAttributes)).to.deep.equal({ id: 'INTEGER NOT NULL auto_increment PRIMARY KEY', updatedAt: 'DATETIME NOT NULL', createdAt: 'DATETIME NOT NULL' });
}); });
it('adds deletedAt if paranoid', function() { it('adds deletedAt if paranoid', function() {
const User = this.sequelize.define(`User${config.rand()}`, {}, { paranoid: true}); const User = this.sequelize.define(`User${config.rand()}`, {}, { paranoid: true });
expect(this.sequelize.getQueryInterface().QueryGenerator.attributesToSQL(User.rawAttributes)).to.deep.equal({id: 'INTEGER NOT NULL auto_increment PRIMARY KEY', deletedAt: 'DATETIME', updatedAt: 'DATETIME NOT NULL', createdAt: 'DATETIME NOT NULL'}); expect(this.sequelize.getQueryInterface().QueryGenerator.attributesToSQL(User.rawAttributes)).to.deep.equal({ id: 'INTEGER NOT NULL auto_increment PRIMARY KEY', deletedAt: 'DATETIME', updatedAt: 'DATETIME NOT NULL', createdAt: 'DATETIME NOT NULL' });
}); });
it('underscores timestamps if underscored', function() { it('underscores timestamps if underscored', function() {
const User = this.sequelize.define(`User${config.rand()}`, {}, { paranoid: true, underscored: true}); const User = this.sequelize.define(`User${config.rand()}`, {}, { paranoid: true, underscored: true });
expect(this.sequelize.getQueryInterface().QueryGenerator.attributesToSQL(User.rawAttributes)).to.deep.equal({id: 'INTEGER NOT NULL auto_increment PRIMARY KEY', deleted_at: 'DATETIME', updated_at: 'DATETIME NOT NULL', created_at: 'DATETIME NOT NULL'}); expect(this.sequelize.getQueryInterface().QueryGenerator.attributesToSQL(User.rawAttributes)).to.deep.equal({ id: 'INTEGER NOT NULL auto_increment PRIMARY KEY', deleted_at: 'DATETIME', updated_at: 'DATETIME NOT NULL', created_at: 'DATETIME NOT NULL' });
}); });
it('omits text fields with defaultValues', function() { it('omits text fields with defaultValues', function() {
const User = this.sequelize.define(`User${config.rand()}`, {name: {type: DataTypes.TEXT, defaultValue: 'helloworld'}}); const User = this.sequelize.define(`User${config.rand()}`, { name: { type: DataTypes.TEXT, defaultValue: 'helloworld' } });
expect(User.rawAttributes.name.type.toString()).to.equal('TEXT'); expect(User.rawAttributes.name.type.toString()).to.equal('TEXT');
}); });
it('omits blobs fields with defaultValues', function() { it('omits blobs fields with defaultValues', function() {
const User = this.sequelize.define(`User${config.rand()}`, {name: {type: DataTypes.STRING.BINARY, defaultValue: 'helloworld'}}); const User = this.sequelize.define(`User${config.rand()}`, { name: { type: DataTypes.STRING.BINARY, defaultValue: 'helloworld' } });
expect(User.rawAttributes.name.type.toString()).to.equal('VARCHAR(255) BINARY'); expect(User.rawAttributes.name.type.toString()).to.equal('VARCHAR(255) BINARY');
}); });
}); });
...@@ -71,10 +71,10 @@ if (dialect === 'mysql') { ...@@ -71,10 +71,10 @@ if (dialect === 'mysql') {
describe('primaryKeys', () => { describe('primaryKeys', () => {
it('determines the correct primaryKeys', function() { it('determines the correct primaryKeys', function() {
const User = this.sequelize.define(`User${config.rand()}`, { const User = this.sequelize.define(`User${config.rand()}`, {
foo: {type: DataTypes.STRING, primaryKey: true}, foo: { type: DataTypes.STRING, primaryKey: true },
bar: DataTypes.STRING bar: DataTypes.STRING
}); });
expect(this.sequelize.getQueryInterface().QueryGenerator.attributesToSQL(User.primaryKeys)).to.deep.equal({'foo': 'VARCHAR(255) PRIMARY KEY'}); expect(this.sequelize.getQueryInterface().QueryGenerator.attributesToSQL(User.primaryKeys)).to.deep.equal({ 'foo': 'VARCHAR(255) PRIMARY KEY' });
}); });
}); });
}); });
......
...@@ -12,8 +12,8 @@ if (dialect.match(/^postgres/)) { ...@@ -12,8 +12,8 @@ if (dialect.match(/^postgres/)) {
describe('many-to-many', () => { describe('many-to-many', () => {
describe('where tables have the same prefix', () => { describe('where tables have the same prefix', () => {
it('should create a table wp_table1wp_table2s', function() { it('should create a table wp_table1wp_table2s', function() {
const Table2 = this.sequelize.define('wp_table2', {foo: DataTypes.STRING}), const Table2 = this.sequelize.define('wp_table2', { foo: DataTypes.STRING }),
Table1 = this.sequelize.define('wp_table1', {foo: DataTypes.STRING}); Table1 = this.sequelize.define('wp_table1', { foo: DataTypes.STRING });
Table1.belongsToMany(Table2, { through: 'wp_table1swp_table2s' }); Table1.belongsToMany(Table2, { through: 'wp_table1swp_table2s' });
Table2.belongsToMany(Table1, { through: 'wp_table1swp_table2s' }); Table2.belongsToMany(Table1, { through: 'wp_table1swp_table2s' });
...@@ -24,11 +24,11 @@ if (dialect.match(/^postgres/)) { ...@@ -24,11 +24,11 @@ if (dialect.match(/^postgres/)) {
describe('when join table name is specified', () => { describe('when join table name is specified', () => {
beforeEach(function() { beforeEach(function() {
const Table2 = this.sequelize.define('ms_table1', {foo: DataTypes.STRING}), const Table2 = this.sequelize.define('ms_table1', { foo: DataTypes.STRING }),
Table1 = this.sequelize.define('ms_table2', {foo: DataTypes.STRING}); Table1 = this.sequelize.define('ms_table2', { foo: DataTypes.STRING });
Table1.belongsToMany(Table2, {through: 'table1_to_table2'}); Table1.belongsToMany(Table2, { through: 'table1_to_table2' });
Table2.belongsToMany(Table1, {through: 'table1_to_table2'}); Table2.belongsToMany(Table1, { through: 'table1_to_table2' });
}); });
it('should not use a combined name', function() { it('should not use a combined name', function() {
...@@ -45,23 +45,23 @@ if (dialect.match(/^postgres/)) { ...@@ -45,23 +45,23 @@ if (dialect.match(/^postgres/)) {
describe('addDAO / getModel', () => { describe('addDAO / getModel', () => {
beforeEach(function() { beforeEach(function() {
//prevent periods from occurring in the table name since they are used to delimit (table.column) //prevent periods from occurring in the table name since they are used to delimit (table.column)
this.User = this.sequelize.define(`User${config.rand()}`, { name: DataTypes.STRING}); this.User = this.sequelize.define(`User${config.rand()}`, { name: DataTypes.STRING });
this.Task = this.sequelize.define(`Task${config.rand()}`, { name: DataTypes.STRING}); this.Task = this.sequelize.define(`Task${config.rand()}`, { name: DataTypes.STRING });
this.users = null; this.users = null;
this.tasks = null; this.tasks = null;
this.User.belongsToMany(this.Task, {as: 'Tasks', through: 'usertasks'}); this.User.belongsToMany(this.Task, { as: 'Tasks', through: 'usertasks' });
this.Task.belongsToMany(this.User, {as: 'Users', through: 'usertasks'}); this.Task.belongsToMany(this.User, { as: 'Users', through: 'usertasks' });
const users = [], const users = [],
tasks = []; tasks = [];
for (let i = 0; i < 5; ++i) { for (let i = 0; i < 5; ++i) {
users[users.length] = {name: `User${Math.random()}`}; users[users.length] = { name: `User${Math.random()}` };
} }
for (let x = 0; x < 5; ++x) { for (let x = 0; x < 5; ++x) {
tasks[tasks.length] = {name: `Task${Math.random()}`}; tasks[tasks.length] = { name: `Task${Math.random()}` };
} }
return this.sequelize.sync({ force: true }).then(() => { return this.sequelize.sync({ force: true }).then(() => {
...@@ -96,20 +96,20 @@ if (dialect.match(/^postgres/)) { ...@@ -96,20 +96,20 @@ if (dialect.match(/^postgres/)) {
tasks = []; tasks = [];
//prevent periods from occurring in the table name since they are used to delimit (table.column) //prevent periods from occurring in the table name since they are used to delimit (table.column)
this.User = this.sequelize.define(`User${config.rand()}`, { name: DataTypes.STRING}); this.User = this.sequelize.define(`User${config.rand()}`, { name: DataTypes.STRING });
this.Task = this.sequelize.define(`Task${config.rand()}`, { name: DataTypes.STRING}); this.Task = this.sequelize.define(`Task${config.rand()}`, { name: DataTypes.STRING });
this.users = null; this.users = null;
this.tasks = null; this.tasks = null;
this.User.belongsToMany(this.Task, {as: 'Tasks', through: 'usertasks'}); this.User.belongsToMany(this.Task, { as: 'Tasks', through: 'usertasks' });
this.Task.belongsToMany(this.User, {as: 'Users', through: 'usertasks'}); this.Task.belongsToMany(this.User, { as: 'Users', through: 'usertasks' });
for (let i = 0; i < 5; ++i) { for (let i = 0; i < 5; ++i) {
users[users.length] = {id: i + 1, name: `User${Math.random()}`}; users[users.length] = { id: i + 1, name: `User${Math.random()}` };
} }
for (let x = 0; x < 5; ++x) { for (let x = 0; x < 5; ++x) {
tasks[tasks.length] = {id: x + 1, name: `Task${Math.random()}`}; tasks[tasks.length] = { id: x + 1, name: `Task${Math.random()}` };
} }
return this.sequelize.sync({ force: true }).then(() => { return this.sequelize.sync({ force: true }).then(() => {
......
...@@ -13,8 +13,8 @@ if (dialect.match(/^postgres/)) { ...@@ -13,8 +13,8 @@ if (dialect.match(/^postgres/)) {
const sequelize = Support.createSequelizeInstance(options); const sequelize = Support.createSequelizeInstance(options);
const tzTable = sequelize.define('tz_table', { foo: DataTypes.STRING }); const tzTable = sequelize.define('tz_table', { foo: DataTypes.STRING });
return tzTable.sync({force: true}).then(() => { return tzTable.sync({ force: true }).then(() => {
return tzTable.create({foo: 'test'}).then(row => { return tzTable.create({ foo: 'test' }).then(row => {
expect(row).to.be.not.null; expect(row).to.be.not.null;
}); });
}); });
...@@ -52,7 +52,7 @@ if (dialect.match(/^postgres/)) { ...@@ -52,7 +52,7 @@ if (dialect.match(/^postgres/)) {
perms: DataTypes.ENUM(['foo', 'bar']) perms: DataTypes.ENUM(['foo', 'bar'])
}); });
return User.sync({force: true}); return User.sync({ force: true });
} }
it('should fetch regular dynamic oids and create parsers', () => { it('should fetch regular dynamic oids and create parsers', () => {
......
...@@ -913,7 +913,7 @@ if (dialect.match(/^postgres/)) { ...@@ -913,7 +913,7 @@ if (dialect.match(/^postgres/)) {
it('should read range array correctly', function() { it('should read range array correctly', function() {
const User = this.User; const User = this.User;
const holidays = [ const holidays = [
[{ value: new Date(2015, 3, 1, 10), inclusive: true}, { value: new Date(2015, 3, 15), inclusive: true }], [{ value: new Date(2015, 3, 1, 10), inclusive: true }, { value: new Date(2015, 3, 15), inclusive: true }],
[{ value: new Date(2015, 8, 1), inclusive: true }, { value: new Date(2015, 9, 15), inclusive: true }] [{ value: new Date(2015, 8, 1), inclusive: true }, { value: new Date(2015, 9, 15), inclusive: true }]
]; ];
const data = { username: 'user', email: ['foo@bar.com'], holidays }; const data = { username: 'user', email: ['foo@bar.com'], holidays };
......
...@@ -22,19 +22,19 @@ if (dialect.match(/^postgres/)) { ...@@ -22,19 +22,19 @@ if (dialect.match(/^postgres/)) {
}); });
it('should handle empty string correctly', () => { it('should handle empty string correctly', () => {
expect(hstore.stringify({foo: ''})).to.equal('"foo"=>\"\"'); expect(hstore.stringify({ foo: '' })).to.equal('"foo"=>\"\"');
}); });
it('should handle a string with backslashes correctly', () => { it('should handle a string with backslashes correctly', () => {
expect(hstore.stringify({foo: '\\'})).to.equal('"foo"=>"\\\\"'); expect(hstore.stringify({ foo: '\\' })).to.equal('"foo"=>"\\\\"');
}); });
it('should handle a string with double quotes correctly', () => { it('should handle a string with double quotes correctly', () => {
expect(hstore.stringify({foo: '""a"'})).to.equal('"foo"=>"\\"\\"a\\""'); expect(hstore.stringify({ foo: '""a"' })).to.equal('"foo"=>"\\"\\"a\\""');
}); });
it('should handle a string with single quotes correctly', () => { it('should handle a string with single quotes correctly', () => {
expect(hstore.stringify({foo: "''a'"})).to.equal('"foo"=>"\'\'\'\'a\'\'"'); expect(hstore.stringify({ foo: "''a'" })).to.equal('"foo"=>"\'\'\'\'a\'\'"');
}); });
it('should handle simple objects correctly', () => { it('should handle simple objects correctly', () => {
...@@ -49,19 +49,19 @@ if (dialect.match(/^postgres/)) { ...@@ -49,19 +49,19 @@ if (dialect.match(/^postgres/)) {
}); });
it('should handle empty string correctly', () => { it('should handle empty string correctly', () => {
expect(hstore.parse('"foo"=>\"\"')).to.deep.equal({foo: ''}); expect(hstore.parse('"foo"=>\"\"')).to.deep.equal({ foo: '' });
}); });
it('should handle a string with double quotes correctly', () => { it('should handle a string with double quotes correctly', () => {
expect(hstore.parse('"foo"=>"\\\"\\\"a\\\""')).to.deep.equal({foo: '\"\"a\"'}); expect(hstore.parse('"foo"=>"\\\"\\\"a\\\""')).to.deep.equal({ foo: '\"\"a\"' });
}); });
it('should handle a string with single quotes correctly', () => { it('should handle a string with single quotes correctly', () => {
expect(hstore.parse('"foo"=>"\'\'\'\'a\'\'"')).to.deep.equal({foo: "''a'"}); expect(hstore.parse('"foo"=>"\'\'\'\'a\'\'"')).to.deep.equal({ foo: "''a'" });
}); });
it('should handle a string with backslashes correctly', () => { it('should handle a string with backslashes correctly', () => {
expect(hstore.parse('"foo"=>"\\\\"')).to.deep.equal({foo: '\\'}); expect(hstore.parse('"foo"=>"\\\\"')).to.deep.equal({ foo: '\\' });
}); });
it('should handle empty objects correctly', () => { it('should handle empty objects correctly', () => {
...@@ -75,7 +75,7 @@ if (dialect.match(/^postgres/)) { ...@@ -75,7 +75,7 @@ if (dialect.match(/^postgres/)) {
}); });
describe('stringify and parse', () => { describe('stringify and parse', () => {
it('should stringify then parse back the same structure', () => { it('should stringify then parse back the same structure', () => {
const testObj = {foo: 'bar', count: '1', emptyString: '', quotyString: '""', extraQuotyString: '"""a"""""', backslashes: '\\f023', moreBackslashes: '\\f\\0\\2\\1', backslashesAndQuotes: '\\"\\"uhoh"\\"', nully: null}; const testObj = { foo: 'bar', count: '1', emptyString: '', quotyString: '""', extraQuotyString: '"""a"""""', backslashes: '\\f023', moreBackslashes: '\\f\\0\\2\\1', backslashesAndQuotes: '\\"\\"uhoh"\\"', nully: null };
expect(hstore.parse(hstore.stringify(testObj))).to.deep.equal(testObj); expect(hstore.parse(hstore.stringify(testObj))).to.deep.equal(testObj);
expect(hstore.parse(hstore.stringify(hstore.parse(hstore.stringify(testObj))))).to.deep.equal(testObj); expect(hstore.parse(hstore.stringify(hstore.parse(hstore.stringify(testObj))))).to.deep.equal(testObj);
}); });
......
...@@ -85,14 +85,14 @@ if (dialect.match(/^postgres/)) { ...@@ -85,14 +85,14 @@ if (dialect.match(/^postgres/)) {
// make sure we don't have a pre-existing function called create_job // make sure we don't have a pre-existing function called create_job
// this is needed to cover the edge case of afterEach not getting called because of an unexpected issue or stopage with the // this is needed to cover the edge case of afterEach not getting called because of an unexpected issue or stopage with the
// test suite causing a failure of afterEach's cleanup to be called. // test suite causing a failure of afterEach's cleanup to be called.
return this.queryInterface.dropFunction('create_job', [{type: 'varchar', name: 'test'}]) return this.queryInterface.dropFunction('create_job', [{ type: 'varchar', name: 'test' }])
// suppress errors here. if create_job doesn't exist thats ok. // suppress errors here. if create_job doesn't exist thats ok.
.reflect(); .reflect();
}); });
after(function() { after(function() {
// cleanup // cleanup
return this.queryInterface.dropFunction('create_job', [{type: 'varchar', name: 'test'}]) return this.queryInterface.dropFunction('create_job', [{ type: 'varchar', name: 'test' }])
// suppress errors here. if create_job doesn't exist thats ok. // suppress errors here. if create_job doesn't exist thats ok.
.reflect(); .reflect();
}); });
...@@ -102,7 +102,7 @@ if (dialect.match(/^postgres/)) { ...@@ -102,7 +102,7 @@ if (dialect.match(/^postgres/)) {
const options = {}; const options = {};
// make our call to create a function // make our call to create a function
return this.queryInterface.createFunction('create_job', [{type: 'varchar', name: 'test'}], 'varchar', 'plpgsql', body, options) return this.queryInterface.createFunction('create_job', [{ type: 'varchar', name: 'test' }], 'varchar', 'plpgsql', body, options)
// validate // validate
.then(() => this.sequelize.query('select create_job(\'test\');', { type: this.sequelize.QueryTypes.SELECT })) .then(() => this.sequelize.query('select create_job(\'test\');', { type: this.sequelize.QueryTypes.SELECT }))
.then(res => { .then(res => {
...@@ -114,7 +114,7 @@ if (dialect.match(/^postgres/)) { ...@@ -114,7 +114,7 @@ if (dialect.match(/^postgres/)) {
const body = 'return test;'; const body = 'return test;';
// run with null options parameter // run with null options parameter
return this.queryInterface.createFunction('create_job', [{type: 'varchar', name: 'test'}], 'varchar', 'plpgsql', body, null) return this.queryInterface.createFunction('create_job', [{ type: 'varchar', name: 'test' }], 'varchar', 'plpgsql', body, null)
// validate // validate
.then(() => this.sequelize.query('select create_job(\'test\');', { type: this.sequelize.QueryTypes.SELECT })) .then(() => this.sequelize.query('select create_job(\'test\');', { type: this.sequelize.QueryTypes.SELECT }))
.then(res => { .then(res => {
...@@ -129,7 +129,7 @@ if (dialect.match(/^postgres/)) { ...@@ -129,7 +129,7 @@ if (dialect.match(/^postgres/)) {
return Promise.all([ return Promise.all([
// requires functionName // requires functionName
expect(() => { expect(() => {
return this.queryInterface.createFunction(null, [{name: 'test'}], 'integer', 'plpgsql', body, options); return this.queryInterface.createFunction(null, [{ name: 'test' }], 'integer', 'plpgsql', body, options);
}).to.throw(/createFunction missing some parameters. Did you pass functionName, returnType, language and body/), }).to.throw(/createFunction missing some parameters. Did you pass functionName, returnType, language and body/),
// requires Parameters array // requires Parameters array
...@@ -139,22 +139,22 @@ if (dialect.match(/^postgres/)) { ...@@ -139,22 +139,22 @@ if (dialect.match(/^postgres/)) {
// requires returnType // requires returnType
expect(() => { expect(() => {
return this.queryInterface.createFunction('create_job', [{type: 'varchar', name: 'test'}], null, 'plpgsql', body, options); return this.queryInterface.createFunction('create_job', [{ type: 'varchar', name: 'test' }], null, 'plpgsql', body, options);
}).to.throw(/createFunction missing some parameters. Did you pass functionName, returnType, language and body/), }).to.throw(/createFunction missing some parameters. Did you pass functionName, returnType, language and body/),
// requires type in parameter array // requires type in parameter array
expect(() => { expect(() => {
return this.queryInterface.createFunction('create_job', [{name: 'test'}], 'integer', 'plpgsql', body, options); return this.queryInterface.createFunction('create_job', [{ name: 'test' }], 'integer', 'plpgsql', body, options);
}).to.throw(/function or trigger used with a parameter without any type/), }).to.throw(/function or trigger used with a parameter without any type/),
// requires language // requires language
expect(() => { expect(() => {
return this.queryInterface.createFunction('create_job', [{type: 'varchar', name: 'test'}], 'varchar', null, body, options); return this.queryInterface.createFunction('create_job', [{ type: 'varchar', name: 'test' }], 'varchar', null, body, options);
}).to.throw(/createFunction missing some parameters. Did you pass functionName, returnType, language and body/), }).to.throw(/createFunction missing some parameters. Did you pass functionName, returnType, language and body/),
// requires body // requires body
expect(() => { expect(() => {
return this.queryInterface.createFunction('create_job', [{type: 'varchar', name: 'test'}], 'varchar', 'plpgsql', null, options); return this.queryInterface.createFunction('create_job', [{ type: 'varchar', name: 'test' }], 'varchar', 'plpgsql', null, options);
}).to.throw(/createFunction missing some parameters. Did you pass functionName, returnType, language and body/) }).to.throw(/createFunction missing some parameters. Did you pass functionName, returnType, language and body/)
]); ]);
}); });
...@@ -166,7 +166,7 @@ if (dialect.match(/^postgres/)) { ...@@ -166,7 +166,7 @@ if (dialect.match(/^postgres/)) {
const options = {}; const options = {};
// make sure we have a droptest function in place. // make sure we have a droptest function in place.
return this.queryInterface.createFunction('droptest', [{type: 'varchar', name: 'test'}], 'varchar', 'plpgsql', body, options) return this.queryInterface.createFunction('droptest', [{ type: 'varchar', name: 'test' }], 'varchar', 'plpgsql', body, options)
// suppress errors.. this could fail if the function is already there.. thats ok. // suppress errors.. this could fail if the function is already there.. thats ok.
.reflect(); .reflect();
}); });
...@@ -174,7 +174,7 @@ if (dialect.match(/^postgres/)) { ...@@ -174,7 +174,7 @@ if (dialect.match(/^postgres/)) {
it('can drop a function', function() { it('can drop a function', function() {
return expect( return expect(
// call drop function // call drop function
this.queryInterface.dropFunction('droptest', [{type: 'varchar', name: 'test'}]) this.queryInterface.dropFunction('droptest', [{ type: 'varchar', name: 'test' }])
// now call the function we attempted to drop.. if dropFunction worked as expect it should produce an error. // now call the function we attempted to drop.. if dropFunction worked as expect it should produce an error.
.then(() => { .then(() => {
// call the function we attempted to drop.. if it is still there then throw an error informing that the expected behavior is not met. // call the function we attempted to drop.. if it is still there then throw an error informing that the expected behavior is not met.
...@@ -195,7 +195,7 @@ if (dialect.match(/^postgres/)) { ...@@ -195,7 +195,7 @@ if (dialect.match(/^postgres/)) {
}).to.throw(/.*function parameters array required/), }).to.throw(/.*function parameters array required/),
expect(() => { expect(() => {
return this.queryInterface.dropFunction('droptest', [{name: 'test'}]); return this.queryInterface.dropFunction('droptest', [{ name: 'test' }]);
}).to.be.throw(/.*function or trigger used with a parameter without any type/) }).to.be.throw(/.*function or trigger used with a parameter without any type/)
]); ]);
}); });
......
...@@ -205,7 +205,7 @@ if (dialect.match(/^postgres/)) { ...@@ -205,7 +205,7 @@ if (dialect.match(/^postgres/)) {
let stringified = Range.stringify(testRange, {}); let stringified = Range.stringify(testRange, {});
stringified = stringified.substr(1, stringified.length - 2); // Remove the escaping ticks stringified = stringified.substr(1, stringified.length - 2); // Remove the escaping ticks
expect(DataTypes.postgres.RANGE.parse(stringified, {parser: DataTypes.postgres.INTEGER.parse})).to.deep.equal(testRange); expect(DataTypes.postgres.RANGE.parse(stringified, { parser: DataTypes.postgres.INTEGER.parse })).to.deep.equal(testRange);
}); });
}); });
}); });
......
...@@ -101,7 +101,7 @@ if (dialect === 'sqlite') { ...@@ -101,7 +101,7 @@ if (dialect === 'sqlite') {
describe('.findOne', () => { describe('.findOne', () => {
beforeEach(function() { beforeEach(function() {
return this.User.create({name: 'user', bio: 'footbar'}); return this.User.create({ name: 'user', bio: 'footbar' });
}); });
it('finds normal lookups', function() { it('finds normal lookups', function() {
...@@ -123,8 +123,8 @@ if (dialect === 'sqlite') { ...@@ -123,8 +123,8 @@ if (dialect === 'sqlite') {
describe('.all', () => { describe('.all', () => {
beforeEach(function() { beforeEach(function() {
return this.User.bulkCreate([ return this.User.bulkCreate([
{name: 'user', bio: 'foobar'}, { name: 'user', bio: 'foobar' },
{name: 'user', bio: 'foobar'} { name: 'user', bio: 'foobar' }
]); ]);
}); });
...@@ -140,7 +140,7 @@ if (dialect === 'sqlite') { ...@@ -140,7 +140,7 @@ if (dialect === 'sqlite') {
const users = []; const users = [];
for (let i = 2; i < 5; i++) { for (let i = 2; i < 5; i++) {
users[users.length] = {age: i}; users[users.length] = { age: i };
} }
return this.User.bulkCreate(users).then(() => { return this.User.bulkCreate(users).then(() => {
...@@ -156,7 +156,7 @@ if (dialect === 'sqlite') { ...@@ -156,7 +156,7 @@ if (dialect === 'sqlite') {
const users = []; const users = [];
for (let i = 2; i <= 5; i++) { for (let i = 2; i <= 5; i++) {
users[users.length] = {age: i}; users[users.length] = { age: i };
} }
return this.User.bulkCreate(users).then(() => { return this.User.bulkCreate(users).then(() => {
......
...@@ -252,8 +252,8 @@ describe(Support.getTestDialectTeaser('Sequelize Errors'), () => { ...@@ -252,8 +252,8 @@ describe(Support.getTestDialectTeaser('Sequelize Errors'), () => {
version: true version: true
}); });
return Account.sync({force: true}).then(() => { return Account.sync({ force: true }).then(() => {
const result = Account.create({number: 1}).then(accountA => { const result = Account.create({ number: 1 }).then(accountA => {
return Account.findByPk(accountA.id).then(accountB => { return Account.findByPk(accountA.id).then(accountB => {
accountA.number += 1; accountA.number += 1;
return accountA.save().then(() => { return accountB; }); return accountA.save().then(() => { return accountB; });
......
...@@ -23,9 +23,9 @@ describe(Support.getTestDialectTeaser('Hooks'), () => { ...@@ -23,9 +23,9 @@ describe(Support.getTestDialectTeaser('Hooks'), () => {
describe('#count', () => { describe('#count', () => {
beforeEach(function() { beforeEach(function() {
return this.User.bulkCreate([ return this.User.bulkCreate([
{username: 'adam', mood: 'happy'}, { username: 'adam', mood: 'happy' },
{username: 'joe', mood: 'sad'}, { username: 'joe', mood: 'sad' },
{username: 'joe', mood: 'happy'} { username: 'joe', mood: 'happy' }
]); ]);
}); });
...@@ -48,7 +48,7 @@ describe(Support.getTestDialectTeaser('Hooks'), () => { ...@@ -48,7 +48,7 @@ describe(Support.getTestDialectTeaser('Hooks'), () => {
options.where.username = 'adam'; options.where.username = 'adam';
}); });
return expect(this.User.count({where: {username: 'joe'}})).to.eventually.equal(1); return expect(this.User.count({ where: { username: 'joe' } })).to.eventually.equal(1);
}); });
}); });
...@@ -58,7 +58,7 @@ describe(Support.getTestDialectTeaser('Hooks'), () => { ...@@ -58,7 +58,7 @@ describe(Support.getTestDialectTeaser('Hooks'), () => {
throw new Error('Oops!'); throw new Error('Oops!');
}); });
return expect(this.User.count({where: {username: 'adam'}})).to.be.rejectedWith('Oops!'); return expect(this.User.count({ where: { username: 'adam' } })).to.be.rejectedWith('Oops!');
}); });
}); });
}); });
......
...@@ -36,7 +36,7 @@ describe(Support.getTestDialectTeaser('Hooks'), () => { ...@@ -36,7 +36,7 @@ describe(Support.getTestDialectTeaser('Hooks'), () => {
this.User.beforeSave(beforeSave); this.User.beforeSave(beforeSave);
this.User.afterSave(afterSave); this.User.afterSave(afterSave);
return this.User.create({username: 'Toni', mood: 'happy'}).then(() => { return this.User.create({ username: 'Toni', mood: 'happy' }).then(() => {
expect(beforeHook).to.have.been.calledOnce; expect(beforeHook).to.have.been.calledOnce;
expect(afterHook).to.have.been.calledOnce; expect(afterHook).to.have.been.calledOnce;
expect(beforeSave).to.have.been.calledOnce; expect(beforeSave).to.have.been.calledOnce;
...@@ -60,7 +60,7 @@ describe(Support.getTestDialectTeaser('Hooks'), () => { ...@@ -60,7 +60,7 @@ describe(Support.getTestDialectTeaser('Hooks'), () => {
this.User.beforeSave(beforeSave); this.User.beforeSave(beforeSave);
this.User.afterSave(afterSave); this.User.afterSave(afterSave);
return expect(this.User.create({username: 'Toni', mood: 'happy'})).to.be.rejected.then(() => { return expect(this.User.create({ username: 'Toni', mood: 'happy' })).to.be.rejected.then(() => {
expect(beforeHook).to.have.been.calledOnce; expect(beforeHook).to.have.been.calledOnce;
expect(afterHook).not.to.have.been.called; expect(afterHook).not.to.have.been.called;
expect(beforeSave).not.to.have.been.called; expect(beforeSave).not.to.have.been.called;
...@@ -83,7 +83,7 @@ describe(Support.getTestDialectTeaser('Hooks'), () => { ...@@ -83,7 +83,7 @@ describe(Support.getTestDialectTeaser('Hooks'), () => {
this.User.beforeSave(beforeSave); this.User.beforeSave(beforeSave);
this.User.afterSave(afterSave); this.User.afterSave(afterSave);
return expect(this.User.create({username: 'Toni', mood: 'happy'})).to.be.rejected.then(() => { return expect(this.User.create({ username: 'Toni', mood: 'happy' })).to.be.rejected.then(() => {
expect(beforeHook).to.have.been.calledOnce; expect(beforeHook).to.have.been.calledOnce;
expect(afterHook).to.have.been.calledOnce; expect(afterHook).to.have.been.calledOnce;
expect(beforeSave).to.have.been.calledOnce; expect(beforeSave).to.have.been.calledOnce;
...@@ -107,13 +107,13 @@ describe(Support.getTestDialectTeaser('Hooks'), () => { ...@@ -107,13 +107,13 @@ describe(Support.getTestDialectTeaser('Hooks'), () => {
return Promise.resolve(); return Promise.resolve();
}); });
B.belongsToMany(A, {through: 'a_b'}); B.belongsToMany(A, { through: 'a_b' });
A.belongsToMany(B, {through: 'a_b'}); A.belongsToMany(B, { through: 'a_b' });
return this.sequelize.sync({force: true}).then(() => { return this.sequelize.sync({ force: true }).then(() => {
return Sequelize.Promise.all([ return Sequelize.Promise.all([
A.create({name: 'a'}), A.create({ name: 'a' }),
B.create({name: 'b'}) B.create({ name: 'b' })
]).then(([a, b]) => { ]).then(([a, b]) => {
return a.addB(b).then(() => { return a.addB(b).then(() => {
expect(hookCalled).to.equal(1); expect(hookCalled).to.equal(1);
...@@ -131,7 +131,7 @@ describe(Support.getTestDialectTeaser('Hooks'), () => { ...@@ -131,7 +131,7 @@ describe(Support.getTestDialectTeaser('Hooks'), () => {
hookCalled++; hookCalled++;
}); });
return this.User.create({mood: 'sad', username: 'leafninja'}).then(user => { return this.User.create({ mood: 'sad', username: 'leafninja' }).then(user => {
expect(user.mood).to.equal('happy'); expect(user.mood).to.equal('happy');
expect(user.username).to.equal('leafninja'); expect(user.username).to.equal('leafninja');
expect(hookCalled).to.equal(1); expect(hookCalled).to.equal(1);
...@@ -146,7 +146,7 @@ describe(Support.getTestDialectTeaser('Hooks'), () => { ...@@ -146,7 +146,7 @@ describe(Support.getTestDialectTeaser('Hooks'), () => {
hookCalled++; hookCalled++;
}); });
return this.User.create({mood: 'sad', username: 'fireninja'}).then(user => { return this.User.create({ mood: 'sad', username: 'fireninja' }).then(user => {
expect(user.mood).to.equal('neutral'); expect(user.mood).to.equal('neutral');
expect(user.username).to.equal('fireninja'); expect(user.username).to.equal('fireninja');
expect(hookCalled).to.equal(1); expect(hookCalled).to.equal(1);
...@@ -161,7 +161,7 @@ describe(Support.getTestDialectTeaser('Hooks'), () => { ...@@ -161,7 +161,7 @@ describe(Support.getTestDialectTeaser('Hooks'), () => {
hookCalled++; hookCalled++;
}); });
return this.User.create({username: 'akira'}).then(user => { return this.User.create({ username: 'akira' }).then(user => {
expect(user.mood).to.equal('happy'); expect(user.mood).to.equal('happy');
expect(user.username).to.equal('akira'); expect(user.username).to.equal('akira');
expect(hookCalled).to.equal(1); expect(hookCalled).to.equal(1);
...@@ -176,7 +176,7 @@ describe(Support.getTestDialectTeaser('Hooks'), () => { ...@@ -176,7 +176,7 @@ describe(Support.getTestDialectTeaser('Hooks'), () => {
hookCalled++; hookCalled++;
}); });
return this.User.create({username: 'akira'}).then(user => { return this.User.create({ username: 'akira' }).then(user => {
expect(user.mood).to.equal('happy'); expect(user.mood).to.equal('happy');
expect(user.username).to.equal('akira'); expect(user.username).to.equal('akira');
expect(hookCalled).to.equal(1); expect(hookCalled).to.equal(1);
...@@ -196,7 +196,7 @@ describe(Support.getTestDialectTeaser('Hooks'), () => { ...@@ -196,7 +196,7 @@ describe(Support.getTestDialectTeaser('Hooks'), () => {
hookCalled++; hookCalled++;
}); });
return this.User.create({username: 'akira'}).then(user => { return this.User.create({ username: 'akira' }).then(user => {
expect(user.mood).to.equal('happy'); expect(user.mood).to.equal('happy');
expect(user.username).to.equal('akira'); expect(user.username).to.equal('akira');
expect(hookCalled).to.equal(2); expect(hookCalled).to.equal(2);
......
...@@ -30,7 +30,7 @@ describe(Support.getTestDialectTeaser('Hooks'), () => { ...@@ -30,7 +30,7 @@ describe(Support.getTestDialectTeaser('Hooks'), () => {
this.User.beforeDestroy(beforeHook); this.User.beforeDestroy(beforeHook);
this.User.afterDestroy(afterHook); this.User.afterDestroy(afterHook);
return this.User.create({username: 'Toni', mood: 'happy'}).then(user => { return this.User.create({ username: 'Toni', mood: 'happy' }).then(user => {
return user.destroy().then(() => { return user.destroy().then(() => {
expect(beforeHook).to.have.been.calledOnce; expect(beforeHook).to.have.been.calledOnce;
expect(afterHook).to.have.been.calledOnce; expect(afterHook).to.have.been.calledOnce;
...@@ -50,7 +50,7 @@ describe(Support.getTestDialectTeaser('Hooks'), () => { ...@@ -50,7 +50,7 @@ describe(Support.getTestDialectTeaser('Hooks'), () => {
}); });
this.User.afterDestroy(afterHook); this.User.afterDestroy(afterHook);
return this.User.create({username: 'Toni', mood: 'happy'}).then(user => { return this.User.create({ username: 'Toni', mood: 'happy' }).then(user => {
return expect(user.destroy()).to.be.rejected.then(() => { return expect(user.destroy()).to.be.rejected.then(() => {
expect(beforeHook).to.have.been.calledOnce; expect(beforeHook).to.have.been.calledOnce;
expect(afterHook).not.to.have.been.called; expect(afterHook).not.to.have.been.called;
...@@ -68,7 +68,7 @@ describe(Support.getTestDialectTeaser('Hooks'), () => { ...@@ -68,7 +68,7 @@ describe(Support.getTestDialectTeaser('Hooks'), () => {
throw new Error('Whoops!'); throw new Error('Whoops!');
}); });
return this.User.create({username: 'Toni', mood: 'happy'}).then(user => { return this.User.create({ username: 'Toni', mood: 'happy' }).then(user => {
return expect(user.destroy()).to.be.rejected.then(() => { return expect(user.destroy()).to.be.rejected.then(() => {
expect(beforeHook).to.have.been.calledOnce; expect(beforeHook).to.have.been.calledOnce;
expect(afterHook).to.have.been.calledOnce; expect(afterHook).to.have.been.calledOnce;
......
...@@ -24,8 +24,8 @@ describe(Support.getTestDialectTeaser('Hooks'), () => { ...@@ -24,8 +24,8 @@ describe(Support.getTestDialectTeaser('Hooks'), () => {
describe('#find', () => { describe('#find', () => {
beforeEach(function() { beforeEach(function() {
return this.User.bulkCreate([ return this.User.bulkCreate([
{username: 'adam', mood: 'happy'}, { username: 'adam', mood: 'happy' },
{username: 'joe', mood: 'sad'} { username: 'joe', mood: 'sad' }
]); ]);
}); });
...@@ -61,7 +61,7 @@ describe(Support.getTestDialectTeaser('Hooks'), () => { ...@@ -61,7 +61,7 @@ describe(Support.getTestDialectTeaser('Hooks'), () => {
afterHook = true; afterHook = true;
}); });
return this.User.findOne({where: {username: 'adam'}}).then(user => { return this.User.findOne({ where: { username: 'adam' } }).then(user => {
expect(user.mood).to.equal('happy'); expect(user.mood).to.equal('happy');
expect(beforeHook).to.be.true; expect(beforeHook).to.be.true;
expect(beforeHook2).to.be.true; expect(beforeHook2).to.be.true;
...@@ -75,7 +75,7 @@ describe(Support.getTestDialectTeaser('Hooks'), () => { ...@@ -75,7 +75,7 @@ describe(Support.getTestDialectTeaser('Hooks'), () => {
options.where.username = 'joe'; options.where.username = 'joe';
}); });
return this.User.findOne({where: {username: 'adam'}}).then(user => { return this.User.findOne({ where: { username: 'adam' } }).then(user => {
expect(user.mood).to.equal('sad'); expect(user.mood).to.equal('sad');
}); });
}); });
...@@ -85,7 +85,7 @@ describe(Support.getTestDialectTeaser('Hooks'), () => { ...@@ -85,7 +85,7 @@ describe(Support.getTestDialectTeaser('Hooks'), () => {
options.where.username = 'joe'; options.where.username = 'joe';
}); });
return this.User.findOne({where: {username: 'adam'}}).then(user => { return this.User.findOne({ where: { username: 'adam' } }).then(user => {
expect(user.mood).to.equal('sad'); expect(user.mood).to.equal('sad');
}); });
}); });
...@@ -95,7 +95,7 @@ describe(Support.getTestDialectTeaser('Hooks'), () => { ...@@ -95,7 +95,7 @@ describe(Support.getTestDialectTeaser('Hooks'), () => {
options.where.username = 'joe'; options.where.username = 'joe';
}); });
return this.User.findOne({where: {username: 'adam'}}).then(user => { return this.User.findOne({ where: { username: 'adam' } }).then(user => {
expect(user.mood).to.equal('sad'); expect(user.mood).to.equal('sad');
}); });
}); });
...@@ -105,7 +105,7 @@ describe(Support.getTestDialectTeaser('Hooks'), () => { ...@@ -105,7 +105,7 @@ describe(Support.getTestDialectTeaser('Hooks'), () => {
user.mood = 'sad'; user.mood = 'sad';
}); });
return this.User.findOne({where: {username: 'adam'}}).then(user => { return this.User.findOne({ where: { username: 'adam' } }).then(user => {
expect(user.mood).to.equal('sad'); expect(user.mood).to.equal('sad');
}); });
}); });
...@@ -117,7 +117,7 @@ describe(Support.getTestDialectTeaser('Hooks'), () => { ...@@ -117,7 +117,7 @@ describe(Support.getTestDialectTeaser('Hooks'), () => {
throw new Error('Oops!'); throw new Error('Oops!');
}); });
return this.User.findOne({where: {username: 'adam'}}).catch (err => { return this.User.findOne({ where: { username: 'adam' } }).catch(err => {
expect(err.message).to.equal('Oops!'); expect(err.message).to.equal('Oops!');
}); });
}); });
...@@ -127,7 +127,7 @@ describe(Support.getTestDialectTeaser('Hooks'), () => { ...@@ -127,7 +127,7 @@ describe(Support.getTestDialectTeaser('Hooks'), () => {
throw new Error('Oops!'); throw new Error('Oops!');
}); });
return this.User.findOne({where: {username: 'adam'}}).catch (err => { return this.User.findOne({ where: { username: 'adam' } }).catch(err => {
expect(err.message).to.equal('Oops!'); expect(err.message).to.equal('Oops!');
}); });
}); });
...@@ -137,7 +137,7 @@ describe(Support.getTestDialectTeaser('Hooks'), () => { ...@@ -137,7 +137,7 @@ describe(Support.getTestDialectTeaser('Hooks'), () => {
throw new Error('Oops!'); throw new Error('Oops!');
}); });
return this.User.findOne({where: {username: 'adam'}}).catch (err => { return this.User.findOne({ where: { username: 'adam' } }).catch(err => {
expect(err.message).to.equal('Oops!'); expect(err.message).to.equal('Oops!');
}); });
}); });
...@@ -147,7 +147,7 @@ describe(Support.getTestDialectTeaser('Hooks'), () => { ...@@ -147,7 +147,7 @@ describe(Support.getTestDialectTeaser('Hooks'), () => {
throw new Error('Oops!'); throw new Error('Oops!');
}); });
return this.User.findOne({where: {username: 'adam'}}).catch (err => { return this.User.findOne({ where: { username: 'adam' } }).catch(err => {
expect(err.message).to.equal('Oops!'); expect(err.message).to.equal('Oops!');
}); });
}); });
......
...@@ -47,7 +47,7 @@ describe(Support.getTestDialectTeaser('Hooks'), () => { ...@@ -47,7 +47,7 @@ describe(Support.getTestDialectTeaser('Hooks'), () => {
factory.options.name.singular = 'barr'; factory.options.name.singular = 'barr';
}); });
this.model = this.sequelize.define('foo', {name: DataTypes.STRING}); this.model = this.sequelize.define('foo', { name: DataTypes.STRING });
}); });
it('beforeDefine hook can change model name', function() { it('beforeDefine hook can change model name', function() {
...@@ -389,11 +389,11 @@ describe(Support.getTestDialectTeaser('Hooks'), () => { ...@@ -389,11 +389,11 @@ describe(Support.getTestDialectTeaser('Hooks'), () => {
this.User.addHook('beforeCreate', 'sasuke', sasukeHook); this.User.addHook('beforeCreate', 'sasuke', sasukeHook);
this.User.addHook('beforeCreate', 'naruto', narutoHook); this.User.addHook('beforeCreate', 'naruto', narutoHook);
return this.User.create({ username: 'makunouchi'}).then(() => { return this.User.create({ username: 'makunouchi' }).then(() => {
expect(sasukeHook).to.have.been.calledOnce; expect(sasukeHook).to.have.been.calledOnce;
expect(narutoHook).to.have.been.calledOnce; expect(narutoHook).to.have.been.calledOnce;
this.User.removeHook('beforeCreate', 'sasuke'); this.User.removeHook('beforeCreate', 'sasuke');
return this.User.create({ username: 'sendo'}); return this.User.create({ username: 'sendo' });
}).then(() => { }).then(() => {
expect(sasukeHook).to.have.been.calledOnce; expect(sasukeHook).to.have.been.calledOnce;
expect(narutoHook).to.have.been.calledTwice; expect(narutoHook).to.have.been.calledTwice;
...@@ -407,11 +407,11 @@ describe(Support.getTestDialectTeaser('Hooks'), () => { ...@@ -407,11 +407,11 @@ describe(Support.getTestDialectTeaser('Hooks'), () => {
this.User.addHook('beforeCreate', sasukeHook); this.User.addHook('beforeCreate', sasukeHook);
this.User.addHook('beforeCreate', narutoHook); this.User.addHook('beforeCreate', narutoHook);
return this.User.create({ username: 'makunouchi'}).then(() => { return this.User.create({ username: 'makunouchi' }).then(() => {
expect(sasukeHook).to.have.been.calledOnce; expect(sasukeHook).to.have.been.calledOnce;
expect(narutoHook).to.have.been.calledOnce; expect(narutoHook).to.have.been.calledOnce;
this.User.removeHook('beforeCreate', sasukeHook); this.User.removeHook('beforeCreate', sasukeHook);
return this.User.create({ username: 'sendo'}); return this.User.create({ username: 'sendo' });
}).then(() => { }).then(() => {
expect(sasukeHook).to.have.been.calledOnce; expect(sasukeHook).to.have.been.calledOnce;
expect(narutoHook).to.have.been.calledTwice; expect(narutoHook).to.have.been.calledTwice;
...@@ -425,11 +425,11 @@ describe(Support.getTestDialectTeaser('Hooks'), () => { ...@@ -425,11 +425,11 @@ describe(Support.getTestDialectTeaser('Hooks'), () => {
this.User.addHook('beforeSave', sasukeHook); this.User.addHook('beforeSave', sasukeHook);
this.User.addHook('beforeSave', narutoHook); this.User.addHook('beforeSave', narutoHook);
return this.User.create({ username: 'makunouchi'}).then(user => { return this.User.create({ username: 'makunouchi' }).then(user => {
expect(sasukeHook).to.have.been.calledOnce; expect(sasukeHook).to.have.been.calledOnce;
expect(narutoHook).to.have.been.calledOnce; expect(narutoHook).to.have.been.calledOnce;
this.User.removeHook('beforeSave', sasukeHook); this.User.removeHook('beforeSave', sasukeHook);
return user.update({ username: 'sendo'}); return user.update({ username: 'sendo' });
}).then(() => { }).then(() => {
expect(sasukeHook).to.have.been.calledOnce; expect(sasukeHook).to.have.been.calledOnce;
expect(narutoHook).to.have.been.calledTwice; expect(narutoHook).to.have.been.calledTwice;
......
...@@ -41,7 +41,7 @@ describe(Support.getTestDialectTeaser('Hooks'), () => { ...@@ -41,7 +41,7 @@ describe(Support.getTestDialectTeaser('Hooks'), () => {
this.ParanoidUser.beforeRestore(beforeHook); this.ParanoidUser.beforeRestore(beforeHook);
this.ParanoidUser.afterRestore(afterHook); this.ParanoidUser.afterRestore(afterHook);
return this.ParanoidUser.create({username: 'Toni', mood: 'happy'}).then(user => { return this.ParanoidUser.create({ username: 'Toni', mood: 'happy' }).then(user => {
return user.destroy().then(() => { return user.destroy().then(() => {
return user.restore().then(() => { return user.restore().then(() => {
expect(beforeHook).to.have.been.calledOnce; expect(beforeHook).to.have.been.calledOnce;
...@@ -63,7 +63,7 @@ describe(Support.getTestDialectTeaser('Hooks'), () => { ...@@ -63,7 +63,7 @@ describe(Support.getTestDialectTeaser('Hooks'), () => {
}); });
this.ParanoidUser.afterRestore(afterHook); this.ParanoidUser.afterRestore(afterHook);
return this.ParanoidUser.create({username: 'Toni', mood: 'happy'}).then(user => { return this.ParanoidUser.create({ username: 'Toni', mood: 'happy' }).then(user => {
return user.destroy().then(() => { return user.destroy().then(() => {
return expect(user.restore()).to.be.rejected.then(() => { return expect(user.restore()).to.be.rejected.then(() => {
expect(beforeHook).to.have.been.calledOnce; expect(beforeHook).to.have.been.calledOnce;
...@@ -83,7 +83,7 @@ describe(Support.getTestDialectTeaser('Hooks'), () => { ...@@ -83,7 +83,7 @@ describe(Support.getTestDialectTeaser('Hooks'), () => {
throw new Error('Whoops!'); throw new Error('Whoops!');
}); });
return this.ParanoidUser.create({username: 'Toni', mood: 'happy'}).then(user => { return this.ParanoidUser.create({ username: 'Toni', mood: 'happy' }).then(user => {
return user.destroy().then(() => { return user.destroy().then(() => {
return expect(user.restore()).to.be.rejected.then(() => { return expect(user.restore()).to.be.rejected.then(() => {
expect(beforeHook).to.have.been.calledOnce; expect(beforeHook).to.have.been.calledOnce;
......
...@@ -34,8 +34,8 @@ describe(Support.getTestDialectTeaser('Hooks'), () => { ...@@ -34,8 +34,8 @@ describe(Support.getTestDialectTeaser('Hooks'), () => {
this.User.beforeSave(beforeSave); this.User.beforeSave(beforeSave);
this.User.afterSave(afterSave); this.User.afterSave(afterSave);
return this.User.create({username: 'Toni', mood: 'happy'}).then(user => { return this.User.create({ username: 'Toni', mood: 'happy' }).then(user => {
return user.update({username: 'Chong'}).then(user => { return user.update({ username: 'Chong' }).then(user => {
expect(beforeHook).to.have.been.calledOnce; expect(beforeHook).to.have.been.calledOnce;
expect(afterHook).to.have.been.calledOnce; expect(afterHook).to.have.been.calledOnce;
expect(beforeSave).to.have.been.calledTwice; expect(beforeSave).to.have.been.calledTwice;
...@@ -61,8 +61,8 @@ describe(Support.getTestDialectTeaser('Hooks'), () => { ...@@ -61,8 +61,8 @@ describe(Support.getTestDialectTeaser('Hooks'), () => {
this.User.beforeSave(beforeSave); this.User.beforeSave(beforeSave);
this.User.afterSave(afterSave); this.User.afterSave(afterSave);
return this.User.create({username: 'Toni', mood: 'happy'}).then(user => { return this.User.create({ username: 'Toni', mood: 'happy' }).then(user => {
return expect(user.update({username: 'Chong'})).to.be.rejected.then(() => { return expect(user.update({ username: 'Chong' })).to.be.rejected.then(() => {
expect(beforeHook).to.have.been.calledOnce; expect(beforeHook).to.have.been.calledOnce;
expect(beforeSave).to.have.been.calledOnce; expect(beforeSave).to.have.been.calledOnce;
expect(afterHook).not.to.have.been.called; expect(afterHook).not.to.have.been.called;
...@@ -85,8 +85,8 @@ describe(Support.getTestDialectTeaser('Hooks'), () => { ...@@ -85,8 +85,8 @@ describe(Support.getTestDialectTeaser('Hooks'), () => {
this.User.beforeSave(beforeSave); this.User.beforeSave(beforeSave);
this.User.afterSave(afterSave); this.User.afterSave(afterSave);
return this.User.create({username: 'Toni', mood: 'happy'}).then(user => { return this.User.create({ username: 'Toni', mood: 'happy' }).then(user => {
return expect(user.update({username: 'Chong'})).to.be.rejected.then(() => { return expect(user.update({ username: 'Chong' })).to.be.rejected.then(() => {
expect(beforeHook).to.have.been.calledOnce; expect(beforeHook).to.have.been.calledOnce;
expect(afterHook).to.have.been.calledOnce; expect(afterHook).to.have.been.calledOnce;
expect(beforeSave).to.have.been.calledTwice; expect(beforeSave).to.have.been.calledTwice;
...@@ -103,8 +103,8 @@ describe(Support.getTestDialectTeaser('Hooks'), () => { ...@@ -103,8 +103,8 @@ describe(Support.getTestDialectTeaser('Hooks'), () => {
user.mood = 'happy'; user.mood = 'happy';
}); });
return this.User.create({username: 'fireninja', mood: 'invalid'}).then(user => { return this.User.create({ username: 'fireninja', mood: 'invalid' }).then(user => {
return user.update({username: 'hero'}); return user.update({ username: 'hero' });
}).then(user => { }).then(user => {
expect(user.username).to.equal('hero'); expect(user.username).to.equal('hero');
expect(user.mood).to.equal('happy'); expect(user.mood).to.equal('happy');
...@@ -117,8 +117,8 @@ describe(Support.getTestDialectTeaser('Hooks'), () => { ...@@ -117,8 +117,8 @@ describe(Support.getTestDialectTeaser('Hooks'), () => {
user.mood = 'sad'; user.mood = 'sad';
}); });
return this.User.create({username: 'fireninja', mood: 'nuetral'}).then(user => { return this.User.create({ username: 'fireninja', mood: 'nuetral' }).then(user => {
return user.update({username: 'spider'}); return user.update({ username: 'spider' });
}).then(user => { }).then(user => {
expect(user.username).to.equal('spider'); expect(user.username).to.equal('spider');
expect(user.mood).to.equal('sad'); expect(user.mood).to.equal('sad');
...@@ -133,8 +133,8 @@ describe(Support.getTestDialectTeaser('Hooks'), () => { ...@@ -133,8 +133,8 @@ describe(Support.getTestDialectTeaser('Hooks'), () => {
hookCalled++; hookCalled++;
}); });
return this.User.create({username: 'fireninja', mood: 'nuetral'}).then(user => { return this.User.create({ username: 'fireninja', mood: 'nuetral' }).then(user => {
return user.update({username: 'spider', mood: 'sad'}); return user.update({ username: 'spider', mood: 'sad' });
}).then(user => { }).then(user => {
expect(user.username).to.equal('spider'); expect(user.username).to.equal('spider');
expect(user.mood).to.equal('happy'); expect(user.mood).to.equal('happy');
...@@ -155,8 +155,8 @@ describe(Support.getTestDialectTeaser('Hooks'), () => { ...@@ -155,8 +155,8 @@ describe(Support.getTestDialectTeaser('Hooks'), () => {
hookCalled++; hookCalled++;
}); });
return this.User.create({username: 'akira'}).then(user => { return this.User.create({ username: 'akira' }).then(user => {
return user.update({username: 'spider', mood: 'sad'}); return user.update({ username: 'spider', mood: 'sad' });
}).then(user => { }).then(user => {
expect(user.mood).to.equal('happy'); expect(user.mood).to.equal('happy');
expect(user.username).to.equal('spider'); expect(user.username).to.equal('spider');
......
...@@ -32,7 +32,7 @@ if (Support.sequelize.dialect.supports.upserts) { ...@@ -32,7 +32,7 @@ if (Support.sequelize.dialect.supports.upserts) {
this.User.beforeUpsert(beforeHook); this.User.beforeUpsert(beforeHook);
this.User.afterUpsert(afterHook); this.User.afterUpsert(afterHook);
return this.User.upsert({username: 'Toni', mood: 'happy'}).then(() => { return this.User.upsert({ username: 'Toni', mood: 'happy' }).then(() => {
expect(beforeHook).to.have.been.calledOnce; expect(beforeHook).to.have.been.calledOnce;
expect(afterHook).to.have.been.calledOnce; expect(afterHook).to.have.been.calledOnce;
}); });
...@@ -50,7 +50,7 @@ if (Support.sequelize.dialect.supports.upserts) { ...@@ -50,7 +50,7 @@ if (Support.sequelize.dialect.supports.upserts) {
}); });
this.User.afterUpsert(afterHook); this.User.afterUpsert(afterHook);
return expect(this.User.upsert({username: 'Toni', mood: 'happy'})).to.be.rejected.then(() => { return expect(this.User.upsert({ username: 'Toni', mood: 'happy' })).to.be.rejected.then(() => {
expect(beforeHook).to.have.been.calledOnce; expect(beforeHook).to.have.been.calledOnce;
expect(afterHook).not.to.have.been.called; expect(afterHook).not.to.have.been.called;
}); });
...@@ -66,7 +66,7 @@ if (Support.sequelize.dialect.supports.upserts) { ...@@ -66,7 +66,7 @@ if (Support.sequelize.dialect.supports.upserts) {
throw new Error('Whoops!'); throw new Error('Whoops!');
}); });
return expect(this.User.upsert({username: 'Toni', mood: 'happy'})).to.be.rejected.then(() => { return expect(this.User.upsert({ username: 'Toni', mood: 'happy' })).to.be.rejected.then(() => {
expect(beforeHook).to.have.been.calledOnce; expect(beforeHook).to.have.been.calledOnce;
expect(afterHook).to.have.been.calledOnce; expect(afterHook).to.have.been.calledOnce;
}); });
......
...@@ -33,7 +33,7 @@ describe(Support.getTestDialectTeaser('Hooks'), () => { ...@@ -33,7 +33,7 @@ describe(Support.getTestDialectTeaser('Hooks'), () => {
user.username = 'Toni'; user.username = 'Toni';
}); });
return this.User.create({mood: 'ecstatic'}).then(user => { return this.User.create({ mood: 'ecstatic' }).then(user => {
expect(user.mood).to.equal('happy'); expect(user.mood).to.equal('happy');
expect(user.username).to.equal('Toni'); expect(user.username).to.equal('Toni');
}); });
...@@ -56,7 +56,7 @@ describe(Support.getTestDialectTeaser('Hooks'), () => { ...@@ -56,7 +56,7 @@ describe(Support.getTestDialectTeaser('Hooks'), () => {
}); });
return this.User.create({username: 'T', mood: 'neutral'}).then(user => { return this.User.create({ username: 'T', mood: 'neutral' }).then(user => {
expect(user.mood).to.equal('neutral'); expect(user.mood).to.equal('neutral');
expect(user.username).to.equal('Samorost 3'); expect(user.username).to.equal('Samorost 3');
...@@ -113,7 +113,7 @@ describe(Support.getTestDialectTeaser('Hooks'), () => { ...@@ -113,7 +113,7 @@ describe(Support.getTestDialectTeaser('Hooks'), () => {
throw new Error('Whoops! Changed user.mood!'); throw new Error('Whoops! Changed user.mood!');
}); });
return expect(this.User.create({username: 'Toni', mood: 'happy'})).to.be.rejectedWith('Whoops! Changed user.mood!'); return expect(this.User.create({ username: 'Toni', mood: 'happy' })).to.be.rejectedWith('Whoops! Changed user.mood!');
}); });
it('should call validationFailed hook', function() { it('should call validationFailed hook', function() {
...@@ -121,7 +121,7 @@ describe(Support.getTestDialectTeaser('Hooks'), () => { ...@@ -121,7 +121,7 @@ describe(Support.getTestDialectTeaser('Hooks'), () => {
this.User.validationFailed(validationFailedHook); this.User.validationFailed(validationFailedHook);
return expect(this.User.create({mood: 'happy'})).to.be.rejected.then(() => { return expect(this.User.create({ mood: 'happy' })).to.be.rejected.then(() => {
expect(validationFailedHook).to.have.been.calledOnce; expect(validationFailedHook).to.have.been.calledOnce;
}); });
}); });
...@@ -131,7 +131,7 @@ describe(Support.getTestDialectTeaser('Hooks'), () => { ...@@ -131,7 +131,7 @@ describe(Support.getTestDialectTeaser('Hooks'), () => {
this.User.validationFailed(validationFailedHook); this.User.validationFailed(validationFailedHook);
return expect(this.User.create({mood: 'happy'})).to.be.rejected.then(err => { return expect(this.User.create({ mood: 'happy' })).to.be.rejected.then(err => {
expect(err.name).to.equal('SequelizeValidationError'); expect(err.name).to.equal('SequelizeValidationError');
}); });
}); });
...@@ -141,7 +141,7 @@ describe(Support.getTestDialectTeaser('Hooks'), () => { ...@@ -141,7 +141,7 @@ describe(Support.getTestDialectTeaser('Hooks'), () => {
this.User.validationFailed(validationFailedHook); this.User.validationFailed(validationFailedHook);
return expect(this.User.create({mood: 'happy'})).to.be.rejected.then(err => { return expect(this.User.create({ mood: 'happy' })).to.be.rejected.then(err => {
expect(err.message).to.equal('Whoops!'); expect(err.message).to.equal('Whoops!');
}); });
}); });
......
...@@ -34,7 +34,7 @@ describe(Support.getTestDialectTeaser('Include'), () => { ...@@ -34,7 +34,7 @@ describe(Support.getTestDialectTeaser('Include'), () => {
// Create an enviroment // Create an enviroment
return Promise.join( return Promise.join(
Project.bulkCreate([ Project.bulkCreate([
{ id: 1, name: 'No tasks'}, { id: 1, name: 'No tasks' },
{ id: 2, name: 'No tasks no employees' }, { id: 2, name: 'No tasks no employees' },
{ id: 3, name: 'No employees' }, { id: 3, name: 'No employees' },
{ id: 4, name: 'In progress A' }, { id: 4, name: 'In progress A' },
...@@ -42,16 +42,16 @@ describe(Support.getTestDialectTeaser('Include'), () => { ...@@ -42,16 +42,16 @@ describe(Support.getTestDialectTeaser('Include'), () => {
{ id: 6, name: 'In progress C' } { id: 6, name: 'In progress C' }
]), ]),
Task.bulkCreate([ Task.bulkCreate([
{ name: 'Important task', fk: 3}, { name: 'Important task', fk: 3 },
{ name: 'Important task', fk: 4}, { name: 'Important task', fk: 4 },
{ name: 'Important task', fk: 5}, { name: 'Important task', fk: 5 },
{ name: 'Important task', fk: 6} { name: 'Important task', fk: 6 }
]), ]),
Employee.bulkCreate([ Employee.bulkCreate([
{ name: 'Jane Doe', fk: 1}, { name: 'Jane Doe', fk: 1 },
{ name: 'John Doe', fk: 4}, { name: 'John Doe', fk: 4 },
{ name: 'Jane John Doe', fk: 5}, { name: 'Jane John Doe', fk: 5 },
{ name: 'John Jane Doe', fk: 6} { name: 'John Jane Doe', fk: 6 }
]) ])
).then(() =>{ ).then(() =>{
//Find all projects with tasks and employees //Find all projects with tasks and employees
...@@ -150,11 +150,11 @@ describe(Support.getTestDialectTeaser('Include'), () => { ...@@ -150,11 +150,11 @@ describe(Support.getTestDialectTeaser('Include'), () => {
]) ])
).then(() => { ).then(() => {
// Delete some of conns to prove the concept // Delete some of conns to prove the concept
return SomeConnection.destroy({where: { return SomeConnection.destroy({ where: {
m: 'A', m: 'A',
u: 1, u: 1,
fk: [1, 2] fk: [1, 2]
}}).then(() => { } }).then(() => {
this.clock.tick(1000); this.clock.tick(1000);
// Last and most important queries ( we connected 4, but deleted 2, witch means we must get 2 only ) // Last and most important queries ( we connected 4, but deleted 2, witch means we must get 2 only )
return A.findAndCountAll({ return A.findAndCountAll({
...@@ -178,7 +178,7 @@ describe(Support.getTestDialectTeaser('Include'), () => { ...@@ -178,7 +178,7 @@ describe(Support.getTestDialectTeaser('Include'), () => {
it('should count on a where and not use an uneeded include', function() { it('should count on a where and not use an uneeded include', function() {
const Project = this.sequelize.define('Project', { const Project = this.sequelize.define('Project', {
id: { type: DataTypes.INTEGER, allowNull: false, primaryKey: true, autoIncrement: true }, id: { type: DataTypes.INTEGER, allowNull: false, primaryKey: true, autoIncrement: true },
project_name: { type: DataTypes.STRING} project_name: { type: DataTypes.STRING }
}); });
const User = this.sequelize.define('User', { const User = this.sequelize.define('User', {
...@@ -190,8 +190,8 @@ describe(Support.getTestDialectTeaser('Include'), () => { ...@@ -190,8 +190,8 @@ describe(Support.getTestDialectTeaser('Include'), () => {
let userId = null; let userId = null;
return User.sync({force: true}).then(() => { return User.sync({ force: true }).then(() => {
return Project.sync({force: true}); return Project.sync({ force: true });
}).then(() => { }).then(() => {
return Promise.all([User.create(), Project.create(), Project.create(), Project.create()]); return Promise.all([User.create(), Project.create(), Project.create(), Project.create()]);
}).then(results => { }).then(results => {
...@@ -200,7 +200,7 @@ describe(Support.getTestDialectTeaser('Include'), () => { ...@@ -200,7 +200,7 @@ describe(Support.getTestDialectTeaser('Include'), () => {
return user.setProjects([results[1], results[2], results[3]]); return user.setProjects([results[1], results[2], results[3]]);
}).then(() => { }).then(() => {
return User.findAndCountAll({ return User.findAndCountAll({
where: {id: userId}, where: { id: userId },
include: [Project], include: [Project],
distinct: true distinct: true
}); });
...@@ -221,10 +221,10 @@ describe(Support.getTestDialectTeaser('Include'), () => { ...@@ -221,10 +221,10 @@ describe(Support.getTestDialectTeaser('Include'), () => {
return s.sync({ force: true }).then(() => { return s.sync({ force: true }).then(() => {
// Make five instances of Foo // Make five instances of Foo
return Foo.bulkCreate([{id: 1}, {id: 2}, {id: 3}, {id: 4}, {id: 5}]); return Foo.bulkCreate([{ id: 1 }, { id: 2 }, { id: 3 }, { id: 4 }, { id: 5 }]);
}).then(() => { }).then(() => {
// Make four instances of Bar, related to the last four instances of Foo // Make four instances of Bar, related to the last four instances of Foo
return Bar.bulkCreate([{'FooId': 2}, {'FooId': 3}, {'FooId': 4}, {'FooId': 5}]); return Bar.bulkCreate([{ 'FooId': 2 }, { 'FooId': 3 }, { 'FooId': 4 }, { 'FooId': 5 }]);
}).then(() => { }).then(() => {
// Query for the first two instances of Foo which have related Bars // Query for the first two instances of Foo which have related Bars
return Foo.findAndCountAll({ return Foo.findAndCountAll({
...@@ -249,16 +249,16 @@ describe(Support.getTestDialectTeaser('Include'), () => { ...@@ -249,16 +249,16 @@ describe(Support.getTestDialectTeaser('Include'), () => {
it('should return the correct count and rows when using a required belongsTo with a where condition and a limit', function() { it('should return the correct count and rows when using a required belongsTo with a where condition and a limit', function() {
const Foo = this.sequelize.define('Foo', {}), const Foo = this.sequelize.define('Foo', {}),
Bar = this.sequelize.define('Bar', {m: DataTypes.STRING(40)}); Bar = this.sequelize.define('Bar', { m: DataTypes.STRING(40) });
Foo.hasMany(Bar); Foo.hasMany(Bar);
Bar.belongsTo(Foo); Bar.belongsTo(Foo);
return this.sequelize.sync({ force: true }).then(() => { return this.sequelize.sync({ force: true }).then(() => {
return Foo.bulkCreate([{id: 1}, {id: 2}, {id: 3}, {id: 4}, {id: 5}]); return Foo.bulkCreate([{ id: 1 }, { id: 2 }, { id: 3 }, { id: 4 }, { id: 5 }]);
}).then(() => { }).then(() => {
// Make four instances of Bar, related to the first two instances of Foo // Make four instances of Bar, related to the first two instances of Foo
return Bar.bulkCreate([{'FooId': 1, m: 'yes'}, {'FooId': 1, m: 'yes'}, {'FooId': 1, m: 'no'}, {'FooId': 2, m: 'yes'}]); return Bar.bulkCreate([{ 'FooId': 1, m: 'yes' }, { 'FooId': 1, m: 'yes' }, { 'FooId': 1, m: 'no' }, { 'FooId': 2, m: 'yes' }]);
}).then(() => { }).then(() => {
// Query for the first instance of Foo which have related Bars with m === 'yes' // Query for the first instance of Foo which have related Bars with m === 'yes'
return Foo.findAndCountAll({ return Foo.findAndCountAll({
...@@ -278,21 +278,21 @@ describe(Support.getTestDialectTeaser('Include'), () => { ...@@ -278,21 +278,21 @@ describe(Support.getTestDialectTeaser('Include'), () => {
it('should correctly filter, limit and sort when multiple includes and types of associations are present.', function() { it('should correctly filter, limit and sort when multiple includes and types of associations are present.', function() {
const TaskTag = this.sequelize.define('TaskTag', { const TaskTag = this.sequelize.define('TaskTag', {
id: { type: DataTypes.INTEGER, allowNull: false, primaryKey: true, autoIncrement: true }, id: { type: DataTypes.INTEGER, allowNull: false, primaryKey: true, autoIncrement: true },
name: { type: DataTypes.STRING} name: { type: DataTypes.STRING }
}); });
const Tag = this.sequelize.define('Tag', { const Tag = this.sequelize.define('Tag', {
id: { type: DataTypes.INTEGER, allowNull: false, primaryKey: true, autoIncrement: true }, id: { type: DataTypes.INTEGER, allowNull: false, primaryKey: true, autoIncrement: true },
name: { type: DataTypes.STRING} name: { type: DataTypes.STRING }
}); });
const Task = this.sequelize.define('Task', { const Task = this.sequelize.define('Task', {
id: { type: DataTypes.INTEGER, allowNull: false, primaryKey: true, autoIncrement: true }, id: { type: DataTypes.INTEGER, allowNull: false, primaryKey: true, autoIncrement: true },
name: { type: DataTypes.STRING} name: { type: DataTypes.STRING }
}); });
const Project = this.sequelize.define('Project', { const Project = this.sequelize.define('Project', {
id: { type: DataTypes.INTEGER, allowNull: false, primaryKey: true, autoIncrement: true }, id: { type: DataTypes.INTEGER, allowNull: false, primaryKey: true, autoIncrement: true },
m: { type: DataTypes.STRING} m: { type: DataTypes.STRING }
}); });
const User = this.sequelize.define('User', { const User = this.sequelize.define('User', {
...@@ -302,7 +302,7 @@ describe(Support.getTestDialectTeaser('Include'), () => { ...@@ -302,7 +302,7 @@ describe(Support.getTestDialectTeaser('Include'), () => {
Project.belongsTo(User); Project.belongsTo(User);
Task.belongsTo(Project); Task.belongsTo(Project);
Task.belongsToMany(Tag, {through: TaskTag}); Task.belongsToMany(Tag, { through: TaskTag });
// Sync them // Sync them
return this.sequelize.sync({ force: true }).then(() => { return this.sequelize.sync({ force: true }).then(() => {
// Create an enviroment // Create an enviroment
...@@ -311,8 +311,8 @@ describe(Support.getTestDialectTeaser('Include'), () => { ...@@ -311,8 +311,8 @@ describe(Support.getTestDialectTeaser('Include'), () => {
{ name: 'user-name-2' } { name: 'user-name-2' }
]).then(() => { ]).then(() => {
return Project.bulkCreate([ return Project.bulkCreate([
{ m: 'A', UserId: 1}, { m: 'A', UserId: 1 },
{ m: 'A', UserId: 2} { m: 'A', UserId: 2 }
]); ]);
}).then(() => { }).then(() => {
return Task.bulkCreate([ return Task.bulkCreate([
...@@ -358,7 +358,7 @@ describe(Support.getTestDialectTeaser('Include'), () => { ...@@ -358,7 +358,7 @@ describe(Support.getTestDialectTeaser('Include'), () => {
const Project = this.sequelize.define('Project', { const Project = this.sequelize.define('Project', {
id: { type: DataTypes.INTEGER, allowNull: false, primaryKey: true, autoIncrement: true }, id: { type: DataTypes.INTEGER, allowNull: false, primaryKey: true, autoIncrement: true },
name: { type: DataTypes.STRING} name: { type: DataTypes.STRING }
}); });
User.hasMany(Project); User.hasMany(Project);
...@@ -371,9 +371,9 @@ describe(Support.getTestDialectTeaser('Include'), () => { ...@@ -371,9 +371,9 @@ describe(Support.getTestDialectTeaser('Include'), () => {
]); ]);
}).then(() => { }).then(() => {
return Project.bulkCreate([ return Project.bulkCreate([
{ name: 'naam-satya', UserId: 1}, { name: 'naam-satya', UserId: 1 },
{ name: 'guru-satya', UserId: 2}, { name: 'guru-satya', UserId: 2 },
{ name: 'app-satya', UserId: 2} { name: 'app-satya', UserId: 2 }
]); ]);
}).then(() => { }).then(() => {
return User.findAndCountAll({ return User.findAndCountAll({
...@@ -389,7 +389,7 @@ describe(Support.getTestDialectTeaser('Include'), () => { ...@@ -389,7 +389,7 @@ describe(Support.getTestDialectTeaser('Include'), () => {
required: true, required: true,
where: { name: { where: { name: {
[Op.in]: ['naam-satya', 'guru-satya'] [Op.in]: ['naam-satya', 'guru-satya']
}} } }
} }
] ]
}); });
......
...@@ -36,7 +36,7 @@ describe(Support.getTestDialectTeaser('Include'), () => { ...@@ -36,7 +36,7 @@ describe(Support.getTestDialectTeaser('Include'), () => {
{ model: B, required: false, include: [ { model: B, required: false, include: [
{ model: C, required: false }, { model: C, required: false },
{ model: D } { model: D }
]} ] }
] ]
}); });
}); });
...@@ -45,7 +45,7 @@ describe(Support.getTestDialectTeaser('Include'), () => { ...@@ -45,7 +45,7 @@ describe(Support.getTestDialectTeaser('Include'), () => {
it('should work with a 1:M to M:1 relation with a where on the last include', function() { it('should work with a 1:M to M:1 relation with a where on the last include', function() {
const Model = this.sequelize.define('Model', {}); const Model = this.sequelize.define('Model', {});
const Model2 = this.sequelize.define('Model2', {}); const Model2 = this.sequelize.define('Model2', {});
const Model4 = this.sequelize.define('Model4', {something: { type: DataTypes.INTEGER }}); const Model4 = this.sequelize.define('Model4', { something: { type: DataTypes.INTEGER } });
Model.belongsTo(Model2); Model.belongsTo(Model2);
Model2.hasMany(Model); Model2.hasMany(Model);
...@@ -53,12 +53,12 @@ describe(Support.getTestDialectTeaser('Include'), () => { ...@@ -53,12 +53,12 @@ describe(Support.getTestDialectTeaser('Include'), () => {
Model2.hasMany(Model4); Model2.hasMany(Model4);
Model4.belongsTo(Model2); Model4.belongsTo(Model2);
return this.sequelize.sync({force: true}).then(() => { return this.sequelize.sync({ force: true }).then(() => {
return Model.findOne({ return Model.findOne({
include: [ include: [
{model: Model2, include: [ { model: Model2, include: [
{model: Model4, where: {something: 2}} { model: Model4, where: { something: 2 } }
]} ] }
] ]
}); });
}); });
...@@ -72,8 +72,8 @@ describe(Support.getTestDialectTeaser('Include'), () => { ...@@ -72,8 +72,8 @@ describe(Support.getTestDialectTeaser('Include'), () => {
} }
}, { paranoid: false }); }, { paranoid: false });
User.hasMany(Task, {foreignKey: 'userId'}); User.hasMany(Task, { foreignKey: 'userId' });
Task.belongsTo(User, {foreignKey: 'userId'}); Task.belongsTo(User, { foreignKey: 'userId' });
return this.sequelize.sync({ return this.sequelize.sync({
force: true force: true
...@@ -81,14 +81,14 @@ describe(Support.getTestDialectTeaser('Include'), () => { ...@@ -81,14 +81,14 @@ describe(Support.getTestDialectTeaser('Include'), () => {
return User.create(); return User.create();
}).then(user => { }).then(user => {
return Task.bulkCreate([ return Task.bulkCreate([
{userId: user.get('id'), deletedAt: new Date()}, { userId: user.get('id'), deletedAt: new Date() },
{userId: user.get('id'), deletedAt: new Date()}, { userId: user.get('id'), deletedAt: new Date() },
{userId: user.get('id'), deletedAt: new Date()} { userId: user.get('id'), deletedAt: new Date() }
]); ]);
}).then(() => { }).then(() => {
return User.findOne({ return User.findOne({
include: [ include: [
{model: Task, where: {deletedAt: null}, required: false} { model: Task, where: { deletedAt: null }, required: false }
] ]
}); });
}).then(user => { }).then(user => {
...@@ -110,8 +110,8 @@ describe(Support.getTestDialectTeaser('Include'), () => { ...@@ -110,8 +110,8 @@ describe(Support.getTestDialectTeaser('Include'), () => {
searchString: { type: DataTypes.STRING } searchString: { type: DataTypes.STRING }
}); });
User.hasMany(Task, {foreignKey: 'userId'}); User.hasMany(Task, { foreignKey: 'userId' });
Task.belongsTo(User, {foreignKey: 'userId'}); Task.belongsTo(User, { foreignKey: 'userId' });
return this.sequelize.sync({ return this.sequelize.sync({
force: true force: true
...@@ -119,13 +119,13 @@ describe(Support.getTestDialectTeaser('Include'), () => { ...@@ -119,13 +119,13 @@ describe(Support.getTestDialectTeaser('Include'), () => {
return User.create(); return User.create();
}).then(user => { }).then(user => {
return Task.bulkCreate([ return Task.bulkCreate([
{userId: user.get('id'), searchString: 'one'}, { userId: user.get('id'), searchString: 'one' },
{userId: user.get('id'), searchString: 'two'} { userId: user.get('id'), searchString: 'two' }
]); ]);
}).then(() => { }).then(() => {
return User.findOne({ return User.findOne({
include: [ include: [
{model: Task, where: {searchString: 'one'} } { model: Task, where: { searchString: 'one' } }
] ]
}); });
}).then(user => { }).then(user => {
...@@ -149,7 +149,7 @@ describe(Support.getTestDialectTeaser('Include'), () => { ...@@ -149,7 +149,7 @@ describe(Support.getTestDialectTeaser('Include'), () => {
B.belongsToMany(A, { through: AB }); B.belongsToMany(A, { through: AB });
return this.sequelize return this.sequelize
.sync({force: true}) .sync({ force: true })
.then(() => { .then(() => {
return Promise.join( return Promise.join(
A.create({}), A.create({}),
...@@ -157,12 +157,12 @@ describe(Support.getTestDialectTeaser('Include'), () => { ...@@ -157,12 +157,12 @@ describe(Support.getTestDialectTeaser('Include'), () => {
); );
}) })
.then(([a, b]) => { .then(([a, b]) => {
return a.addB(b, { through: {name: 'Foobar'}}); return a.addB(b, { through: { name: 'Foobar' } });
}) })
.then(() => { .then(() => {
return A.findOne({ return A.findOne({
include: [ include: [
{model: B, through: { where: {name: 'Foobar'} }, required: true } { model: B, through: { where: { name: 'Foobar' } }, required: true }
] ]
}); });
}) })
...@@ -181,11 +181,11 @@ describe(Support.getTestDialectTeaser('Include'), () => { ...@@ -181,11 +181,11 @@ describe(Support.getTestDialectTeaser('Include'), () => {
name: DataTypes.STRING(40) name: DataTypes.STRING(40)
}); });
A.belongsToMany(B, {through: 'a_b'}); A.belongsToMany(B, { through: 'a_b' });
B.belongsToMany(A, {through: 'a_b'}); B.belongsToMany(A, { through: 'a_b' });
return this.sequelize return this.sequelize
.sync({force: true}) .sync({ force: true })
.then(() => { .then(() => {
return A.create({ return A.create({
name: 'Foobar' name: 'Foobar'
...@@ -193,9 +193,9 @@ describe(Support.getTestDialectTeaser('Include'), () => { ...@@ -193,9 +193,9 @@ describe(Support.getTestDialectTeaser('Include'), () => {
}) })
.then(() => { .then(() => {
return A.findOne({ return A.findOne({
where: {name: 'Foobar'}, where: { name: 'Foobar' },
include: [ include: [
{model: B, where: {name: 'idontexist'}, required: false} { model: B, where: { name: 'idontexist' }, required: false }
] ]
}); });
}) })
...@@ -250,7 +250,7 @@ describe(Support.getTestDialectTeaser('Include'), () => { ...@@ -250,7 +250,7 @@ describe(Support.getTestDialectTeaser('Include'), () => {
const User = this.sequelize.define('User', { username: DataTypes.STRING }), const User = this.sequelize.define('User', { username: DataTypes.STRING }),
Task = this.sequelize.define('Task', { title: DataTypes.STRING }); Task = this.sequelize.define('Task', { title: DataTypes.STRING });
User.removeAttribute('id'); User.removeAttribute('id');
Task.belongsTo(User, { foreignKey: 'user_name', targetKey: 'username'}); Task.belongsTo(User, { foreignKey: 'user_name', targetKey: 'username' });
return this.sequelize.sync({ force: true }).then(() => { return this.sequelize.sync({ force: true }).then(() => {
return User.create({ username: 'bob' }).then(newUser => { return User.create({ username: 'bob' }).then(newUser => {
...@@ -292,7 +292,7 @@ describe(Support.getTestDialectTeaser('Include'), () => { ...@@ -292,7 +292,7 @@ describe(Support.getTestDialectTeaser('Include'), () => {
F.belongsTo(G); F.belongsTo(G);
G.belongsTo(H); G.belongsTo(H);
return this.sequelize.sync({force: true}).then(() => { return this.sequelize.sync({ force: true }).then(() => {
return Promise.join( return Promise.join(
A.create({}), A.create({}),
(function(singles) { (function(singles) {
...@@ -330,21 +330,21 @@ describe(Support.getTestDialectTeaser('Include'), () => { ...@@ -330,21 +330,21 @@ describe(Support.getTestDialectTeaser('Include'), () => {
}).then(() => { }).then(() => {
return A.findOne({ return A.findOne({
include: [ include: [
{model: B, include: [ { model: B, include: [
{model: C, include: [ { model: C, include: [
{model: D, include: [ { model: D, include: [
{model: E, include: [ { model: E, include: [
{model: F, include: [ { model: F, include: [
{model: G, where: { { model: G, where: {
name: 'yolo' name: 'yolo'
}, include: [ }, include: [
{model: H} { model: H }
]} ] }
]} ] }
]} ] }
]} ] }
]} ] }
]} ] }
] ]
}).then(a => { }).then(a => {
expect(a.b.c.d.e.f.g.h).to.be.ok; expect(a.b.c.d.e.f.g.h).to.be.ok;
...@@ -369,11 +369,11 @@ describe(Support.getTestDialectTeaser('Include'), () => { ...@@ -369,11 +369,11 @@ describe(Support.getTestDialectTeaser('Include'), () => {
User.hasMany(Post, { foreignKey: 'owner_id', scope: { owner_type: 'user' }, as: 'UserPosts', constraints: false }); User.hasMany(Post, { foreignKey: 'owner_id', scope: { owner_type: 'user' }, as: 'UserPosts', constraints: false });
Post.belongsTo(User, { foreignKey: 'owner_id', as: 'Owner', constraints: false }); Post.belongsTo(User, { foreignKey: 'owner_id', as: 'Owner', constraints: false });
return this.sequelize.sync({force: true}).then(() => { return this.sequelize.sync({ force: true }).then(() => {
return User.findOne({ return User.findOne({
where: { id: 2 }, where: { id: 2 },
include: [ include: [
{ model: Post, as: 'UserPosts', where: {'private': true} } { model: Post, as: 'UserPosts', where: { 'private': true } }
] ]
}); });
}); });
......
...@@ -15,7 +15,7 @@ describe(Support.getTestDialectTeaser('Include'), () => { ...@@ -15,7 +15,7 @@ describe(Support.getTestDialectTeaser('Include'), () => {
* shortcut for building simple {name: 'foo'} seed data * shortcut for building simple {name: 'foo'} seed data
*/ */
function build() { function build() {
return Array.prototype.slice.call(arguments).map(arg => ({name: arg})); return Array.prototype.slice.call(arguments).map(arg => ({ name: arg }));
} }
/* /*
...@@ -40,78 +40,78 @@ describe(Support.getTestDialectTeaser('Include'), () => { ...@@ -40,78 +40,78 @@ describe(Support.getTestDialectTeaser('Include'), () => {
type: DataTypes.STRING, type: DataTypes.STRING,
primaryKey: true primaryKey: true
} }
}, {timestamps: false}); }, { timestamps: false });
this.User = this.sequelize.define('User', { this.User = this.sequelize.define('User', {
name: { name: {
type: DataTypes.STRING, type: DataTypes.STRING,
primaryKey: true primaryKey: true
} }
}, {timestamps: false}); }, { timestamps: false });
this.Task = this.sequelize.define('Task', { this.Task = this.sequelize.define('Task', {
name: { name: {
type: DataTypes.STRING, type: DataTypes.STRING,
primaryKey: true primaryKey: true
} }
}, {timestamps: false}); }, { timestamps: false });
this.Hobby = this.sequelize.define('Hobby', { this.Hobby = this.sequelize.define('Hobby', {
name: { name: {
type: DataTypes.STRING, type: DataTypes.STRING,
primaryKey: true primaryKey: true
} }
}, {timestamps: false}); }, { timestamps: false });
this.User.belongsToMany(this.Project, {through: 'user_project'}); this.User.belongsToMany(this.Project, { through: 'user_project' });
this.Project.belongsToMany(this.User, {through: 'user_project'}); this.Project.belongsToMany(this.User, { through: 'user_project' });
this.Project.belongsToMany(this.Task, {through: 'task_project'}); this.Project.belongsToMany(this.Task, { through: 'task_project' });
this.Task.belongsToMany(this.Project, {through: 'task_project'}); this.Task.belongsToMany(this.Project, { through: 'task_project' });
this.User.belongsToMany(this.Hobby, {through: 'user_hobby'}); this.User.belongsToMany(this.Hobby, { through: 'user_hobby' });
this.Hobby.belongsToMany(this.User, {through: 'user_hobby'}); this.Hobby.belongsToMany(this.User, { through: 'user_hobby' });
this.Post = this.sequelize.define('Post', { this.Post = this.sequelize.define('Post', {
name: { name: {
type: DataTypes.STRING, type: DataTypes.STRING,
primaryKey: true primaryKey: true
} }
}, {timestamps: false}); }, { timestamps: false });
this.Comment = this.sequelize.define('Comment', { this.Comment = this.sequelize.define('Comment', {
name: { name: {
type: DataTypes.STRING, type: DataTypes.STRING,
primaryKey: true primaryKey: true
} }
}, {timestamps: false}); }, { timestamps: false });
this.Tag = this.sequelize.define('Tag', { this.Tag = this.sequelize.define('Tag', {
name: { name: {
type: DataTypes.STRING, type: DataTypes.STRING,
primaryKey: true primaryKey: true
} }
}, {timestamps: false}); }, { timestamps: false });
this.Color = this.sequelize.define('Color', { this.Color = this.sequelize.define('Color', {
name: { name: {
type: DataTypes.STRING, type: DataTypes.STRING,
primaryKey: true primaryKey: true
} }
}, {timestamps: false}); }, { timestamps: false });
this.Footnote = this.sequelize.define('Footnote', { this.Footnote = this.sequelize.define('Footnote', {
name: { name: {
type: DataTypes.STRING, type: DataTypes.STRING,
primaryKey: true primaryKey: true
} }
}, {timestamps: false}); }, { timestamps: false });
this.Post.hasMany(this.Comment); this.Post.hasMany(this.Comment);
this.Comment.belongsTo(this.Post); this.Comment.belongsTo(this.Post);
this.Post.belongsToMany(this.Tag, {through: 'post_tag'}); this.Post.belongsToMany(this.Tag, { through: 'post_tag' });
this.Tag.belongsToMany(this.Post, {through: 'post_tag'}); this.Tag.belongsToMany(this.Post, { through: 'post_tag' });
this.Post.hasMany(this.Footnote); this.Post.hasMany(this.Footnote);
this.Footnote.belongsTo(this.Post); this.Footnote.belongsTo(this.Post);
......
...@@ -19,7 +19,7 @@ describe(Support.getTestDialectTeaser('Paranoid'), () => { ...@@ -19,7 +19,7 @@ describe(Support.getTestDialectTeaser('Paranoid'), () => {
D = this.D = S.define('D', { name: DT.STRING }, { paranoid: true }); D = this.D = S.define('D', { name: DT.STRING }, { paranoid: true });
A.belongsTo(B); A.belongsTo(B);
A.belongsToMany(D, {through: 'a_d'}); A.belongsToMany(D, { through: 'a_d' });
A.hasMany(C); A.hasMany(C);
B.hasMany(A); B.hasMany(A);
...@@ -28,7 +28,7 @@ describe(Support.getTestDialectTeaser('Paranoid'), () => { ...@@ -28,7 +28,7 @@ describe(Support.getTestDialectTeaser('Paranoid'), () => {
C.belongsTo(A); C.belongsTo(A);
C.belongsTo(B); C.belongsTo(B);
D.belongsToMany(A, {through: 'a_d'}); D.belongsToMany(A, { through: 'a_d' });
return S.sync({ force: true }); return S.sync({ force: true });
}); });
...@@ -105,7 +105,7 @@ describe(Support.getTestDialectTeaser('Paranoid'), () => { ...@@ -105,7 +105,7 @@ describe(Support.getTestDialectTeaser('Paranoid'), () => {
X.hasMany(Y); X.hasMany(Y);
return this.sequelize.sync({ force: true}).then(() => { return this.sequelize.sync({ force: true }).then(() => {
return Sequelize.Promise.all([ return Sequelize.Promise.all([
X.create(), X.create(),
Y.create() Y.create()
......
...@@ -18,9 +18,9 @@ if (current.dialect.supports.groupedLimit) { ...@@ -18,9 +18,9 @@ if (current.dialect.supports.groupedLimit) {
Task = this.sequelize.define('Task', {}), Task = this.sequelize.define('Task', {}),
sqlSpy = sinon.spy(); sqlSpy = sinon.spy();
User.Tasks = User.hasMany(Task, {as: 'tasks'}); User.Tasks = User.hasMany(Task, { as: 'tasks' });
return this.sequelize.sync({force: true}).then(() => { return this.sequelize.sync({ force: true }).then(() => {
return Promise.join( return Promise.join(
User.create({ User.create({
id: 1, id: 1,
...@@ -43,7 +43,7 @@ if (current.dialect.supports.groupedLimit) { ...@@ -43,7 +43,7 @@ if (current.dialect.supports.groupedLimit) {
).then(() => { ).then(() => {
return User.findAll({ return User.findAll({
include: [ include: [
{association: User.Tasks, separate: true} { association: User.Tasks, separate: true }
], ],
order: [ order: [
['id', 'ASC'] ['id', 'ASC']
...@@ -71,9 +71,9 @@ if (current.dialect.supports.groupedLimit) { ...@@ -71,9 +71,9 @@ if (current.dialect.supports.groupedLimit) {
Task = this.sequelize.define('Task', {}), Task = this.sequelize.define('Task', {}),
sqlSpy = sinon.spy(); sqlSpy = sinon.spy();
User.Tasks = User.hasMany(Task, {as: 'tasks'}); User.Tasks = User.hasMany(Task, { as: 'tasks' });
return this.sequelize.sync({force: true}).then(() => { return this.sequelize.sync({ force: true }).then(() => {
return User.create({ return User.create({
id: 1, id: 1,
tasks: [ tasks: [
...@@ -87,7 +87,7 @@ if (current.dialect.supports.groupedLimit) { ...@@ -87,7 +87,7 @@ if (current.dialect.supports.groupedLimit) {
return User.findAll({ return User.findAll({
attributes: ['name'], attributes: ['name'],
include: [ include: [
{association: User.Tasks, separate: true} { association: User.Tasks, separate: true }
], ],
order: [ order: [
['id', 'ASC'] ['id', 'ASC']
...@@ -122,7 +122,7 @@ if (current.dialect.supports.groupedLimit) { ...@@ -122,7 +122,7 @@ if (current.dialect.supports.groupedLimit) {
}); });
return this.sequelize return this.sequelize
.sync({force: true}) .sync({ force: true })
.then(() => { .then(() => {
return User.create({ return User.create({
id: 1, id: 1,
...@@ -169,12 +169,12 @@ if (current.dialect.supports.groupedLimit) { ...@@ -169,12 +169,12 @@ if (current.dialect.supports.groupedLimit) {
User.Team = User.belongsTo(Team); User.Team = User.belongsTo(Team);
Team.Company = Team.belongsTo(Company); Team.Company = Team.belongsTo(Company);
return this.sequelize.sync({force: true}).then(() => { return this.sequelize.sync({ force: true }).then(() => {
return User.create({}); return User.create({});
}).then(() => { }).then(() => {
return User.findAll({ return User.findAll({
include: [ include: [
{association: User.Team, include: [Team.Company]} { association: User.Team, include: [Team.Company] }
] ]
}); });
}); });
...@@ -190,9 +190,9 @@ if (current.dialect.supports.groupedLimit) { ...@@ -190,9 +190,9 @@ if (current.dialect.supports.groupedLimit) {
}), }),
sqlSpy = sinon.spy(); sqlSpy = sinon.spy();
User.Tasks = User.hasMany(Task, {as: 'tasks', foreignKey: 'userId'}); User.Tasks = User.hasMany(Task, { as: 'tasks', foreignKey: 'userId' });
return this.sequelize.sync({force: true}).then(() => { return this.sequelize.sync({ force: true }).then(() => {
return Promise.join( return Promise.join(
User.create({ User.create({
id: 1, id: 1,
...@@ -218,7 +218,7 @@ if (current.dialect.supports.groupedLimit) { ...@@ -218,7 +218,7 @@ if (current.dialect.supports.groupedLimit) {
).then(() => { ).then(() => {
return User.findAll({ return User.findAll({
include: [ include: [
{association: User.Tasks, limit: 2} { association: User.Tasks, limit: 2 }
], ],
order: [ order: [
['id', 'ASC'] ['id', 'ASC']
...@@ -241,10 +241,10 @@ if (current.dialect.supports.groupedLimit) { ...@@ -241,10 +241,10 @@ if (current.dialect.supports.groupedLimit) {
Task = this.sequelize.define('Task', {}), Task = this.sequelize.define('Task', {}),
sqlSpy = sinon.spy(); sqlSpy = sinon.spy();
User.Company = User.belongsTo(Company, {as: 'company'}); User.Company = User.belongsTo(Company, { as: 'company' });
Company.Tasks = Company.hasMany(Task, {as: 'tasks'}); Company.Tasks = Company.hasMany(Task, { as: 'tasks' });
return this.sequelize.sync({force: true}).then(() => { return this.sequelize.sync({ force: true }).then(() => {
return Promise.join( return Promise.join(
User.create({ User.create({
id: 1, id: 1,
...@@ -257,7 +257,7 @@ if (current.dialect.supports.groupedLimit) { ...@@ -257,7 +257,7 @@ if (current.dialect.supports.groupedLimit) {
} }
}, { }, {
include: [ include: [
{association: User.Company, include: [Company.Tasks]} { association: User.Company, include: [Company.Tasks] }
] ]
}), }),
User.create({ User.create({
...@@ -269,15 +269,15 @@ if (current.dialect.supports.groupedLimit) { ...@@ -269,15 +269,15 @@ if (current.dialect.supports.groupedLimit) {
} }
}, { }, {
include: [ include: [
{association: User.Company, include: [Company.Tasks]} { association: User.Company, include: [Company.Tasks] }
] ]
}) })
).then(() => { ).then(() => {
return User.findAll({ return User.findAll({
include: [ include: [
{association: User.Company, include: [ { association: User.Company, include: [
{association: Company.Tasks, separate: true} { association: Company.Tasks, separate: true }
]} ] }
], ],
order: [ order: [
['id', 'ASC'] ['id', 'ASC']
...@@ -301,40 +301,40 @@ if (current.dialect.supports.groupedLimit) { ...@@ -301,40 +301,40 @@ if (current.dialect.supports.groupedLimit) {
Task = this.sequelize.define('Task', {}), Task = this.sequelize.define('Task', {}),
sqlSpy = sinon.spy(); sqlSpy = sinon.spy();
Company.Users = Company.hasMany(User, {as: 'users'}); Company.Users = Company.hasMany(User, { as: 'users' });
User.Tasks = User.hasMany(Task, {as: 'tasks'}); User.Tasks = User.hasMany(Task, { as: 'tasks' });
Task.Project = Task.belongsTo(Project, {as: 'project'}); Task.Project = Task.belongsTo(Project, { as: 'project' });
return this.sequelize.sync({force: true}).then(() => { return this.sequelize.sync({ force: true }).then(() => {
return Promise.join( return Promise.join(
Company.create({ Company.create({
id: 1, id: 1,
users: [ users: [
{ {
tasks: [ tasks: [
{project: {}}, { project: {} },
{project: {}}, { project: {} },
{project: {}} { project: {} }
] ]
} }
] ]
}, { }, {
include: [ include: [
{association: Company.Users, include: [ { association: Company.Users, include: [
{association: User.Tasks, include: [ { association: User.Tasks, include: [
Task.Project Task.Project
]} ] }
]} ] }
] ]
}) })
).then(() => { ).then(() => {
return Company.findAll({ return Company.findAll({
include: [ include: [
{association: Company.Users, include: [ { association: Company.Users, include: [
{association: User.Tasks, separate: true, include: [ { association: User.Tasks, separate: true, include: [
Task.Project Task.Project
]} ] }
]} ] }
], ],
order: [ order: [
['id', 'ASC'] ['id', 'ASC']
...@@ -355,10 +355,10 @@ if (current.dialect.supports.groupedLimit) { ...@@ -355,10 +355,10 @@ if (current.dialect.supports.groupedLimit) {
Task = this.sequelize.define('Task', {}), Task = this.sequelize.define('Task', {}),
sqlSpy = sinon.spy(); sqlSpy = sinon.spy();
User.Projects = User.hasMany(Project, {as: 'projects'}); User.Projects = User.hasMany(Project, { as: 'projects' });
Project.Tasks = Project.hasMany(Task, {as: 'tasks'}); Project.Tasks = Project.hasMany(Task, { as: 'tasks' });
return this.sequelize.sync({force: true}).then(() => { return this.sequelize.sync({ force: true }).then(() => {
return Promise.join( return Promise.join(
User.create({ User.create({
id: 1, id: 1,
...@@ -380,7 +380,7 @@ if (current.dialect.supports.groupedLimit) { ...@@ -380,7 +380,7 @@ if (current.dialect.supports.groupedLimit) {
] ]
}, { }, {
include: [ include: [
{association: User.Projects, include: [Project.Tasks]} { association: User.Projects, include: [Project.Tasks] }
] ]
}), }),
User.create({ User.create({
...@@ -396,15 +396,15 @@ if (current.dialect.supports.groupedLimit) { ...@@ -396,15 +396,15 @@ if (current.dialect.supports.groupedLimit) {
] ]
}, { }, {
include: [ include: [
{association: User.Projects, include: [Project.Tasks]} { association: User.Projects, include: [Project.Tasks] }
] ]
}) })
).then(() => { ).then(() => {
return User.findAll({ return User.findAll({
include: [ include: [
{association: User.Projects, separate: true, include: [ { association: User.Projects, separate: true, include: [
{association: Project.Tasks, separate: true} { association: Project.Tasks, separate: true }
]} ] }
], ],
order: [ order: [
['id', 'ASC'] ['id', 'ASC']
...@@ -434,25 +434,25 @@ if (current.dialect.supports.groupedLimit) { ...@@ -434,25 +434,25 @@ if (current.dialect.supports.groupedLimit) {
}); });
it('should work with two schema models in a hasMany association', function() { it('should work with two schema models in a hasMany association', function() {
const User = this.sequelize.define('User', {}, {schema: 'archive'}), const User = this.sequelize.define('User', {}, { schema: 'archive' }),
Task = this.sequelize.define('Task', { Task = this.sequelize.define('Task', {
id: { type: DataTypes.INTEGER, primaryKey: true }, id: { type: DataTypes.INTEGER, primaryKey: true },
title: DataTypes.STRING title: DataTypes.STRING
}, {schema: 'archive'}); }, { schema: 'archive' });
User.Tasks = User.hasMany(Task, {as: 'tasks'}); User.Tasks = User.hasMany(Task, { as: 'tasks' });
return Support.dropTestSchemas(this.sequelize).then(() => { return Support.dropTestSchemas(this.sequelize).then(() => {
return this.sequelize.createSchema('archive').then(() => { return this.sequelize.createSchema('archive').then(() => {
return this.sequelize.sync({force: true}).then(() => { return this.sequelize.sync({ force: true }).then(() => {
return Promise.join( return Promise.join(
User.create({ User.create({
id: 1, id: 1,
tasks: [ tasks: [
{id: 1, title: 'b'}, { id: 1, title: 'b' },
{id: 2, title: 'd'}, { id: 2, title: 'd' },
{id: 3, title: 'c'}, { id: 3, title: 'c' },
{id: 4, title: 'a'} { id: 4, title: 'a' }
] ]
}, { }, {
include: [User.Tasks] include: [User.Tasks]
...@@ -460,9 +460,9 @@ if (current.dialect.supports.groupedLimit) { ...@@ -460,9 +460,9 @@ if (current.dialect.supports.groupedLimit) {
User.create({ User.create({
id: 2, id: 2,
tasks: [ tasks: [
{id: 5, title: 'a'}, { id: 5, title: 'a' },
{id: 6, title: 'c'}, { id: 6, title: 'c' },
{id: 7, title: 'b'} { id: 7, title: 'b' }
] ]
}, { }, {
include: [User.Tasks] include: [User.Tasks]
......
...@@ -25,7 +25,7 @@ describe(Support.getTestDialectTeaser('InstanceValidator'), () => { ...@@ -25,7 +25,7 @@ describe(Support.getTestDialectTeaser('InstanceValidator'), () => {
return User.sync({ force: true }).then(() => { return User.sync({ force: true }).then(() => {
return User.create({ username: 'bob', email: 'hello@world.com' }).then(user => { return User.create({ username: 'bob', email: 'hello@world.com' }).then(user => {
return User return User
.update({ username: 'toni' }, { where: {id: user.id }}) .update({ username: 'toni' }, { where: { id: user.id } })
.then(() => { .then(() => {
return User.findByPk(1).then(user => { return User.findByPk(1).then(user => {
expect(user.username).to.equal('toni'); expect(user.username).to.equal('toni');
...@@ -47,8 +47,8 @@ describe(Support.getTestDialectTeaser('InstanceValidator'), () => { ...@@ -47,8 +47,8 @@ describe(Support.getTestDialectTeaser('InstanceValidator'), () => {
}); });
return Model.sync({ force: true }).then(() => { return Model.sync({ force: true }).then(() => {
return Model.create({name: 'World'}).then(model => { return Model.create({ name: 'World' }).then(model => {
return model.update({name: ''}).catch(err => { return model.update({ name: '' }).catch(err => {
expect(err).to.be.an.instanceOf(Error); expect(err).to.be.an.instanceOf(Error);
expect(err.get('name')[0].message).to.equal('Validation notEmpty on name failed'); expect(err.get('name')[0].message).to.equal('Validation notEmpty on name failed');
}); });
...@@ -68,8 +68,8 @@ describe(Support.getTestDialectTeaser('InstanceValidator'), () => { ...@@ -68,8 +68,8 @@ describe(Support.getTestDialectTeaser('InstanceValidator'), () => {
}); });
return Model.sync({ force: true }).then(() => { return Model.sync({ force: true }).then(() => {
return Model.create({name: 'World'}).then(() => { return Model.create({ name: 'World' }).then(() => {
return Model.update({name: ''}, {where: {id: 1}}).catch(err => { return Model.update({ name: '' }, { where: { id: 1 } }).catch(err => {
expect(err).to.be.an.instanceOf(Error); expect(err).to.be.an.instanceOf(Error);
expect(err.get('name')[0].message).to.equal('Validation notEmpty on name failed'); expect(err.get('name')[0].message).to.equal('Validation notEmpty on name failed');
}); });
...@@ -196,14 +196,14 @@ describe(Support.getTestDialectTeaser('InstanceValidator'), () => { ...@@ -196,14 +196,14 @@ describe(Support.getTestDialectTeaser('InstanceValidator'), () => {
}); });
it('correctly throws an error using create method ', function() { it('correctly throws an error using create method ', function() {
return this.Project.create({name: 'nope'}).catch(err => { return this.Project.create({ name: 'nope' }).catch(err => {
expect(err).to.have.ownProperty('name'); expect(err).to.have.ownProperty('name');
}); });
}); });
it('correctly validates using create method ', function() { it('correctly validates using create method ', function() {
return this.Project.create({}).then(project => { return this.Project.create({}).then(project => {
return this.Task.create({something: 1}).then(task => { return this.Task.create({ something: 1 }).then(task => {
return project.setTask(task).then(task => { return project.setTask(task).then(task => {
expect(task.ProjectId).to.not.be.null; expect(task.ProjectId).to.not.be.null;
return task.setProject(project).then(project => { return task.setProject(project).then(project => {
...@@ -229,7 +229,7 @@ describe(Support.getTestDialectTeaser('InstanceValidator'), () => { ...@@ -229,7 +229,7 @@ describe(Support.getTestDialectTeaser('InstanceValidator'), () => {
}); });
return User.sync({ force: true }).then(() => { return User.sync({ force: true }).then(() => {
return User.create({id: 'helloworld'}).catch(err => { return User.create({ id: 'helloworld' }).catch(err => {
expect(err).to.be.an.instanceOf(Error); expect(err).to.be.an.instanceOf(Error);
expect(err.get('id')[0].message).to.equal('Validation isInt on id failed'); expect(err.get('id')[0].message).to.equal('Validation isInt on id failed');
}); });
...@@ -249,7 +249,7 @@ describe(Support.getTestDialectTeaser('InstanceValidator'), () => { ...@@ -249,7 +249,7 @@ describe(Support.getTestDialectTeaser('InstanceValidator'), () => {
}); });
return User.sync({ force: true }).then(() => { return User.sync({ force: true }).then(() => {
return User.create({username: 'helloworldhelloworld'}).catch(err => { return User.create({ username: 'helloworldhelloworld' }).catch(err => {
expect(err).to.be.an.instanceOf(Error); expect(err).to.be.an.instanceOf(Error);
expect(err.get('username')[0].message).to.equal('Username must be an integer!'); expect(err.get('username')[0].message).to.equal('Username must be an integer!');
}); });
...@@ -273,14 +273,14 @@ describe(Support.getTestDialectTeaser('InstanceValidator'), () => { ...@@ -273,14 +273,14 @@ describe(Support.getTestDialectTeaser('InstanceValidator'), () => {
}); });
it('should emit an error when we try to enter in a string for the id key with validation arguments', function() { it('should emit an error when we try to enter in a string for the id key with validation arguments', function() {
return this.User.create({id: 'helloworld'}).catch(err => { return this.User.create({ id: 'helloworld' }).catch(err => {
expect(err).to.be.an.instanceOf(Error); expect(err).to.be.an.instanceOf(Error);
expect(err.get('id')[0].message).to.equal('ID must be an integer!'); expect(err.get('id')[0].message).to.equal('ID must be an integer!');
}); });
}); });
it('should emit an error when we try to enter in a string for an auto increment key through .build().validate()', function() { it('should emit an error when we try to enter in a string for an auto increment key through .build().validate()', function() {
const user = this.User.build({id: 'helloworld'}); const user = this.User.build({ id: 'helloworld' });
return expect(user.validate()).to.be.rejected.then(err => { return expect(user.validate()).to.be.rejected.then(err => {
expect(err.get('id')[0].message).to.equal('ID must be an integer!'); expect(err.get('id')[0].message).to.equal('ID must be an integer!');
...@@ -288,7 +288,7 @@ describe(Support.getTestDialectTeaser('InstanceValidator'), () => { ...@@ -288,7 +288,7 @@ describe(Support.getTestDialectTeaser('InstanceValidator'), () => {
}); });
it('should emit an error when we try to .save()', function() { it('should emit an error when we try to .save()', function() {
const user = this.User.build({id: 'helloworld'}); const user = this.User.build({ id: 'helloworld' });
return user.save().catch(err => { return user.save().catch(err => {
expect(err).to.be.an.instanceOf(Error); expect(err).to.be.an.instanceOf(Error);
expect(err.get('id')[0].message).to.equal('ID must be an integer!'); expect(err.get('id')[0].message).to.equal('ID must be an integer!');
...@@ -496,7 +496,7 @@ describe(Support.getTestDialectTeaser('InstanceValidator'), () => { ...@@ -496,7 +496,7 @@ describe(Support.getTestDialectTeaser('InstanceValidator'), () => {
} }
} }
}), }),
foo = Foo.build({bar: 'a'}); foo = Foo.build({ bar: 'a' });
return expect(foo.validate()).not.to.be.rejected.then(() => { return expect(foo.validate()).not.to.be.rejected.then(() => {
return expect(foo.validate()).not.to.be.rejected; return expect(foo.validate()).not.to.be.rejected;
}); });
...@@ -569,7 +569,7 @@ describe(Support.getTestDialectTeaser('InstanceValidator'), () => { ...@@ -569,7 +569,7 @@ describe(Support.getTestDialectTeaser('InstanceValidator'), () => {
} }
}); });
return User.sync({force: true}).then(() => { return User.sync({ force: true }).then(() => {
return User.create({ name: 'RedCat' }).then(user => { return User.create({ name: 'RedCat' }).then(user => {
expect(user.getDataValue('name')).to.equal('RedCat'); expect(user.getDataValue('name')).to.equal('RedCat');
user.setDataValue('name', 'YellowCat'); user.setDataValue('name', 'YellowCat');
...@@ -641,7 +641,7 @@ describe(Support.getTestDialectTeaser('InstanceValidator'), () => { ...@@ -641,7 +641,7 @@ describe(Support.getTestDialectTeaser('InstanceValidator'), () => {
}); });
return expect(User.build({ return expect(User.build({
email: {lol: true} email: { lol: true }
}).validate()).to.be.rejectedWith(Sequelize.ValidationError); }).validate()).to.be.rejectedWith(Sequelize.ValidationError);
}); });
...@@ -653,7 +653,7 @@ describe(Support.getTestDialectTeaser('InstanceValidator'), () => { ...@@ -653,7 +653,7 @@ describe(Support.getTestDialectTeaser('InstanceValidator'), () => {
}); });
return expect(User.build({ return expect(User.build({
email: {lol: true} email: { lol: true }
}).validate()).to.be.rejectedWith(Sequelize.ValidationError); }).validate()).to.be.rejectedWith(Sequelize.ValidationError);
}); });
...@@ -665,7 +665,7 @@ describe(Support.getTestDialectTeaser('InstanceValidator'), () => { ...@@ -665,7 +665,7 @@ describe(Support.getTestDialectTeaser('InstanceValidator'), () => {
}); });
return expect(User.build({ return expect(User.build({
email: {lol: true} email: { lol: true }
}).validate()).to.be.rejectedWith(Sequelize.ValidationError); }).validate()).to.be.rejectedWith(Sequelize.ValidationError);
}); });
......
...@@ -207,13 +207,13 @@ describe(Support.getTestDialectTeaser('Instance'), () => { ...@@ -207,13 +207,13 @@ describe(Support.getTestDialectTeaser('Instance'), () => {
return this.User.create({ username: 'fnord', age: 1, isAdmin: true }).then(user => { return this.User.create({ username: 'fnord', age: 1, isAdmin: true }).then(user => {
return this.Project.create({ title: 'fnord' }).then(project => { return this.Project.create({ title: 'fnord' }).then(project => {
return user.setProjects([project]).then(() => { return user.setProjects([project]).then(() => {
return this.User.findAll({include: [{ model: this.Project, as: 'Projects' }]}).then(users => { return this.User.findAll({ include: [{ model: this.Project, as: 'Projects' }] }).then(users => {
const _user = users[0]; const _user = users[0];
expect(_user.Projects).to.exist; expect(_user.Projects).to.exist;
expect(JSON.parse(JSON.stringify(_user)).Projects).to.exist; expect(JSON.parse(JSON.stringify(_user)).Projects).to.exist;
return this.Project.findAll({include: [{ model: this.User, as: 'LovelyUser' }]}).then(projects => { return this.Project.findAll({ include: [{ model: this.User, as: 'LovelyUser' }] }).then(projects => {
const _project = projects[0]; const _project = projects[0];
expect(_project.LovelyUser).to.exist; expect(_project.LovelyUser).to.exist;
......
...@@ -31,17 +31,17 @@ describe(Support.getTestDialectTeaser('Instance'), () => { ...@@ -31,17 +31,17 @@ describe(Support.getTestDialectTeaser('Instance'), () => {
validateTest: { validateTest: {
type: DataTypes.INTEGER, type: DataTypes.INTEGER,
allowNull: true, allowNull: true,
validate: {isInt: true} validate: { isInt: true }
}, },
validateCustom: { validateCustom: {
type: DataTypes.STRING, type: DataTypes.STRING,
allowNull: true, allowNull: true,
validate: {len: {msg: 'Length failed.', args: [1, 20]}} validate: { len: { msg: 'Length failed.', args: [1, 20] } }
}, },
validateSideEffect: { validateSideEffect: {
type: DataTypes.VIRTUAL, type: DataTypes.VIRTUAL,
allowNull: true, allowNull: true,
validate: {isInt: true}, validate: { isInt: true },
set(val) { set(val) {
this.setDataValue('validateSideEffect', val); this.setDataValue('validateSideEffect', val);
this.setDataValue('validateSideAffected', val*2); this.setDataValue('validateSideAffected', val*2);
...@@ -50,7 +50,7 @@ describe(Support.getTestDialectTeaser('Instance'), () => { ...@@ -50,7 +50,7 @@ describe(Support.getTestDialectTeaser('Instance'), () => {
validateSideAffected: { validateSideAffected: {
type: DataTypes.INTEGER, type: DataTypes.INTEGER,
allowNull: true, allowNull: true,
validate: {isInt: true} validate: { isInt: true }
}, },
dateAllowNullTrue: { dateAllowNullTrue: {
...@@ -92,14 +92,14 @@ describe(Support.getTestDialectTeaser('Instance'), () => { ...@@ -92,14 +92,14 @@ describe(Support.getTestDialectTeaser('Instance'), () => {
email: DataTypes.STRING email: DataTypes.STRING
}); });
return User.sync({force: true}).then(() => { return User.sync({ force: true }).then(() => {
return User.create({ return User.create({
name: 'snafu', name: 'snafu',
email: 'email' email: 'email'
}, { }, {
fields: ['name', 'email'] fields: ['name', 'email']
}).then(user => { }).then(user => {
return user.update({bio: 'swag'}); return user.update({ bio: 'swag' });
}).then(user => { }).then(user => {
return user.reload(); return user.reload();
}).then(user => { }).then(user => {
...@@ -119,7 +119,7 @@ describe(Support.getTestDialectTeaser('Instance'), () => { ...@@ -119,7 +119,7 @@ describe(Support.getTestDialectTeaser('Instance'), () => {
timestamps: false timestamps: false
}); });
return User.sync({force: true}).then(() => { return User.sync({ force: true }).then(() => {
return User.create({ return User.create({
name: 'snafu', name: 'snafu',
email: 'email' email: 'email'
...@@ -144,15 +144,15 @@ describe(Support.getTestDialectTeaser('Instance'), () => { ...@@ -144,15 +144,15 @@ describe(Support.getTestDialectTeaser('Instance'), () => {
name: DataTypes.STRING, name: DataTypes.STRING,
bio: DataTypes.TEXT, bio: DataTypes.TEXT,
email: DataTypes.STRING, email: DataTypes.STRING,
createdAt: {type: DataTypes.DATE(6), allowNull: false}, createdAt: { type: DataTypes.DATE(6), allowNull: false },
updatedAt: {type: DataTypes.DATE(6), allowNull: false} updatedAt: { type: DataTypes.DATE(6), allowNull: false }
}, { }, {
timestamps: true timestamps: true
}); });
this.clock.tick(2100); //move the clock forward 2100 ms. this.clock.tick(2100); //move the clock forward 2100 ms.
return User.sync({force: true}).then(() => { return User.sync({ force: true }).then(() => {
return User.create({ return User.create({
name: 'snafu', name: 'snafu',
email: 'email' email: 'email'
...@@ -188,7 +188,7 @@ describe(Support.getTestDialectTeaser('Instance'), () => { ...@@ -188,7 +188,7 @@ describe(Support.getTestDialectTeaser('Instance'), () => {
it('should save attributes affected by setters', function() { it('should save attributes affected by setters', function() {
const user = this.User.build(); const user = this.User.build();
return user.update({validateSideEffect: 5}).then(() => { return user.update({ validateSideEffect: 5 }).then(() => {
expect(user.validateSideEffect).to.be.equal(5); expect(user.validateSideEffect).to.be.equal(5);
}).then(() => { }).then(() => {
return user.reload(); return user.reload();
...@@ -210,7 +210,7 @@ describe(Support.getTestDialectTeaser('Instance'), () => { ...@@ -210,7 +210,7 @@ describe(Support.getTestDialectTeaser('Instance'), () => {
instance.set('email', 'B'); instance.set('email', 'B');
}); });
return User.sync({force: true}).then(() => { return User.sync({ force: true }).then(() => {
return User.create({ return User.create({
name: 'A', name: 'A',
bio: 'A', bio: 'A',
...@@ -241,7 +241,7 @@ describe(Support.getTestDialectTeaser('Instance'), () => { ...@@ -241,7 +241,7 @@ describe(Support.getTestDialectTeaser('Instance'), () => {
instance.set('email', 'C'); instance.set('email', 'C');
}); });
return User.sync({force: true}).then(() => { return User.sync({ force: true }).then(() => {
return User.create({ return User.create({
name: 'A', name: 'A',
bio: 'A', bio: 'A',
...@@ -278,7 +278,7 @@ describe(Support.getTestDialectTeaser('Instance'), () => { ...@@ -278,7 +278,7 @@ describe(Support.getTestDialectTeaser('Instance'), () => {
instance.set('email', 'B'); instance.set('email', 'B');
}); });
return User.sync({force: true}).then(() => { return User.sync({ force: true }).then(() => {
return User.create({ return User.create({
name: 'A', name: 'A',
bio: 'A', bio: 'A',
...@@ -311,7 +311,7 @@ describe(Support.getTestDialectTeaser('Instance'), () => { ...@@ -311,7 +311,7 @@ describe(Support.getTestDialectTeaser('Instance'), () => {
instance.set('email', 'B'); instance.set('email', 'B');
}); });
return User.sync({force: true}).then(() => { return User.sync({ force: true }).then(() => {
return User.create({ return User.create({
name: 'A', name: 'A',
bio: 'A', bio: 'A',
...@@ -337,7 +337,7 @@ describe(Support.getTestDialectTeaser('Instance'), () => { ...@@ -337,7 +337,7 @@ describe(Support.getTestDialectTeaser('Instance'), () => {
email: DataTypes.STRING email: DataTypes.STRING
}); });
return User.sync({force: true}).then(() => { return User.sync({ force: true }).then(() => {
return User.create({ return User.create({
name: 'snafu', name: 'snafu',
email: 'email' email: 'email'
...@@ -367,7 +367,7 @@ describe(Support.getTestDialectTeaser('Instance'), () => { ...@@ -367,7 +367,7 @@ describe(Support.getTestDialectTeaser('Instance'), () => {
it('ignores unknown attributes', function() { it('ignores unknown attributes', function() {
return this.User.create({ username: 'user' }).then(user => { return this.User.create({ username: 'user' }).then(user => {
return user.update({ username: 'person', foo: 'bar'}).then(user => { return user.update({ username: 'person', foo: 'bar' }).then(user => {
expect(user.username).to.equal('person'); expect(user.username).to.equal('person');
expect(user.foo).not.to.exist; expect(user.foo).not.to.exist;
}); });
...@@ -375,7 +375,7 @@ describe(Support.getTestDialectTeaser('Instance'), () => { ...@@ -375,7 +375,7 @@ describe(Support.getTestDialectTeaser('Instance'), () => {
}); });
it('ignores undefined attributes', function() { it('ignores undefined attributes', function() {
return this.User.sync({force: true}).then(() => { return this.User.sync({ force: true }).then(() => {
return this.User.create({ username: 'user' }).then(user => { return this.User.create({ username: 'user' }).then(user => {
return user.update({ username: undefined }).then(user => { return user.update({ username: undefined }).then(user => {
expect(user.username).to.equal('user'); expect(user.username).to.equal('user');
...@@ -388,7 +388,7 @@ describe(Support.getTestDialectTeaser('Instance'), () => { ...@@ -388,7 +388,7 @@ describe(Support.getTestDialectTeaser('Instance'), () => {
const User = this.sequelize.define(`User${ config.rand()}`, { const User = this.sequelize.define(`User${ config.rand()}`, {
name: DataTypes.STRING, name: DataTypes.STRING,
bio: DataTypes.TEXT, bio: DataTypes.TEXT,
identifier: {type: DataTypes.STRING, primaryKey: true} identifier: { type: DataTypes.STRING, primaryKey: true }
}); });
return User.sync({ force: true }).then(() => { return User.sync({ force: true }).then(() => {
...@@ -437,7 +437,7 @@ describe(Support.getTestDialectTeaser('Instance'), () => { ...@@ -437,7 +437,7 @@ describe(Support.getTestDialectTeaser('Instance'), () => {
expect(download.finishedAt).to.not.be.ok; expect(download.finishedAt).to.not.be.ok;
return Download.findAll({ return Download.findAll({
where: {finishedAt: null} where: { finishedAt: null }
}).then(downloads => { }).then(downloads => {
downloads.forEach(download => { downloads.forEach(download => {
expect(download.startedAt instanceof Date).to.be.true; expect(download.startedAt instanceof Date).to.be.true;
...@@ -454,7 +454,7 @@ describe(Support.getTestDialectTeaser('Instance'), () => { ...@@ -454,7 +454,7 @@ describe(Support.getTestDialectTeaser('Instance'), () => {
const spy = sinon.spy(); const spy = sinon.spy();
return this.User.create({}).then(user => { return this.User.create({}).then(user => {
return user.update({username: 'yolo'}, {logging: spy}).then(() => { return user.update({ username: 'yolo' }, { logging: spy }).then(() => {
expect(spy.called).to.be.ok; expect(spy.called).to.be.ok;
}); });
}); });
......
...@@ -12,10 +12,10 @@ describe(Support.getTestDialectTeaser('DAO'), () => { ...@@ -12,10 +12,10 @@ describe(Support.getTestDialectTeaser('DAO'), () => {
describe('set', () => { describe('set', () => {
it('doesn\'t overwrite generated primary keys', function() { it('doesn\'t overwrite generated primary keys', function() {
const User = this.sequelize.define('User', { const User = this.sequelize.define('User', {
name: {type: DataTypes.STRING} name: { type: DataTypes.STRING }
}); });
const user = User.build({id: 1, name: 'Mick'}); const user = User.build({ id: 1, name: 'Mick' });
expect(user.get('id')).to.equal(1); expect(user.get('id')).to.equal(1);
expect(user.get('name')).to.equal('Mick'); expect(user.get('name')).to.equal('Mick');
...@@ -29,10 +29,10 @@ describe(Support.getTestDialectTeaser('DAO'), () => { ...@@ -29,10 +29,10 @@ describe(Support.getTestDialectTeaser('DAO'), () => {
it('doesn\'t overwrite defined primary keys', function() { it('doesn\'t overwrite defined primary keys', function() {
const User = this.sequelize.define('User', { const User = this.sequelize.define('User', {
identifier: {type: DataTypes.STRING, primaryKey: true} identifier: { type: DataTypes.STRING, primaryKey: true }
}); });
const user = User.build({identifier: 'identifier'}); const user = User.build({ identifier: 'identifier' });
expect(user.get('identifier')).to.equal('identifier'); expect(user.get('identifier')).to.equal('identifier');
user.set('identifier', 'another identifier'); user.set('identifier', 'another identifier');
...@@ -41,7 +41,7 @@ describe(Support.getTestDialectTeaser('DAO'), () => { ...@@ -41,7 +41,7 @@ describe(Support.getTestDialectTeaser('DAO'), () => {
it('doesn\'t set timestamps', function() { it('doesn\'t set timestamps', function() {
const User = this.sequelize.define('User', { const User = this.sequelize.define('User', {
identifier: {type: DataTypes.STRING, primaryKey: true} identifier: { type: DataTypes.STRING, primaryKey: true }
}); });
const user = User.build({}, { const user = User.build({}, {
...@@ -59,7 +59,7 @@ describe(Support.getTestDialectTeaser('DAO'), () => { ...@@ -59,7 +59,7 @@ describe(Support.getTestDialectTeaser('DAO'), () => {
it('doesn\'t set underscored timestamps', function() { it('doesn\'t set underscored timestamps', function() {
const User = this.sequelize.define('User', { const User = this.sequelize.define('User', {
identifier: {type: DataTypes.STRING, primaryKey: true} identifier: { type: DataTypes.STRING, primaryKey: true }
}, { }, {
underscored: true underscored: true
}); });
...@@ -79,8 +79,8 @@ describe(Support.getTestDialectTeaser('DAO'), () => { ...@@ -79,8 +79,8 @@ describe(Support.getTestDialectTeaser('DAO'), () => {
it('doesn\'t set value if not a dynamic setter or a model attribute', function() { it('doesn\'t set value if not a dynamic setter or a model attribute', function() {
const User = this.sequelize.define('User', { const User = this.sequelize.define('User', {
name: {type: DataTypes.STRING}, name: { type: DataTypes.STRING },
email_hidden: {type: DataTypes.STRING} email_hidden: { type: DataTypes.STRING }
}, { }, {
setterMethods: { setterMethods: {
email_secret(value) { email_secret(value) {
...@@ -113,7 +113,7 @@ describe(Support.getTestDialectTeaser('DAO'), () => { ...@@ -113,7 +113,7 @@ describe(Support.getTestDialectTeaser('DAO'), () => {
type: DataTypes.BOOLEAN, type: DataTypes.BOOLEAN,
defaultValue: false defaultValue: false
} }
}, {timestamps: false}); }, { timestamps: false });
return User.sync({ force: true }).then(() => { return User.sync({ force: true }).then(() => {
return User.create({}).then(user => { return User.create({}).then(user => {
...@@ -168,8 +168,8 @@ describe(Support.getTestDialectTeaser('DAO'), () => { ...@@ -168,8 +168,8 @@ describe(Support.getTestDialectTeaser('DAO'), () => {
id: 1, id: 1,
title: 'Chair', title: 'Chair',
tags: [ tags: [
{id: 1, name: 'Alpha'}, { id: 1, name: 'Alpha' },
{id: 2, name: 'Beta'} { id: 2, name: 'Beta' }
], ],
user: { user: {
id: 1, id: 1,
...@@ -211,15 +211,15 @@ describe(Support.getTestDialectTeaser('DAO'), () => { ...@@ -211,15 +211,15 @@ describe(Support.getTestDialectTeaser('DAO'), () => {
id: 1, id: 1,
title: 'Chair', title: 'Chair',
tags: [ tags: [
{id: 1, name: 'Alpha'}, { id: 1, name: 'Alpha' },
{id: 2, name: 'Beta'} { id: 2, name: 'Beta' }
], ],
user: { user: {
id: 1, id: 1,
first_name: 'Mick', first_name: 'Mick',
last_name: 'Hansen' last_name: 'Hansen'
} }
}, {raw: true}); }, { raw: true });
expect(product.tags).to.be.ok; expect(product.tags).to.be.ok;
expect(product.tags.length).to.equal(2); expect(product.tags.length).to.equal(2);
...@@ -285,7 +285,7 @@ describe(Support.getTestDialectTeaser('DAO'), () => { ...@@ -285,7 +285,7 @@ describe(Support.getTestDialectTeaser('DAO'), () => {
const product = Product.build({ const product = Product.build({
price: 10 price: 10
}); });
expect(product.toJSON()).to.deep.equal({withTaxes: 1250, price: 1000, id: null}); expect(product.toJSON()).to.deep.equal({ withTaxes: 1250, price: 1000, id: null });
}); });
it('should work with save', function() { it('should work with save', function() {
...@@ -344,10 +344,10 @@ describe(Support.getTestDialectTeaser('DAO'), () => { ...@@ -344,10 +344,10 @@ describe(Support.getTestDialectTeaser('DAO'), () => {
first_name: 'Mick', first_name: 'Mick',
last_name: 'Hansen' last_name: 'Hansen'
} }
}, {raw: true}); }, { raw: true });
expect(product.get('user', {plain: true})).not.to.be.instanceof(User); expect(product.get('user', { plain: true })).not.to.be.instanceof(User);
expect(product.get({plain: true}).user).not.to.be.instanceof(User); expect(product.get({ plain: true }).user).not.to.be.instanceof(User);
}); });
}); });
...@@ -360,12 +360,12 @@ describe(Support.getTestDialectTeaser('DAO'), () => { ...@@ -360,12 +360,12 @@ describe(Support.getTestDialectTeaser('DAO'), () => {
const product = Product.build({ const product = Product.build({
id: 1, id: 1,
title: 'Chair' title: 'Chair'
}, {raw: true}); }, { raw: true });
const values = product.get({clone: true}); const values = product.get({ clone: true });
delete values.title; delete values.title;
expect(product.get({clone: true}).title).to.be.ok; expect(product.get({ clone: true }).title).to.be.ok;
}); });
}); });
...@@ -418,32 +418,32 @@ describe(Support.getTestDialectTeaser('DAO'), () => { ...@@ -418,32 +418,32 @@ describe(Support.getTestDialectTeaser('DAO'), () => {
}); });
expect(product.get('rating')).to.equal(5); expect(product.get('rating')).to.equal(5);
expect(product.get('rating', {apiVersion: 2})).to.equal(100); expect(product.get('rating', { apiVersion: 2 })).to.equal(100);
expect(product.get({plain: true})).to.have.property('rating', 5); expect(product.get({ plain: true })).to.have.property('rating', 5);
expect(product.get({plain: true}).user).to.have.property('height', 6.06); expect(product.get({ plain: true }).user).to.have.property('height', 6.06);
expect(product.get({plain: true, apiVersion: 1})).to.have.property('rating', 5); expect(product.get({ plain: true, apiVersion: 1 })).to.have.property('rating', 5);
expect(product.get({plain: true, apiVersion: 1}).user).to.have.property('height', 6.06); expect(product.get({ plain: true, apiVersion: 1 }).user).to.have.property('height', 6.06);
expect(product.get({plain: true, apiVersion: 2})).to.have.property('rating', 100); expect(product.get({ plain: true, apiVersion: 2 })).to.have.property('rating', 100);
expect(product.get({plain: true, apiVersion: 2}).user).to.have.property('height', 185); expect(product.get({ plain: true, apiVersion: 2 }).user).to.have.property('height', 185);
expect(product.get('user').get('height', {apiVersion: 2})).to.equal(185); expect(product.get('user').get('height', { apiVersion: 2 })).to.equal(185);
}); });
}); });
describe('changed', () => { describe('changed', () => {
it('should return false if object was built from database', function() { it('should return false if object was built from database', function() {
const User = this.sequelize.define('User', { const User = this.sequelize.define('User', {
name: {type: DataTypes.STRING} name: { type: DataTypes.STRING }
}); });
return User.sync().then(() => { return User.sync().then(() => {
return User.create({name: 'Jan Meier'}).then(user => { return User.create({ name: 'Jan Meier' }).then(user => {
expect(user.changed('name')).to.be.false; expect(user.changed('name')).to.be.false;
expect(user.changed()).not.to.be.ok; expect(user.changed()).not.to.be.ok;
}); });
}).then(() => { }).then(() => {
return User.bulkCreate([{name: 'Jan Meier'}]).spread(user => { return User.bulkCreate([{ name: 'Jan Meier' }]).spread(user => {
expect(user.changed('name')).to.be.false; expect(user.changed('name')).to.be.false;
expect(user.changed()).not.to.be.ok; expect(user.changed()).not.to.be.ok;
}); });
...@@ -452,7 +452,7 @@ describe(Support.getTestDialectTeaser('DAO'), () => { ...@@ -452,7 +452,7 @@ describe(Support.getTestDialectTeaser('DAO'), () => {
it('should return true if previous value is different', function() { it('should return true if previous value is different', function() {
const User = this.sequelize.define('User', { const User = this.sequelize.define('User', {
name: {type: DataTypes.STRING} name: { type: DataTypes.STRING }
}); });
const user = User.build({ const user = User.build({
...@@ -465,7 +465,7 @@ describe(Support.getTestDialectTeaser('DAO'), () => { ...@@ -465,7 +465,7 @@ describe(Support.getTestDialectTeaser('DAO'), () => {
it('should return false immediately after saving', function() { it('should return false immediately after saving', function() {
const User = this.sequelize.define('User', { const User = this.sequelize.define('User', {
name: {type: DataTypes.STRING} name: { type: DataTypes.STRING }
}); });
return User.sync().then(() => { return User.sync().then(() => {
...@@ -485,7 +485,7 @@ describe(Support.getTestDialectTeaser('DAO'), () => { ...@@ -485,7 +485,7 @@ describe(Support.getTestDialectTeaser('DAO'), () => {
it('should be available to a afterUpdate hook', function() { it('should be available to a afterUpdate hook', function() {
const User = this.sequelize.define('User', { const User = this.sequelize.define('User', {
name: {type: DataTypes.STRING} name: { type: DataTypes.STRING }
}); });
let changed; let changed;
...@@ -494,7 +494,7 @@ describe(Support.getTestDialectTeaser('DAO'), () => { ...@@ -494,7 +494,7 @@ describe(Support.getTestDialectTeaser('DAO'), () => {
return; return;
}); });
return User.sync({force: true}).then(() => { return User.sync({ force: true }).then(() => {
return User.create({ return User.create({
name: 'Ford Prefect' name: 'Ford Prefect'
}); });
...@@ -531,7 +531,7 @@ describe(Support.getTestDialectTeaser('DAO'), () => { ...@@ -531,7 +531,7 @@ describe(Support.getTestDialectTeaser('DAO'), () => {
it('should return the previous value', function() { it('should return the previous value', function() {
const User = this.sequelize.define('User', { const User = this.sequelize.define('User', {
name: {type: DataTypes.STRING} name: { type: DataTypes.STRING }
}); });
const user = User.build({ const user = User.build({
......
...@@ -253,9 +253,9 @@ describe('model', () => { ...@@ -253,9 +253,9 @@ describe('model', () => {
username: 'swen123', username: 'swen123',
emergency_contact: 'Unknown' emergency_contact: 'Unknown'
}).then(() => { }).then(() => {
return this.User.findOne({where: { return this.User.findOne({ where: {
emergency_contact: 'Unknown' emergency_contact: 'Unknown'
}}); } });
}).then(user => { }).then(user => {
expect(user.username).to.equal('swen123'); expect(user.username).to.equal('swen123');
}); });
......
...@@ -13,7 +13,7 @@ describe(Support.getTestDialectTeaser('Model'), () => { ...@@ -13,7 +13,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
let callCount = 0; let callCount = 0;
this.Student = this.sequelize.define('student', { this.Student = this.sequelize.define('student', {
no: {type: Sequelize.INTEGER, primaryKey: true}, no: { type: Sequelize.INTEGER, primaryKey: true },
name: Sequelize.STRING name: Sequelize.STRING
}, { }, {
tableName: 'student', tableName: 'student',
...@@ -21,7 +21,7 @@ describe(Support.getTestDialectTeaser('Model'), () => { ...@@ -21,7 +21,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
}); });
this.Course = this.sequelize.define('course', { this.Course = this.sequelize.define('course', {
no: {type: Sequelize.INTEGER, primaryKey: true}, no: { type: Sequelize.INTEGER, primaryKey: true },
name: Sequelize.STRING name: Sequelize.STRING
}, { }, {
tableName: 'course', tableName: 'course',
...@@ -42,15 +42,15 @@ describe(Support.getTestDialectTeaser('Model'), () => { ...@@ -42,15 +42,15 @@ describe(Support.getTestDialectTeaser('Model'), () => {
timestamps: false timestamps: false
}); });
this.Student.belongsToMany(this.Course, {through: this.Score, foreignKey: 'StudentId'}); this.Student.belongsToMany(this.Course, { through: this.Score, foreignKey: 'StudentId' });
this.Course.belongsToMany(this.Student, {through: this.Score, foreignKey: 'CourseId'}); this.Course.belongsToMany(this.Student, { through: this.Score, foreignKey: 'CourseId' });
return this.sequelize.sync({force: true}).then(() => { return this.sequelize.sync({ force: true }).then(() => {
return Promise.join( return Promise.join(
this.Student.create({no: 1, name: 'ryan'}), this.Student.create({ no: 1, name: 'ryan' }),
this.Course.create({no: 100, name: 'history'}) this.Course.create({ no: 100, name: 'history' })
).then(([student, course]) => { ).then(([student, course]) => {
return student.addCourse(course, { through: {score: 98, test_value: 1000}}); return student.addCourse(course, { through: { score: 98, test_value: 1000 } });
}).then(() => { }).then(() => {
expect(callCount).to.equal(1); expect(callCount).to.equal(1);
return this.Score.findOne({ where: { StudentId: 1, CourseId: 100 } }).then(score => { return this.Score.findOne({ where: { StudentId: 1, CourseId: 100 } }).then(score => {
...@@ -59,7 +59,7 @@ describe(Support.getTestDialectTeaser('Model'), () => { ...@@ -59,7 +59,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
}) })
.then(() => { .then(() => {
return Promise.join( return Promise.join(
this.Student.build({no: 1}).getCourses({where: {no: 100}}), this.Student.build({ no: 1 }).getCourses({ where: { no: 100 } }),
this.Score.findOne({ where: { StudentId: 1, CourseId: 100 } }) this.Score.findOne({ where: { StudentId: 1, CourseId: 100 } })
); );
}) })
...@@ -79,8 +79,8 @@ describe(Support.getTestDialectTeaser('Model'), () => { ...@@ -79,8 +79,8 @@ describe(Support.getTestDialectTeaser('Model'), () => {
timestamps: false timestamps: false
}); });
return this.sequelize.sync({force: true}) return this.sequelize.sync({ force: true })
.then(() => Person.create({name: 'Jozef', nick: 'Joe'})) .then(() => Person.create({ name: 'Jozef', nick: 'Joe' }))
.then(() => Person.findOne({ .then(() => Person.findOne({
attributes: [ attributes: [
'nick', 'nick',
...@@ -108,9 +108,9 @@ describe(Support.getTestDialectTeaser('Model'), () => { ...@@ -108,9 +108,9 @@ describe(Support.getTestDialectTeaser('Model'), () => {
Person.hasMany(Computer); Person.hasMany(Computer);
return this.sequelize.sync({force: true}) return this.sequelize.sync({ force: true })
.then(() => Person.create({name: 'Jozef', nick: 'Joe'})) .then(() => Person.create({ name: 'Jozef', nick: 'Joe' }))
.then(person => person.createComputer({hostname: 'laptop'})) .then(person => person.createComputer({ hostname: 'laptop' }))
.then(() => Person.findAll({ .then(() => Person.findAll({
attributes: [ attributes: [
'nick', 'nick',
...@@ -138,7 +138,7 @@ describe(Support.getTestDialectTeaser('Model'), () => { ...@@ -138,7 +138,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
'foo.bar.baz': Sequelize.TEXT 'foo.bar.baz': Sequelize.TEXT
}); });
return this.sequelize.sync({force: true}) return this.sequelize.sync({ force: true })
.then(() => User.findAll()) .then(() => User.findAll())
.then(result => { .then(result => {
expect(result.length).to.equal(0); expect(result.length).to.equal(0);
......
...@@ -214,8 +214,8 @@ describe(Support.getTestDialectTeaser('Model'), () => { ...@@ -214,8 +214,8 @@ describe(Support.getTestDialectTeaser('Model'), () => {
describe('field and attribute name is the same', () => { describe('field and attribute name is the same', () => {
beforeEach(function() { beforeEach(function() {
return this.Comment.bulkCreate([ return this.Comment.bulkCreate([
{ notes: 'Number one'}, { notes: 'Number one' },
{ notes: 'Number two'} { notes: 'Number two' }
]); ]);
}); });
...@@ -227,7 +227,7 @@ describe(Support.getTestDialectTeaser('Model'), () => { ...@@ -227,7 +227,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
}); });
it('find with where should work', function() { it('find with where should work', function() {
return this.Comment.findAll({ where: { notes: 'Number one' }}).then(comments => { return this.Comment.findAll({ where: { notes: 'Number one' } }).then(comments => {
expect(comments).to.have.length(1); expect(comments).to.have.length(1);
expect(comments[0].notes).to.equal('Number one'); expect(comments[0].notes).to.equal('Number one');
}); });
...@@ -303,15 +303,15 @@ describe(Support.getTestDialectTeaser('Model'), () => { ...@@ -303,15 +303,15 @@ describe(Support.getTestDialectTeaser('Model'), () => {
it('should bulk update', function() { it('should bulk update', function() {
const Entity = this.sequelize.define('Entity', { const Entity = this.sequelize.define('Entity', {
strField: {type: Sequelize.STRING, field: 'str_field'} strField: { type: Sequelize.STRING, field: 'str_field' }
}); });
return this.sequelize.sync({force: true}).then(() => { return this.sequelize.sync({ force: true }).then(() => {
return Entity.create({strField: 'foo'}); return Entity.create({ strField: 'foo' });
}).then(() => { }).then(() => {
return Entity.update( return Entity.update(
{strField: 'bar'}, { strField: 'bar' },
{where: {strField: 'foo'}} { where: { strField: 'foo' } }
); );
}).then(() => { }).then(() => {
return Entity.findOne({ return Entity.findOne({
...@@ -347,8 +347,8 @@ describe(Support.getTestDialectTeaser('Model'), () => { ...@@ -347,8 +347,8 @@ describe(Support.getTestDialectTeaser('Model'), () => {
freezeTableName: true freezeTableName: true
}); });
return Model.sync({force: true}).then(() => { return Model.sync({ force: true }).then(() => {
return Model.create({title: 'test'}).then(data => { return Model.create({ title: 'test' }).then(data => {
expect(data.get('test_title')).to.be.an('undefined'); expect(data.get('test_title')).to.be.an('undefined');
expect(data.get('test_id')).to.be.an('undefined'); expect(data.get('test_id')).to.be.an('undefined');
}); });
...@@ -377,10 +377,10 @@ describe(Support.getTestDialectTeaser('Model'), () => { ...@@ -377,10 +377,10 @@ describe(Support.getTestDialectTeaser('Model'), () => {
}).then(() => { }).then(() => {
return this.Task.findOne({ return this.Task.findOne({
include: [ include: [
{model: this.Comment}, { model: this.Comment },
{model: this.User} { model: this.User }
], ],
where: {title: 'DatDo'} where: { title: 'DatDo' }
}); });
}).then(task => { }).then(task => {
expect(task.get('title')).to.equal('DatDo'); expect(task.get('title')).to.equal('DatDo');
...@@ -403,9 +403,9 @@ describe(Support.getTestDialectTeaser('Model'), () => { ...@@ -403,9 +403,9 @@ describe(Support.getTestDialectTeaser('Model'), () => {
}).then(() => { }).then(() => {
return this.User.findAll({ return this.User.findAll({
include: [ include: [
{model: this.Task, where: {title: 'DoDat'}, include: [ { model: this.Task, where: { title: 'DoDat' }, include: [
{model: this.Comment} { model: this.Comment }
]} ] }
] ]
}); });
}).then(users => { }).then(users => {
...@@ -569,7 +569,7 @@ describe(Support.getTestDialectTeaser('Model'), () => { ...@@ -569,7 +569,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
paranoid: true paranoid: true
}); });
return User.sync({force: true}) return User.sync({ force: true })
.then(() => { .then(() => {
return User.create(); return User.create();
}) })
...@@ -596,9 +596,9 @@ describe(Support.getTestDialectTeaser('Model'), () => { ...@@ -596,9 +596,9 @@ describe(Support.getTestDialectTeaser('Model'), () => {
paranoid: true paranoid: true
}); });
return User.sync({force: true}).then(() => { return User.sync({ force: true }).then(() => {
return User.create().then(user => { return User.create().then(user => {
return User.destroy({where: {id: user.get('id')}}); return User.destroy({ where: { id: user.get('id') } });
}).then(() => { }).then(() => {
return User.findAll().then(users => { return User.findAll().then(users => {
expect(users.length).to.equal(0); expect(users.length).to.equal(0);
......
...@@ -40,8 +40,8 @@ describe(Support.getTestDialectTeaser('Model'), () => { ...@@ -40,8 +40,8 @@ describe(Support.getTestDialectTeaser('Model'), () => {
this.Project = this.sequelize.define('project', {}); this.Project = this.sequelize.define('project', {});
this.Task.belongsTo(this.User); this.Task.belongsTo(this.User);
this.Project.belongsToMany(this.User, {through: 'project_user'}); this.Project.belongsToMany(this.User, { through: 'project_user' });
this.User.belongsToMany(this.Project, {through: 'project_user'}); this.User.belongsToMany(this.Project, { through: 'project_user' });
this.sqlAssert = function(sql) { this.sqlAssert = function(sql) {
expect(sql).to.not.include('field1'); expect(sql).to.not.include('field1');
...@@ -97,7 +97,7 @@ describe(Support.getTestDialectTeaser('Model'), () => { ...@@ -97,7 +97,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
} }
}); });
return this.sequelize.sync({ force: true}).then(() => { return this.sequelize.sync({ force: true }).then(() => {
return Post.bulkCreate([{ text: 'text1' }, { text: 'text2' }]); return Post.bulkCreate([{ text: 'text1' }, { text: 'text2' }]);
}).then(() => { }).then(() => {
let boolQuery = 'EXISTS(SELECT 1) AS "someBoolean"'; let boolQuery = 'EXISTS(SELECT 1) AS "someBoolean"';
......
...@@ -18,14 +18,14 @@ describe(Support.getTestDialectTeaser('Model'), () => { ...@@ -18,14 +18,14 @@ describe(Support.getTestDialectTeaser('Model'), () => {
this.User.hasMany(this.Project); this.User.hasMany(this.Project);
this.Project.belongsTo(this.User); this.Project.belongsTo(this.User);
return this.sequelize.sync({force: true}); return this.sequelize.sync({ force: true });
}); });
describe('count', () => { describe('count', () => {
beforeEach(function() { beforeEach(function() {
return this.User.bulkCreate([ return this.User.bulkCreate([
{username: 'boo'}, { username: 'boo' },
{username: 'boo2'} { username: 'boo2' }
]).then(() => { ]).then(() => {
return this.User.findOne(); return this.User.findOne();
}).then(user => { }).then(user => {
...@@ -74,9 +74,9 @@ describe(Support.getTestDialectTeaser('Model'), () => { ...@@ -74,9 +74,9 @@ describe(Support.getTestDialectTeaser('Model'), () => {
return this.sequelize.sync({ force: true }) return this.sequelize.sync({ force: true })
.then(() => .then(() =>
this.User.bulkCreate([ this.User.bulkCreate([
{ username: 'valak', age: 10}, { username: 'valak', age: 10 },
{ username: 'conjuring', age: 20}, { username: 'conjuring', age: 20 },
{ username: 'scary', age: 10} { username: 'scary', age: 10 }
]) ])
) )
.then(() => .then(() =>
...@@ -108,9 +108,9 @@ describe(Support.getTestDialectTeaser('Model'), () => { ...@@ -108,9 +108,9 @@ describe(Support.getTestDialectTeaser('Model'), () => {
return this.sequelize.sync({ force: true }) return this.sequelize.sync({ force: true })
.then(() => .then(() =>
this.User.bulkCreate([ this.User.bulkCreate([
{ username: 'ember', age: 10}, { username: 'ember', age: 10 },
{ username: 'angular', age: 20}, { username: 'angular', age: 20 },
{ username: 'mithril', age: 10} { username: 'mithril', age: 10 }
]) ])
) )
.then(() => .then(() =>
...@@ -150,9 +150,9 @@ describe(Support.getTestDialectTeaser('Model'), () => { ...@@ -150,9 +150,9 @@ describe(Support.getTestDialectTeaser('Model'), () => {
it('should be able to specify column for COUNT() with includes', function() { it('should be able to specify column for COUNT() with includes', function() {
return this.sequelize.sync({ force: true }).then(() => return this.sequelize.sync({ force: true }).then(() =>
this.User.bulkCreate([ this.User.bulkCreate([
{ username: 'ember', age: 10}, { username: 'ember', age: 10 },
{ username: 'angular', age: 20}, { username: 'angular', age: 20 },
{ username: 'mithril', age: 10} { username: 'mithril', age: 10 }
]) ])
).then(() => ).then(() =>
this.User.count({ this.User.count({
......
...@@ -102,7 +102,7 @@ describe(Support.getTestDialectTeaser('Model'), () => { ...@@ -102,7 +102,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
last_name: Sequelize.STRING last_name: Sequelize.STRING
}); });
const Creator = Product.belongsTo(User, {as: 'creator'}); const Creator = Product.belongsTo(User, { as: 'creator' });
return this.sequelize.sync({ force: true }).then(() => { return this.sequelize.sync({ force: true }).then(() => {
return Product.create({ return Product.create({
...@@ -156,8 +156,8 @@ describe(Support.getTestDialectTeaser('Model'), () => { ...@@ -156,8 +156,8 @@ describe(Support.getTestDialectTeaser('Model'), () => {
id: 1, id: 1,
title: 'Chair', title: 'Chair',
Tags: [ Tags: [
{id: 1, name: 'Alpha'}, { id: 1, name: 'Alpha' },
{id: 2, name: 'Beta'} { id: 2, name: 'Beta' }
] ]
}, { }, {
include: [{ include: [{
...@@ -189,15 +189,15 @@ describe(Support.getTestDialectTeaser('Model'), () => { ...@@ -189,15 +189,15 @@ describe(Support.getTestDialectTeaser('Model'), () => {
name: Sequelize.STRING name: Sequelize.STRING
}); });
const Categories = Product.hasMany(Tag, {as: 'categories'}); const Categories = Product.hasMany(Tag, { as: 'categories' });
return this.sequelize.sync({ force: true }).then(() => { return this.sequelize.sync({ force: true }).then(() => {
return Product.create({ return Product.create({
id: 1, id: 1,
title: 'Chair', title: 'Chair',
categories: [ categories: [
{id: 1, name: 'Alpha'}, { id: 1, name: 'Alpha' },
{id: 2, name: 'Beta'} { id: 2, name: 'Beta' }
] ]
}, { }, {
include: [Categories] include: [Categories]
...@@ -252,7 +252,7 @@ describe(Support.getTestDialectTeaser('Model'), () => { ...@@ -252,7 +252,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
title: Sequelize.STRING title: Sequelize.STRING
}); });
const Job = User.hasOne(Task, {as: 'job'}); const Job = User.hasOne(Task, { as: 'job' });
return this.sequelize.sync({ force: true }).then(() => { return this.sequelize.sync({ force: true }).then(() => {
...@@ -299,8 +299,8 @@ describe(Support.getTestDialectTeaser('Model'), () => { ...@@ -299,8 +299,8 @@ describe(Support.getTestDialectTeaser('Model'), () => {
} }
}); });
User.belongsToMany(Task, {through: 'user_task'}); User.belongsToMany(Task, { through: 'user_task' });
Task.belongsToMany(User, {through: 'user_task'}); Task.belongsToMany(User, { through: 'user_task' });
return this.sequelize.sync({ force: true }).then(() => { return this.sequelize.sync({ force: true }).then(() => {
return User.create({ return User.create({
...@@ -441,8 +441,8 @@ describe(Support.getTestDialectTeaser('Model'), () => { ...@@ -441,8 +441,8 @@ describe(Support.getTestDialectTeaser('Model'), () => {
active: DataTypes.BOOLEAN active: DataTypes.BOOLEAN
}); });
const Jobs = User.belongsToMany(Task, {through: 'user_job', as: 'jobs'}); const Jobs = User.belongsToMany(Task, { through: 'user_job', as: 'jobs' });
Task.belongsToMany(User, {through: 'user_job'}); Task.belongsToMany(User, { through: 'user_job' });
return this.sequelize.sync({ force: true }).then(() => { return this.sequelize.sync({ force: true }).then(() => {
return User.create({ return User.create({
......
...@@ -32,11 +32,11 @@ describe(Support.getTestDialectTeaser('Model'), () => { ...@@ -32,11 +32,11 @@ describe(Support.getTestDialectTeaser('Model'), () => {
]); ]);
}).then(() => { }).then(() => {
return Comment.bulkCreate([ return Comment.bulkCreate([
{ text: 'Market', PostId: 1}, { text: 'Market', PostId: 1 },
{ text: 'Text', PostId: 2}, { text: 'Text', PostId: 2 },
{ text: 'Abc', PostId: 2}, { text: 'Abc', PostId: 2 },
{ text: 'Semaphor', PostId: 1}, { text: 'Semaphor', PostId: 1 },
{ text: 'Text', PostId: 1} { text: 'Text', PostId: 1 }
]); ]);
}).then(() => { }).then(() => {
return Post.findAll({ return Post.findAll({
......
...@@ -42,17 +42,17 @@ if (current.dialect.supports['UNION ALL']) { ...@@ -42,17 +42,17 @@ if (current.dialect.supports['UNION ALL']) {
updatedAt: false updatedAt: false
}); });
this.User.Projects = this.User.belongsToMany(this.Project, {through: 'project_user' }); this.User.Projects = this.User.belongsToMany(this.Project, { through: 'project_user' });
this.Project.belongsToMany(this.User, {as: 'members', through: 'project_user' }); this.Project.belongsToMany(this.User, { as: 'members', through: 'project_user' });
this.User.ParanoidProjects = this.User.belongsToMany(this.Project, {through: this.ProjectUserParanoid}); this.User.ParanoidProjects = this.User.belongsToMany(this.Project, { through: this.ProjectUserParanoid });
this.Project.belongsToMany(this.User, {as: 'paranoidMembers', through: this.ProjectUserParanoid}); this.Project.belongsToMany(this.User, { as: 'paranoidMembers', through: this.ProjectUserParanoid });
this.User.Tasks = this.User.hasMany(this.Task); this.User.Tasks = this.User.hasMany(this.Task);
return this.sequelize.sync({force: true}).then(() => { return this.sequelize.sync({ force: true }).then(() => {
return Promise.join( return Promise.join(
this.User.bulkCreate([{age: -5}, {age: 45}, {age: 7}, {age: -9}, {age: 8}, {age: 15}, {age: -9}]), this.User.bulkCreate([{ age: -5 }, { age: 45 }, { age: 7 }, { age: -9 }, { age: 8 }, { age: 15 }, { age: -9 }]),
this.Project.bulkCreate([{}, {}]), this.Project.bulkCreate([{}, {}]),
this.Task.bulkCreate([{}, {}]) this.Task.bulkCreate([{}, {}])
); );
...@@ -217,10 +217,10 @@ if (current.dialect.supports['UNION ALL']) { ...@@ -217,10 +217,10 @@ if (current.dialect.supports['UNION ALL']) {
this.Task = this.sequelize.define('task'); this.Task = this.sequelize.define('task');
this.User.Tasks = this.User.hasMany(this.Task); this.User.Tasks = this.User.hasMany(this.Task);
return this.sequelize.sync({force: true}).then(() => { return this.sequelize.sync({ force: true }).then(() => {
return Promise.join( return Promise.join(
this.User.bulkCreate([{}, {}, {}]), this.User.bulkCreate([{}, {}, {}]),
this.Task.bulkCreate([{id: 1}, {id: 2}, {id: 3}, {id: 4}, {id: 5}, {id: 6}]) this.Task.bulkCreate([{ id: 1 }, { id: 2 }, { id: 3 }, { id: 4 }, { id: 5 }, { id: 6 }])
); );
}) })
.then(() => Promise.all([this.User.findAll(), this.Task.findAll()])) .then(() => Promise.all([this.User.findAll(), this.Task.findAll()]))
......
...@@ -15,7 +15,7 @@ describe(Support.getTestDialectTeaser('Model'), () => { ...@@ -15,7 +15,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
email: DataTypes.STRING email: DataTypes.STRING
}); });
return this.User.sync({force: true}).then(() => { return this.User.sync({ force: true }).then(() => {
return this.User.create({ return this.User.create({
email: 'test@sequelizejs.com' email: 'test@sequelizejs.com'
}); });
...@@ -69,7 +69,7 @@ describe(Support.getTestDialectTeaser('Model'), () => { ...@@ -69,7 +69,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
}); });
this.User.belongsTo(this.Group); this.User.belongsTo(this.Group);
return this.sequelize.sync({force: true}); return this.sequelize.sync({ force: true });
}); });
if (current.dialect.supports['ORDER NULLS']) { if (current.dialect.supports['ORDER NULLS']) {
......
...@@ -18,7 +18,7 @@ describe(Support.getTestDialectTeaser('Model'), () => { ...@@ -18,7 +18,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
this.User.hasMany(this.Project); this.User.hasMany(this.Project);
this.Project.belongsTo(this.User); this.Project.belongsTo(this.User);
return this.sequelize.sync({force: true}); return this.sequelize.sync({ force: true });
}); });
......
...@@ -21,12 +21,12 @@ describe(Support.getTestDialectTeaser('Model'), () => { ...@@ -21,12 +21,12 @@ describe(Support.getTestDialectTeaser('Model'), () => {
it('works with aliases fields', function() { it('works with aliases fields', function() {
const Pub = this.sequelize.define('Pub', { const Pub = this.sequelize.define('Pub', {
location: {field: 'coordinates', type: DataTypes.GEOGRAPHY} location: { field: 'coordinates', type: DataTypes.GEOGRAPHY }
}), }),
point = {type: 'Point', coordinates: [39.807222, -76.984722]}; point = { type: 'Point', coordinates: [39.807222, -76.984722] };
return Pub.sync({ force: true }).then(() => { return Pub.sync({ force: true }).then(() => {
return Pub.create({location: point}); return Pub.create({ location: point });
}).then(pub => { }).then(pub => {
expect(pub).not.to.be.null; expect(pub).not.to.be.null;
expect(pub.location).to.be.deep.eql(point); expect(pub.location).to.be.deep.eql(point);
...@@ -35,9 +35,9 @@ describe(Support.getTestDialectTeaser('Model'), () => { ...@@ -35,9 +35,9 @@ describe(Support.getTestDialectTeaser('Model'), () => {
it('should create a geography object', function() { it('should create a geography object', function() {
const User = this.User; const User = this.User;
const point = { type: 'Point', coordinates: [39.807222, -76.984722]}; const point = { type: 'Point', coordinates: [39.807222, -76.984722] };
return User.create({username: 'username', geography: point }).then(newUser => { return User.create({ username: 'username', geography: point }).then(newUser => {
expect(newUser).not.to.be.null; expect(newUser).not.to.be.null;
expect(newUser.geography).to.be.deep.eql(point); expect(newUser.geography).to.be.deep.eql(point);
}); });
...@@ -45,14 +45,14 @@ describe(Support.getTestDialectTeaser('Model'), () => { ...@@ -45,14 +45,14 @@ describe(Support.getTestDialectTeaser('Model'), () => {
it('should update a geography object', function() { it('should update a geography object', function() {
const User = this.User; const User = this.User;
const point1 = { type: 'Point', coordinates: [39.807222, -76.984722]}, const point1 = { type: 'Point', coordinates: [39.807222, -76.984722] },
point2 = { type: 'Point', coordinates: [49.807222, -86.984722]}; point2 = { type: 'Point', coordinates: [49.807222, -86.984722] };
const props = {username: 'username', geography: point1}; const props = { username: 'username', geography: point1 };
return User.create(props).then(() => { return User.create(props).then(() => {
return User.update({geography: point2}, {where: {username: props.username}}); return User.update({ geography: point2 }, { where: { username: props.username } });
}).then(() => { }).then(() => {
return User.findOne({where: {username: props.username}}); return User.findOne({ where: { username: props.username } });
}).then(user => { }).then(user => {
expect(user.geography).to.be.deep.eql(point2); expect(user.geography).to.be.deep.eql(point2);
}); });
...@@ -71,9 +71,9 @@ describe(Support.getTestDialectTeaser('Model'), () => { ...@@ -71,9 +71,9 @@ describe(Support.getTestDialectTeaser('Model'), () => {
it('should create a geography object', function() { it('should create a geography object', function() {
const User = this.User; const User = this.User;
const point = { type: 'Point', coordinates: [39.807222, -76.984722]}; const point = { type: 'Point', coordinates: [39.807222, -76.984722] };
return User.create({username: 'username', geography: point }).then(newUser => { return User.create({ username: 'username', geography: point }).then(newUser => {
expect(newUser).not.to.be.null; expect(newUser).not.to.be.null;
expect(newUser.geography).to.be.deep.eql(point); expect(newUser.geography).to.be.deep.eql(point);
}); });
...@@ -81,14 +81,14 @@ describe(Support.getTestDialectTeaser('Model'), () => { ...@@ -81,14 +81,14 @@ describe(Support.getTestDialectTeaser('Model'), () => {
it('should update a geography object', function() { it('should update a geography object', function() {
const User = this.User; const User = this.User;
const point1 = { type: 'Point', coordinates: [39.807222, -76.984722]}, const point1 = { type: 'Point', coordinates: [39.807222, -76.984722] },
point2 = { type: 'Point', coordinates: [49.807222, -86.984722]}; point2 = { type: 'Point', coordinates: [49.807222, -86.984722] };
const props = {username: 'username', geography: point1}; const props = { username: 'username', geography: point1 };
return User.create(props).then(() => { return User.create(props).then(() => {
return User.update({geography: point2}, {where: {username: props.username}}); return User.update({ geography: point2 }, { where: { username: props.username } });
}).then(() => { }).then(() => {
return User.findOne({where: {username: props.username}}); return User.findOne({ where: { username: props.username } });
}).then(user => { }).then(user => {
expect(user.geography).to.be.deep.eql(point2); expect(user.geography).to.be.deep.eql(point2);
}); });
...@@ -109,7 +109,7 @@ describe(Support.getTestDialectTeaser('Model'), () => { ...@@ -109,7 +109,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
const User = this.User; const User = this.User;
const point = { type: 'LineString', 'coordinates': [[100.0, 0.0], [101.0, 1.0]] }; const point = { type: 'LineString', 'coordinates': [[100.0, 0.0], [101.0, 1.0]] };
return User.create({username: 'username', geography: point }).then(newUser => { return User.create({ username: 'username', geography: point }).then(newUser => {
expect(newUser).not.to.be.null; expect(newUser).not.to.be.null;
expect(newUser.geography).to.be.deep.eql(point); expect(newUser.geography).to.be.deep.eql(point);
}); });
...@@ -119,12 +119,12 @@ describe(Support.getTestDialectTeaser('Model'), () => { ...@@ -119,12 +119,12 @@ describe(Support.getTestDialectTeaser('Model'), () => {
const User = this.User; const User = this.User;
const point1 = { type: 'LineString', coordinates: [[100.0, 0.0], [101.0, 1.0]] }, const point1 = { type: 'LineString', coordinates: [[100.0, 0.0], [101.0, 1.0]] },
point2 = { type: 'LineString', coordinates: [[101.0, 0.0], [102.0, 1.0]] }; point2 = { type: 'LineString', coordinates: [[101.0, 0.0], [102.0, 1.0]] };
const props = {username: 'username', geography: point1}; const props = { username: 'username', geography: point1 };
return User.create(props).then(() => { return User.create(props).then(() => {
return User.update({geography: point2}, {where: {username: props.username}}); return User.update({ geography: point2 }, { where: { username: props.username } });
}).then(() => { }).then(() => {
return User.findOne({where: {username: props.username}}); return User.findOne({ where: { username: props.username } });
}).then(user => { }).then(user => {
expect(user.geography).to.be.deep.eql(point2); expect(user.geography).to.be.deep.eql(point2);
}); });
...@@ -146,9 +146,9 @@ describe(Support.getTestDialectTeaser('Model'), () => { ...@@ -146,9 +146,9 @@ describe(Support.getTestDialectTeaser('Model'), () => {
const point = { type: 'Polygon', coordinates: [ const point = { type: 'Polygon', coordinates: [
[[100.0, 0.0], [101.0, 0.0], [101.0, 1.0], [[100.0, 0.0], [101.0, 0.0], [101.0, 1.0],
[100.0, 1.0], [100.0, 0.0]] [100.0, 1.0], [100.0, 0.0]]
]}; ] };
return User.create({username: 'username', geography: point }).then(newUser => { return User.create({ username: 'username', geography: point }).then(newUser => {
expect(newUser).not.to.be.null; expect(newUser).not.to.be.null;
expect(newUser.geography).to.be.deep.eql(point); expect(newUser.geography).to.be.deep.eql(point);
}); });
...@@ -158,17 +158,17 @@ describe(Support.getTestDialectTeaser('Model'), () => { ...@@ -158,17 +158,17 @@ describe(Support.getTestDialectTeaser('Model'), () => {
const User = this.User; const User = this.User;
const polygon1 = { type: 'Polygon', coordinates: [ const polygon1 = { type: 'Polygon', coordinates: [
[[100.0, 0.0], [101.0, 0.0], [101.0, 1.0], [100.0, 1.0], [100.0, 0.0]] [[100.0, 0.0], [101.0, 0.0], [101.0, 1.0], [100.0, 1.0], [100.0, 0.0]]
]}, ] },
polygon2 = { type: 'Polygon', coordinates: [ polygon2 = { type: 'Polygon', coordinates: [
[[100.0, 0.0], [102.0, 0.0], [102.0, 1.0], [[100.0, 0.0], [102.0, 0.0], [102.0, 1.0],
[100.0, 1.0], [100.0, 0.0]] [100.0, 1.0], [100.0, 0.0]]
]}; ] };
const props = {username: 'username', geography: polygon1}; const props = { username: 'username', geography: polygon1 };
return User.create(props).then(() => { return User.create(props).then(() => {
return User.update({geography: polygon2}, {where: {username: props.username}}); return User.update({ geography: polygon2 }, { where: { username: props.username } });
}).then(() => { }).then(() => {
return User.findOne({where: {username: props.username}}); return User.findOne({ where: { username: props.username } });
}).then(user => { }).then(user => {
expect(user.geography).to.be.deep.eql(polygon2); expect(user.geography).to.be.deep.eql(polygon2);
}); });
...@@ -191,9 +191,9 @@ describe(Support.getTestDialectTeaser('Model'), () => { ...@@ -191,9 +191,9 @@ describe(Support.getTestDialectTeaser('Model'), () => {
const point = { type: 'Polygon', coordinates: [ const point = { type: 'Polygon', coordinates: [
[[100.0, 0.0], [101.0, 0.0], [101.0, 1.0], [[100.0, 0.0], [101.0, 0.0], [101.0, 1.0],
[100.0, 1.0], [100.0, 0.0]] [100.0, 1.0], [100.0, 0.0]]
]}; ] };
return User.create({username: 'username', geography: point }).then(newUser => { return User.create({ username: 'username', geography: point }).then(newUser => {
expect(newUser).not.to.be.null; expect(newUser).not.to.be.null;
expect(newUser.geography).to.be.deep.eql(point); expect(newUser.geography).to.be.deep.eql(point);
}); });
...@@ -203,17 +203,17 @@ describe(Support.getTestDialectTeaser('Model'), () => { ...@@ -203,17 +203,17 @@ describe(Support.getTestDialectTeaser('Model'), () => {
const User = this.User; const User = this.User;
const polygon1 = { type: 'Polygon', coordinates: [ const polygon1 = { type: 'Polygon', coordinates: [
[[100.0, 0.0], [101.0, 0.0], [101.0, 1.0], [100.0, 1.0], [100.0, 0.0]] [[100.0, 0.0], [101.0, 0.0], [101.0, 1.0], [100.0, 1.0], [100.0, 0.0]]
]}, ] },
polygon2 = { type: 'Polygon', coordinates: [ polygon2 = { type: 'Polygon', coordinates: [
[[100.0, 0.0], [102.0, 0.0], [102.0, 1.0], [[100.0, 0.0], [102.0, 0.0], [102.0, 1.0],
[100.0, 1.0], [100.0, 0.0]] [100.0, 1.0], [100.0, 0.0]]
]}; ] };
const props = {username: 'username', geography: polygon1}; const props = { username: 'username', geography: polygon1 };
return User.create(props).then(() => { return User.create(props).then(() => {
return User.update({geography: polygon2}, {where: {username: props.username}}); return User.update({ geography: polygon2 }, { where: { username: props.username } });
}).then(() => { }).then(() => {
return User.findOne({where: {username: props.username}}); return User.findOne({ where: { username: props.username } });
}).then(user => { }).then(user => {
expect(user.geography).to.be.deep.eql(polygon2); expect(user.geography).to.be.deep.eql(polygon2);
}); });
......
...@@ -23,12 +23,12 @@ describe(Support.getTestDialectTeaser('Model'), () => { ...@@ -23,12 +23,12 @@ describe(Support.getTestDialectTeaser('Model'), () => {
it('works with aliases fields', function() { it('works with aliases fields', function() {
const Pub = this.sequelize.define('Pub', { const Pub = this.sequelize.define('Pub', {
location: {field: 'coordinates', type: DataTypes.GEOMETRY} location: { field: 'coordinates', type: DataTypes.GEOMETRY }
}), }),
point = {type: 'Point', coordinates: [39.807222, -76.984722]}; point = { type: 'Point', coordinates: [39.807222, -76.984722] };
return Pub.sync({ force: true }).then(() => { return Pub.sync({ force: true }).then(() => {
return Pub.create({location: point}); return Pub.create({ location: point });
}).then(pub => { }).then(pub => {
expect(pub).not.to.be.null; expect(pub).not.to.be.null;
expect(pub.location).to.be.deep.eql(point); expect(pub.location).to.be.deep.eql(point);
...@@ -37,9 +37,9 @@ describe(Support.getTestDialectTeaser('Model'), () => { ...@@ -37,9 +37,9 @@ describe(Support.getTestDialectTeaser('Model'), () => {
it('should create a geometry object', function() { it('should create a geometry object', function() {
const User = this.User; const User = this.User;
const point = { type: 'Point', coordinates: [39.807222, -76.984722]}; const point = { type: 'Point', coordinates: [39.807222, -76.984722] };
return User.create({username: 'username', geometry: point }).then(newUser => { return User.create({ username: 'username', geometry: point }).then(newUser => {
expect(newUser).not.to.be.null; expect(newUser).not.to.be.null;
expect(newUser.geometry).to.be.deep.eql(point); expect(newUser.geometry).to.be.deep.eql(point);
}); });
...@@ -47,14 +47,14 @@ describe(Support.getTestDialectTeaser('Model'), () => { ...@@ -47,14 +47,14 @@ describe(Support.getTestDialectTeaser('Model'), () => {
it('should update a geometry object', function() { it('should update a geometry object', function() {
const User = this.User; const User = this.User;
const point1 = { type: 'Point', coordinates: [39.807222, -76.984722]}, const point1 = { type: 'Point', coordinates: [39.807222, -76.984722] },
point2 = { type: 'Point', coordinates: [49.807222, -86.984722]}; point2 = { type: 'Point', coordinates: [49.807222, -86.984722] };
const props = {username: 'username', geometry: point1}; const props = { username: 'username', geometry: point1 };
return User.create(props).then(() => { return User.create(props).then(() => {
return User.update({geometry: point2}, {where: {username: props.username}}); return User.update({ geometry: point2 }, { where: { username: props.username } });
}).then(() => { }).then(() => {
return User.findOne({where: {username: props.username}}); return User.findOne({ where: { username: props.username } });
}).then(user => { }).then(user => {
expect(user.geometry).to.be.deep.eql(point2); expect(user.geometry).to.be.deep.eql(point2);
}); });
...@@ -73,9 +73,9 @@ describe(Support.getTestDialectTeaser('Model'), () => { ...@@ -73,9 +73,9 @@ describe(Support.getTestDialectTeaser('Model'), () => {
it('should create a geometry object', function() { it('should create a geometry object', function() {
const User = this.User; const User = this.User;
const point = { type: 'Point', coordinates: [39.807222, -76.984722]}; const point = { type: 'Point', coordinates: [39.807222, -76.984722] };
return User.create({username: 'username', geometry: point }).then(newUser => { return User.create({ username: 'username', geometry: point }).then(newUser => {
expect(newUser).not.to.be.null; expect(newUser).not.to.be.null;
expect(newUser.geometry).to.be.deep.eql(point); expect(newUser.geometry).to.be.deep.eql(point);
}); });
...@@ -83,14 +83,14 @@ describe(Support.getTestDialectTeaser('Model'), () => { ...@@ -83,14 +83,14 @@ describe(Support.getTestDialectTeaser('Model'), () => {
it('should update a geometry object', function() { it('should update a geometry object', function() {
const User = this.User; const User = this.User;
const point1 = { type: 'Point', coordinates: [39.807222, -76.984722]}, const point1 = { type: 'Point', coordinates: [39.807222, -76.984722] },
point2 = { type: 'Point', coordinates: [49.807222, -86.984722]}; point2 = { type: 'Point', coordinates: [49.807222, -86.984722] };
const props = {username: 'username', geometry: point1}; const props = { username: 'username', geometry: point1 };
return User.create(props).then(() => { return User.create(props).then(() => {
return User.update({geometry: point2}, {where: {username: props.username}}); return User.update({ geometry: point2 }, { where: { username: props.username } });
}).then(() => { }).then(() => {
return User.findOne({where: {username: props.username}}); return User.findOne({ where: { username: props.username } });
}).then(user => { }).then(user => {
expect(user.geometry).to.be.deep.eql(point2); expect(user.geometry).to.be.deep.eql(point2);
}); });
...@@ -111,7 +111,7 @@ describe(Support.getTestDialectTeaser('Model'), () => { ...@@ -111,7 +111,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
const User = this.User; const User = this.User;
const point = { type: 'LineString', 'coordinates': [[100.0, 0.0], [101.0, 1.0]] }; const point = { type: 'LineString', 'coordinates': [[100.0, 0.0], [101.0, 1.0]] };
return User.create({username: 'username', geometry: point }).then(newUser => { return User.create({ username: 'username', geometry: point }).then(newUser => {
expect(newUser).not.to.be.null; expect(newUser).not.to.be.null;
expect(newUser.geometry).to.be.deep.eql(point); expect(newUser.geometry).to.be.deep.eql(point);
}); });
...@@ -121,12 +121,12 @@ describe(Support.getTestDialectTeaser('Model'), () => { ...@@ -121,12 +121,12 @@ describe(Support.getTestDialectTeaser('Model'), () => {
const User = this.User; const User = this.User;
const point1 = { type: 'LineString', coordinates: [[100.0, 0.0], [101.0, 1.0]] }, const point1 = { type: 'LineString', coordinates: [[100.0, 0.0], [101.0, 1.0]] },
point2 = { type: 'LineString', coordinates: [[101.0, 0.0], [102.0, 1.0]] }; point2 = { type: 'LineString', coordinates: [[101.0, 0.0], [102.0, 1.0]] };
const props = {username: 'username', geometry: point1}; const props = { username: 'username', geometry: point1 };
return User.create(props).then(() => { return User.create(props).then(() => {
return User.update({geometry: point2}, {where: {username: props.username}}); return User.update({ geometry: point2 }, { where: { username: props.username } });
}).then(() => { }).then(() => {
return User.findOne({where: {username: props.username}}); return User.findOne({ where: { username: props.username } });
}).then(user => { }).then(user => {
expect(user.geometry).to.be.deep.eql(point2); expect(user.geometry).to.be.deep.eql(point2);
}); });
...@@ -148,9 +148,9 @@ describe(Support.getTestDialectTeaser('Model'), () => { ...@@ -148,9 +148,9 @@ describe(Support.getTestDialectTeaser('Model'), () => {
const point = { type: 'Polygon', coordinates: [ const point = { type: 'Polygon', coordinates: [
[[100.0, 0.0], [101.0, 0.0], [101.0, 1.0], [[100.0, 0.0], [101.0, 0.0], [101.0, 1.0],
[100.0, 1.0], [100.0, 0.0]] [100.0, 1.0], [100.0, 0.0]]
]}; ] };
return User.create({username: 'username', geometry: point }).then(newUser => { return User.create({ username: 'username', geometry: point }).then(newUser => {
expect(newUser).not.to.be.null; expect(newUser).not.to.be.null;
expect(newUser.geometry).to.be.deep.eql(point); expect(newUser.geometry).to.be.deep.eql(point);
}); });
...@@ -160,17 +160,17 @@ describe(Support.getTestDialectTeaser('Model'), () => { ...@@ -160,17 +160,17 @@ describe(Support.getTestDialectTeaser('Model'), () => {
const User = this.User; const User = this.User;
const polygon1 = { type: 'Polygon', coordinates: [ const polygon1 = { type: 'Polygon', coordinates: [
[[100.0, 0.0], [101.0, 0.0], [101.0, 1.0], [100.0, 1.0], [100.0, 0.0]] [[100.0, 0.0], [101.0, 0.0], [101.0, 1.0], [100.0, 1.0], [100.0, 0.0]]
]}, ] },
polygon2 = { type: 'Polygon', coordinates: [ polygon2 = { type: 'Polygon', coordinates: [
[[100.0, 0.0], [102.0, 0.0], [102.0, 1.0], [[100.0, 0.0], [102.0, 0.0], [102.0, 1.0],
[100.0, 1.0], [100.0, 0.0]] [100.0, 1.0], [100.0, 0.0]]
]}; ] };
const props = {username: 'username', geometry: polygon1}; const props = { username: 'username', geometry: polygon1 };
return User.create(props).then(() => { return User.create(props).then(() => {
return User.update({geometry: polygon2}, {where: {username: props.username}}); return User.update({ geometry: polygon2 }, { where: { username: props.username } });
}).then(() => { }).then(() => {
return User.findOne({where: {username: props.username}}); return User.findOne({ where: { username: props.username } });
}).then(user => { }).then(user => {
expect(user.geometry).to.be.deep.eql(polygon2); expect(user.geometry).to.be.deep.eql(polygon2);
}); });
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!