sequelize
Advanced tools
Comparing version 1.6.0-alpha-2 to 1.6.0-alpha-3
# v1.6.0 # | ||
- [DEPENDENCIES] upgraded most dependencies. most important: mysql was upgraded to 2.0.0-alpha-3 | ||
- [REFACTORING] separated tests for dialects | ||
- [BUG] fixed wrong version in sequelize binary | ||
- [FEATURE] added association prefetching for find and findAll | ||
- [FEATURE] it's now possible to use callbacks of async functions inside migrations (thanks to mphilpot) | ||
- [FEATURE] improved comfort of sequelize.query. just pass an sql string to it and wait for the result | ||
- [FEATURE] Migrations now understand NODE_ENV (thanks to gavri) | ||
- [FEATURE] | ||
@@ -6,0 +11,0 @@ # v1.5.0 # |
@@ -27,3 +27,3 @@ var Utils = require("./../utils") | ||
newAttributes[this.identifier] = { type: DataTypes.INTEGER } | ||
Utils._.extend(this.source.rawAttributes, newAttributes) | ||
Utils._.defaults(this.source.rawAttributes, newAttributes) | ||
return this | ||
@@ -30,0 +30,0 @@ } |
@@ -9,2 +9,3 @@ var Utils = require("./../utils") | ||
var HasMany = function(srcDAO, targetDAO, options) { | ||
this.associationType = 'HasMany' | ||
this.source = srcDAO | ||
@@ -57,2 +58,3 @@ this.target = targetDAO | ||
this.connectorDAO = this.source.daoFactoryManager.sequelize.define(this.combinedName, combinedTableAttributes, this.options) | ||
if(!this.isSelfAssociation) { | ||
@@ -68,3 +70,3 @@ this.target.associations[this.associationAccessor].connectorDAO = this.connectorDAO | ||
newAttributes[this.identifier] = { type: DataTypes.INTEGER } | ||
Utils._.extend(this.target.rawAttributes, newAttributes) | ||
Utils._.defaults(this.target.rawAttributes, newAttributes) | ||
} | ||
@@ -71,0 +73,0 @@ |
@@ -32,3 +32,3 @@ var Utils = require("./../utils") | ||
newAttributes[this.identifier] = { type: DataTypes.INTEGER } | ||
Utils._.extend(this.target.rawAttributes, newAttributes) | ||
Utils._.defaults(this.target.rawAttributes, newAttributes) | ||
@@ -35,0 +35,0 @@ return this |
@@ -206,3 +206,3 @@ var Utils = require("./utils") | ||
Utils._.each(this.options.instanceMethods || {}, function(fct, name) { instance[name] = fct }) | ||
Utils._.each(this.associations, function(association, associationName) { | ||
Utils._.each(this.associations, function(association) { | ||
association.injectGetter(instance) | ||
@@ -212,3 +212,4 @@ association.injectSetter(instance) | ||
instance.isNewRecord = options.hasOwnProperty('isNewRecord') ? options.isNewRecord : true | ||
instance.isNewRecord = options.hasOwnProperty('isNewRecord') ? options.isNewRecord : true | ||
instance.selectedValues = values | ||
@@ -225,4 +226,5 @@ return instance | ||
Utils._.each(this.attributes, function(dataTypeString, attributeName) { | ||
if((attributeName != 'id') && (dataTypeString.indexOf('PRIMARY KEY') > -1)) | ||
if((attributeName != 'id') && (dataTypeString.indexOf('PRIMARY KEY') > -1)) { | ||
result[attributeName] = dataTypeString | ||
} | ||
}) | ||
@@ -236,8 +238,16 @@ | ||
var query = function() { | ||
var args = Utils._.map(arguments, function(arg, _) { return arg }) | ||
, s = this.daoFactoryManager.sequelize | ||
var args = Utils._.map(arguments, function(arg, _) { return arg }) | ||
, sequelize = this.daoFactoryManager.sequelize | ||
// add this as the second argument | ||
if(arguments.length == 1) args.push(this) | ||
return s.query.apply(s, args) | ||
if (arguments.length === 1) { | ||
args.push(this) | ||
} | ||
// add {} as options | ||
if (args.length === 2) { | ||
args.push({}) | ||
} | ||
return sequelize.query.apply(sequelize, args) | ||
} | ||
@@ -244,0 +254,0 @@ |
@@ -183,10 +183,12 @@ var Utils = require('../../utils') | ||
var handleInsertQuery = function(results, metaData) { | ||
// add the inserted row id to the instance | ||
var autoIncrementField = this.callee.__factory.autoIncrementField | ||
, id = null | ||
if (this.callee) { | ||
// add the inserted row id to the instance | ||
var autoIncrementField = this.callee.__factory.autoIncrementField | ||
, id = null | ||
id = id || (results && results[this.getInsertIdField()]) | ||
id = id || (metaData && metaData[this.getInsertIdField()]) | ||
id = id || (results && results[this.getInsertIdField()]) | ||
id = id || (metaData && metaData[this.getInsertIdField()]) | ||
this.callee[autoIncrementField] = id | ||
this.callee[autoIncrementField] = id | ||
} | ||
} | ||
@@ -193,0 +195,0 @@ |
@@ -118,5 +118,6 @@ var Utils = require("../../utils") | ||
var query = "SELECT <%= attributes %> FROM <%= table %>" | ||
, table = null | ||
options = options || {} | ||
options.table = Array.isArray(tableName) ? tableName.map(function(tbl){ return Utils.addTicks(tbl) }).join(", ") : Utils.addTicks(tableName) | ||
options = options || {} | ||
options.table = table = Array.isArray(tableName) ? tableName.map(function(tbl){ return Utils.addTicks(tbl) }).join(", ") : Utils.addTicks(tableName) | ||
options.attributes = options.attributes && options.attributes.map(function(attr){ | ||
@@ -132,15 +133,38 @@ if(Array.isArray(attr) && attr.length == 2) { | ||
if (options.include) { | ||
var tableNames = [options.table] | ||
, optAttributes = [options.table + '.*'] | ||
var optAttributes = [options.table + '.*'] | ||
for (var daoName in options.include) { | ||
if (options.include.hasOwnProperty(daoName)) { | ||
var dao = options.include[daoName] | ||
, _tableName = Utils.addTicks(dao.tableName) | ||
var dao = options.include[daoName] | ||
, daoFactory = dao.daoFactoryManager.getDAO(tableName, { | ||
attribute: 'tableName' | ||
}) | ||
, _tableName = Utils.addTicks(dao.tableName) | ||
, association = dao.getAssociation(daoFactory) | ||
tableNames.push(_tableName) | ||
if (association.connectorDAO) { | ||
var foreignIdentifier = Utils._.keys(association.connectorDAO.rawAttributes).filter(function(attrName) { | ||
return (!!attrName.match(/.+Id$/) || !!attrName.match(/.+_id$/)) && (attrName !== association.identifier) | ||
})[0] | ||
query += ' LEFT OUTER JOIN ' + Utils.addTicks(association.connectorDAO.tableName) + ' ON ' | ||
query += Utils.addTicks(association.connectorDAO.tableName) + '.' | ||
query += Utils.addTicks(foreignIdentifier) + '=' | ||
query += Utils.addTicks(table) + '.' + Utils.addTicks('id') | ||
query += ' LEFT OUTER JOIN ' + Utils.addTicks(dao.tableName) + ' ON ' | ||
query += Utils.addTicks(dao.tableName) + '.' | ||
query += Utils.addTicks('id') + '=' | ||
query += Utils.addTicks(association.connectorDAO.tableName) + '.' + Utils.addTicks(association.identifier) | ||
} else { | ||
query += ' LEFT OUTER JOIN ' + Utils.addTicks(dao.tableName) + ' ON ' | ||
query += Utils.addTicks(association.associationType === 'BelongsTo' ? dao.tableName : tableName) + '.' | ||
query += Utils.addTicks(association.identifier) + '=' | ||
query += Utils.addTicks(table) + '.' + Utils.addTicks('id') | ||
} | ||
optAttributes = optAttributes.concat( | ||
Utils._.keys(dao.attributes).map(function(attr) { | ||
var identifer = [_tableName, Utils.addTicks(attr)] | ||
return identifer.join('.') + ' AS ' + Utils.addTicks(identifer.join('.')) | ||
var identifier = [_tableName, Utils.addTicks(attr)] | ||
return identifier.join('.') + ' AS ' + Utils.addTicks(identifier.join('.')) | ||
}) | ||
@@ -151,3 +175,2 @@ ) | ||
options.table = tableNames.join(', ') | ||
options.attributes = optAttributes.join(', ') | ||
@@ -154,0 +177,0 @@ } |
@@ -13,3 +13,3 @@ var Utils = require("../../utils") | ||
quoteChar = quoteChar || '"' | ||
return quoteChar + removeQuotes(s) + quoteChar | ||
return s.split('.').map(function(e) { return quoteChar + String(e) + quoteChar }).join('.') | ||
} | ||
@@ -206,4 +206,4 @@ | ||
Utils._.keys(dao.attributes).map(function(attr) { | ||
var identifer = [_tableName, Utils.addTicks(attr)] | ||
return identifer.join('.') + ' AS ' + Utils.addTicks(identifer.join('.')) | ||
var identifier = [_tableName, Utils.addTicks(attr)] | ||
return identifier.join('.') + ' AS ' + Utils.addTicks(identifier.join('.')) | ||
}) | ||
@@ -348,5 +348,6 @@ ) | ||
var indexTable = tableName.split('.') | ||
options = Utils._.extend({ | ||
indicesType: null, | ||
indexName: Utils._.underscored(tableName + '_' + onlyAttributeNames.join('_')), | ||
indexName: Utils._.underscored(indexTable[indexTable.length-1] + '_' + onlyAttributeNames.join('_')), | ||
parser: null | ||
@@ -353,0 +354,0 @@ }, options || {}) |
@@ -124,3 +124,3 @@ var moment = require("moment") | ||
self.queryInterface[_method].apply(self.queryInterface, args) | ||
return self.queryInterface[_method].apply(self.queryInterface, args) | ||
} | ||
@@ -127,0 +127,0 @@ })(method) |
@@ -151,3 +151,3 @@ var Utils = require('./utils') | ||
self.sequelize.query(sql).success(function() { | ||
self.sequelize.query(sql, null, {}).success(function() { | ||
self.emit('renameColumn', null) | ||
@@ -241,4 +241,4 @@ emitter.emit('success', null) | ||
options = Utils._.extend({ | ||
success: function(obj){}, | ||
error: function(err){} | ||
success: function(){}, | ||
error: function(){} | ||
}, options || {}) | ||
@@ -250,5 +250,13 @@ | ||
if(Array.isArray(sqlOrQueryParams)) { | ||
if (sqlOrQueryParams.length === 1) { | ||
sqlOrQueryParams.push(null) | ||
} | ||
if (sqlOrQueryParams.length === 2) { | ||
sqlOrQueryParams.push({}) | ||
} | ||
query = self.sequelize.query.apply(self.sequelize, sqlOrQueryParams) | ||
} else { | ||
query = self.sequelize.query(sqlOrQueryParams) | ||
query = self.sequelize.query(sqlOrQueryParams, null, {}) | ||
} | ||
@@ -255,0 +263,0 @@ |
@@ -120,3 +120,4 @@ var Utils = require("./utils") | ||
Sequelize.prototype.query = function(sql, callee, options) { | ||
options = Utils._.extend(Utils._.clone(this.options.query), options || {}) | ||
options = (arguments.length === 3) ? options : { raw: true } | ||
options = Utils._.extend(Utils._.clone(this.options.query), options) | ||
options = Utils._.extend(options, { | ||
@@ -123,0 +124,0 @@ logging: this.options.hasOwnProperty('logging') ? this.options.logging : console.log |
{ | ||
"name": "sequelize", | ||
"description": "Multi dialect ORM for Node.JS", | ||
"version": "1.6.0-alpha-2", | ||
"version": "1.6.0-alpha-3", | ||
"author": "Sascha Depold <sascha@depold.com>", | ||
@@ -51,3 +51,7 @@ "contributors": [ | ||
"test-jasmine": "./node_modules/.bin/jasmine-node spec-jasmine/", | ||
"test-buster": "./node_modules/.bin/buster-test", | ||
"test-buster": "npm run test-buster-mysql && npm run test-buster-postgres && npm run test-buster-sqlite", | ||
"test-buster-travis": "./node_modules/.bin/buster-test", | ||
"test-buster-mysql": "DIALECT=mysql ./node_modules/.bin/buster-test", | ||
"test-buster-postgres": "DIALECT=postgres ./node_modules/.bin/buster-test", | ||
"test-buster-sqlite": "DIALECT=sqlite ./node_modules/.bin/buster-test", | ||
"generate-docs": "node_modules/.bin/dox-foundation --source ./lib --title Sequelize" | ||
@@ -54,0 +58,0 @@ }, |
@@ -22,2 +22,7 @@ var config = require("../config/config") | ||
}, | ||
{ | ||
arguments: ['mySchema.myTable', {title: 'VARCHAR(255)', name: 'VARCHAR(255)'}], | ||
expectation: "CREATE TABLE IF NOT EXISTS \"mySchema\".\"myTable\" (\"title\" VARCHAR(255), \"name\" VARCHAR(255));" | ||
}, | ||
], | ||
@@ -29,2 +34,6 @@ | ||
expectation: "DROP TABLE IF EXISTS \"myTable\";" | ||
}, | ||
{ | ||
arguments: ['mySchema.myTable'], | ||
expectation: "DROP TABLE IF EXISTS \"mySchema\".\"myTable\";" | ||
} | ||
@@ -74,2 +83,8 @@ ], | ||
expectation: "SELECT * FROM \"myTable\" OFFSET 2;" | ||
}, { | ||
arguments: ['mySchema.myTable'], | ||
expectation: "SELECT * FROM \"mySchema\".\"myTable\";" | ||
}, { | ||
arguments: ['mySchema.myTable', {where: {name: "foo';DROP TABLE mySchema.myTable;"}}], | ||
expectation: "SELECT * FROM \"mySchema\".\"myTable\" WHERE \"name\"='foo'';DROP TABLE mySchema.myTable;';" | ||
} | ||
@@ -106,2 +121,8 @@ ], | ||
context: {options: {omitNull: true}} | ||
}, { | ||
arguments: ['mySchema.myTable', {name: 'foo'}], | ||
expectation: "INSERT INTO \"mySchema\".\"myTable\" (\"name\") VALUES ('foo') RETURNING *;" | ||
}, { | ||
arguments: ['mySchema.myTable', {name: "foo';DROP TABLE mySchema.myTable;"}], | ||
expectation: "INSERT INTO \"mySchema\".\"myTable\" (\"name\") VALUES ('foo'';DROP TABLE mySchema.myTable;') RETURNING *;" | ||
} | ||
@@ -138,3 +159,9 @@ ], | ||
context: {options: {omitNull: true}} | ||
}, | ||
}, { | ||
arguments: ['mySchema.myTable', {name: 'foo', birthday: new Date(Date.UTC(2011, 2, 27, 10, 1, 55))}, {id: 2}], | ||
expectation: "UPDATE \"mySchema\".\"myTable\" SET \"name\"='foo',\"birthday\"='2011-03-27 10:01:55.0' WHERE \"id\"=2" | ||
}, { | ||
arguments: ['mySchema.myTable', {name: "foo';DROP TABLE mySchema.myTable;"}, {name: 'foo'}], | ||
expectation: "UPDATE \"mySchema\".\"myTable\" SET \"name\"='foo'';DROP TABLE mySchema.myTable;' WHERE \"name\"='foo'" | ||
} | ||
], | ||
@@ -155,2 +182,8 @@ | ||
expectation: "DELETE FROM \"myTable\" WHERE \"id\" IN (SELECT \"id\" FROM \"myTable\" WHERE \"name\"='foo'';DROP TABLE myTable;' LIMIT 10)" | ||
}, { | ||
arguments: ['mySchema.myTable', {name: 'foo'}], | ||
expectation: "DELETE FROM \"mySchema\".\"myTable\" WHERE \"id\" IN (SELECT \"id\" FROM \"mySchema\".\"myTable\" WHERE \"name\"='foo' LIMIT 1)" | ||
}, { | ||
arguments: ['mySchema.myTable', {name: "foo';DROP TABLE mySchema.myTable;"}, {limit: 10}], | ||
expectation: "DELETE FROM \"mySchema\".\"myTable\" WHERE \"id\" IN (SELECT \"id\" FROM \"mySchema\".\"myTable\" WHERE \"name\"='foo'';DROP TABLE mySchema.myTable;' LIMIT 10)" | ||
} | ||
@@ -176,2 +209,5 @@ ], | ||
expectation: "CREATE FULLTEXT INDEX \"bar\" ON \"User\" (\"username\", \"isAdmin\")" | ||
}, { | ||
arguments: ['mySchema.User', ['username', 'isAdmin']], | ||
expectation: 'CREATE INDEX \"user_username_is_admin\" ON \"mySchema\".\"User\" (\"username\", \"isAdmin\")' | ||
} | ||
@@ -198,2 +234,5 @@ ], | ||
expectation: "DROP INDEX IF EXISTS \"user_foo_bar\"" | ||
}, { | ||
arguments: ['User', 'mySchema.user_foo_bar'], | ||
expectation: "DROP INDEX IF EXISTS \"mySchema\".\"user_foo_bar\"" | ||
} | ||
@@ -200,0 +239,0 @@ ], |
@@ -5,3 +5,3 @@ if (typeof require === 'function') { | ||
, Sequelize = require('../../index') | ||
, dialects = Helpers.getSupportedDialects() | ||
, dialect = Helpers.getTestDialect() | ||
} | ||
@@ -12,35 +12,33 @@ | ||
dialects.forEach(function(dialect) { | ||
describe('BelongsTo@' + dialect, function() { | ||
before(function(done) { | ||
Helpers.initTests({ | ||
beforeComplete: function(sequelize) { | ||
this.sequelize = sequelize | ||
}.bind(this), | ||
onComplete: done | ||
}) | ||
describe("[" + dialect.toUpperCase() + "] BelongsTo", function() { | ||
before(function(done) { | ||
Helpers.initTests({ | ||
beforeComplete: function(sequelize) { | ||
this.sequelize = sequelize | ||
}.bind(this), | ||
onComplete: done | ||
}) | ||
}) | ||
describe('setAssociation', function() { | ||
it('clears the association if null is passed', function(done) { | ||
var User = this.sequelize.define('User', { username: Sequelize.STRING }) | ||
, Task = this.sequelize.define('Task', { title: Sequelize.STRING }) | ||
describe('setAssociation', function() { | ||
it('clears the association if null is passed', function(done) { | ||
var User = this.sequelize.define('User', { username: Sequelize.STRING }) | ||
, Task = this.sequelize.define('Task', { title: Sequelize.STRING }) | ||
Task.belongsTo(User) | ||
Task.belongsTo(User) | ||
this.sequelize.sync({ force: true }).success(function() { | ||
User.create({ username: 'foo' }).success(function(user) { | ||
Task.create({ title: 'task' }).success(function(task) { | ||
task.setUser(user).success(function() { | ||
task.getUser().success(function(user) { | ||
expect(user).not.toEqual(null) | ||
this.sequelize.sync({ force: true }).success(function() { | ||
User.create({ username: 'foo' }).success(function(user) { | ||
Task.create({ title: 'task' }).success(function(task) { | ||
task.setUser(user).success(function() { | ||
task.getUser().success(function(user) { | ||
expect(user).not.toEqual(null) | ||
task.setUser(null).success(function() { | ||
task.getUser().success(function(user) { | ||
expect(user).toEqual(null) | ||
done() | ||
}) | ||
task.setUser(null).success(function() { | ||
task.getUser().success(function(user) { | ||
expect(user).toEqual(null) | ||
done() | ||
}) | ||
}) | ||
}) | ||
}) | ||
@@ -47,0 +45,0 @@ }) |
@@ -5,3 +5,3 @@ if (typeof require === 'function') { | ||
, Sequelize = require('../../index') | ||
, dialects = Helpers.getSupportedDialects() | ||
, dialect = Helpers.getTestDialect() | ||
} | ||
@@ -12,145 +12,115 @@ | ||
dialects.forEach(function(dialect) { | ||
describe('HasMany@' + dialect, function() { | ||
before(function(done) { | ||
var self = this | ||
describe("[" + dialect.toUpperCase() + "] HasMany", function() { | ||
before(function(done) { | ||
var self = this | ||
Helpers.initTests({ | ||
dialect: dialect, | ||
beforeComplete: function(sequelize) { self.sequelize = sequelize }, | ||
onComplete: done | ||
}) | ||
Helpers.initTests({ | ||
dialect: dialect, | ||
beforeComplete: function(sequelize) { self.sequelize = sequelize }, | ||
onComplete: done | ||
}) | ||
}) | ||
describe('(1:N)', function() { | ||
describe('hasSingle', function() { | ||
before(function(done) { | ||
this.Article = this.sequelize.define('Article', { 'title': Sequelize.STRING }) | ||
this.Label = this.sequelize.define('Label', { 'text': Sequelize.STRING }) | ||
describe('(1:N)', function() { | ||
describe('hasSingle', function() { | ||
before(function(done) { | ||
this.Article = this.sequelize.define('Article', { 'title': Sequelize.STRING }) | ||
this.Label = this.sequelize.define('Label', { 'text': Sequelize.STRING }) | ||
this.Article.hasMany(this.Label) | ||
this.Article.hasMany(this.Label) | ||
this.sequelize.sync({ force: true }).success(done) | ||
}) | ||
this.sequelize.sync({ force: true }).success(done) | ||
}) | ||
it('does not have any labels assigned to it initially', function(done) { | ||
var self = this | ||
it('does not have any labels assigned to it initially', function(done) { | ||
var self = this | ||
var chainer = new Sequelize.Utils.QueryChainer([ | ||
this.Article.create({ title: 'Article' }), | ||
this.Label.create({ text: 'Awesomeness' }), | ||
this.Label.create({ text: 'Epicness' }) | ||
]) | ||
chainer.run().success(function(results, article, label1, label2) { | ||
var chainer = new Sequelize.Utils.QueryChainer([ | ||
this.Article.create({ title: 'Article' }), | ||
this.Label.create({ text: 'Awesomeness' }), | ||
this.Label.create({ text: 'Epicness' }) | ||
article.hasLabel(label1), | ||
article.hasLabel(label2) | ||
]) | ||
chainer.run().success(function(results, article, label1, label2) { | ||
var chainer = new Sequelize.Utils.QueryChainer([ | ||
article.hasLabel(label1), | ||
article.hasLabel(label2) | ||
]) | ||
chainer.run().success(function(_, hasLabel1, hasLabel2) { | ||
expect(hasLabel1).toBeFalse() | ||
expect(hasLabel2).toBeFalse() | ||
done() | ||
}) | ||
chainer.run().success(function(_, hasLabel1, hasLabel2) { | ||
expect(hasLabel1).toBeFalse() | ||
expect(hasLabel2).toBeFalse() | ||
done() | ||
}) | ||
}) | ||
}) | ||
it('answers true if the label has been assigned', function(done) { | ||
var self = this | ||
it('answers true if the label has been assigned', function(done) { | ||
var self = this | ||
var chainer = new Sequelize.Utils.QueryChainer([ | ||
this.Article.create({ title: 'Article' }), | ||
this.Label.create({ text: 'Awesomeness' }), | ||
this.Label.create({ text: 'Epicness' }) | ||
]) | ||
chainer.run().success(function(results, article, label1, label2) { | ||
var chainer = new Sequelize.Utils.QueryChainer([ | ||
this.Article.create({ title: 'Article' }), | ||
this.Label.create({ text: 'Awesomeness' }), | ||
this.Label.create({ text: 'Epicness' }) | ||
[ article, 'addLabel', [ label1 ]], | ||
[ article, 'hasLabel', [ label1 ]], | ||
[ article, 'hasLabel', [ label2 ]] | ||
]) | ||
chainer.run().success(function(results, article, label1, label2) { | ||
var chainer = new Sequelize.Utils.QueryChainer([ | ||
[ article, 'addLabel', [ label1 ]], | ||
[ article, 'hasLabel', [ label1 ]], | ||
[ article, 'hasLabel', [ label2 ]] | ||
]) | ||
chainer.runSerially().success(function(_, label1, hasLabel1, hasLabel2) { | ||
expect(hasLabel1).toBeTrue() | ||
expect(hasLabel2).toBeFalse() | ||
done() | ||
}) | ||
chainer.runSerially().success(function(_, label1, hasLabel1, hasLabel2) { | ||
expect(hasLabel1).toBeTrue() | ||
expect(hasLabel2).toBeFalse() | ||
done() | ||
}) | ||
}) | ||
}) | ||
}) | ||
describe('hasAll', function() { | ||
before(function(done) { | ||
this.Article = this.sequelize.define('Article', { 'title': Sequelize.STRING }) | ||
this.Label = this.sequelize.define('Label', { 'text': Sequelize.STRING }) | ||
describe('hasAll', function() { | ||
before(function(done) { | ||
this.Article = this.sequelize.define('Article', { 'title': Sequelize.STRING }) | ||
this.Label = this.sequelize.define('Label', { 'text': Sequelize.STRING }) | ||
this.Article.hasMany(this.Label) | ||
this.Article.hasMany(this.Label) | ||
this.sequelize.sync({ force: true }).success(done) | ||
}) | ||
this.sequelize.sync({ force: true }).success(done) | ||
}) | ||
it('answers false if only some labels have been assigned', function(done) { | ||
var self = this | ||
it('answers false if only some labels have been assigned', function(done) { | ||
var self = this | ||
var chainer = new Sequelize.Utils.QueryChainer([ | ||
this.Article.create({ title: 'Article' }), | ||
this.Label.create({ text: 'Awesomeness' }), | ||
this.Label.create({ text: 'Epicness' }) | ||
]) | ||
var chainer = new Sequelize.Utils.QueryChainer([ | ||
this.Article.create({ title: 'Article' }), | ||
this.Label.create({ text: 'Awesomeness' }), | ||
this.Label.create({ text: 'Epicness' }) | ||
]) | ||
chainer.run().success(function(results, article, label1, label2) { | ||
article.addLabel(label1).success(function() { | ||
article.hasLabels([label1, label2]).success(function(result) { | ||
expect(result).toBeFalse() | ||
done() | ||
}) | ||
chainer.run().success(function(results, article, label1, label2) { | ||
article.addLabel(label1).success(function() { | ||
article.hasLabels([label1, label2]).success(function(result) { | ||
expect(result).toBeFalse() | ||
done() | ||
}) | ||
}) | ||
}) | ||
it('answers true if all label have been assigned', function(done) { | ||
var self = this | ||
var chainer = new Sequelize.Utils.QueryChainer([ | ||
this.Article.create({ title: 'Article' }), | ||
this.Label.create({ text: 'Awesomeness' }), | ||
this.Label.create({ text: 'Epicness' }) | ||
]) | ||
chainer.run().success(function(results, article, label1, label2) { | ||
article.setLabels([label1, label2]).success(function() { | ||
article.hasLabels([label1, label2]).success(function(result) { | ||
expect(result).toBeTrue() | ||
done() | ||
}) | ||
}) | ||
}) | ||
}) | ||
}) | ||
describe('setAssociations', function() { | ||
it("clears associations when passing null to the set-method", function(done) { | ||
var User = this.sequelize.define('User', { username: Sequelize.STRING }) | ||
, Task = this.sequelize.define('Task', { title: Sequelize.STRING }) | ||
it('answers true if all label have been assigned', function(done) { | ||
var self = this | ||
Task.hasMany(User) | ||
var chainer = new Sequelize.Utils.QueryChainer([ | ||
this.Article.create({ title: 'Article' }), | ||
this.Label.create({ text: 'Awesomeness' }), | ||
this.Label.create({ text: 'Epicness' }) | ||
]) | ||
this.sequelize.sync({ force: true }).success(function() { | ||
User.create({ username: 'foo' }).success(function(user) { | ||
Task.create({ title: 'task' }).success(function(task) { | ||
task.setUsers([ user ]).success(function() { | ||
task.getUsers().success(function(_users) { | ||
expect(_users.length).toEqual(1) | ||
task.setUsers(null).success(function() { | ||
task.getUsers().success(function(_users) { | ||
expect(_users.length).toEqual(0) | ||
done() | ||
}) | ||
}) | ||
}) | ||
}) | ||
}) | ||
chainer.run().success(function(results, article, label1, label2) { | ||
article.setLabels([label1, label2]).success(function() { | ||
article.hasLabels([label1, label2]).success(function(result) { | ||
expect(result).toBeTrue() | ||
done() | ||
}) | ||
@@ -160,6 +130,6 @@ }) | ||
}) | ||
}) | ||
it("clears associations when passing null to the set-method with omitNull set to true", function(done) { | ||
this.sequelize.options.omitNull = true | ||
describe('setAssociations', function() { | ||
it("clears associations when passing null to the set-method", function(done) { | ||
var User = this.sequelize.define('User', { username: Sequelize.STRING }) | ||
@@ -189,134 +159,162 @@ , Task = this.sequelize.define('Task', { title: Sequelize.STRING }) | ||
}) | ||
}) | ||
describe("getting assocations with options", function() { | ||
before(function(done) { | ||
var self = this; | ||
it("clears associations when passing null to the set-method with omitNull set to true", function(done) { | ||
this.sequelize.options.omitNull = true | ||
this.User = this.sequelize.define('User', { username: Sequelize.STRING }) | ||
this.Task = this.sequelize.define('Task', { title: Sequelize.STRING, active: Sequelize.BOOLEAN }) | ||
var User = this.sequelize.define('User', { username: Sequelize.STRING }) | ||
, Task = this.sequelize.define('Task', { title: Sequelize.STRING }) | ||
this.User.hasMany(self.Task) | ||
Task.hasMany(User) | ||
this.sequelize.sync({ force: true }).done(function() { | ||
var chainer = new Sequelize.Utils.QueryChainer([ | ||
self.User.create({ username: 'John'}), | ||
self.Task.create({ title: 'Get rich', active: true}), | ||
self.Task.create({ title: 'Die trying', active: false}) | ||
]) | ||
this.sequelize.sync({ force: true }).success(function() { | ||
User.create({ username: 'foo' }).success(function(user) { | ||
Task.create({ title: 'task' }).success(function(task) { | ||
task.setUsers([ user ]).success(function() { | ||
task.getUsers().success(function(_users) { | ||
expect(_users.length).toEqual(1) | ||
chainer.run().success(function (results, john, task1, task2) { | ||
john.setTasks([task1, task2]).success(done) | ||
task.setUsers(null).success(function() { | ||
task.getUsers().success(function(_users) { | ||
expect(_users.length).toEqual(0) | ||
done() | ||
}) | ||
}) | ||
}) | ||
}) | ||
}) | ||
}) | ||
}) | ||
}) | ||
it("gets all associated objects when no options are passed", function(done) { | ||
this.User.find({where: {username: 'John'}}).success(function (john) { | ||
john.getTasks().success(function (tasks) { | ||
expect(tasks.length).toEqual(2) | ||
done(); | ||
}) | ||
describe("getting assocations with options", function() { | ||
before(function(done) { | ||
var self = this; | ||
this.User = this.sequelize.define('User', { username: Sequelize.STRING }) | ||
this.Task = this.sequelize.define('Task', { title: Sequelize.STRING, active: Sequelize.BOOLEAN }) | ||
this.User.hasMany(self.Task) | ||
this.sequelize.sync({ force: true }).done(function() { | ||
var chainer = new Sequelize.Utils.QueryChainer([ | ||
self.User.create({ username: 'John'}), | ||
self.Task.create({ title: 'Get rich', active: true}), | ||
self.Task.create({ title: 'Die trying', active: false}) | ||
]) | ||
chainer.run().success(function (results, john, task1, task2) { | ||
john.setTasks([task1, task2]).success(done) | ||
}) | ||
}) | ||
}) | ||
it("only get objects that fulfill the options", function(done) { | ||
this.User.find({ where: { username: 'John' } }).success(function (john) { | ||
john.getTasks({ where: { active: true }, limit: 10, order: 'id DESC' }).success(function (tasks) { | ||
expect(tasks.length).toEqual(1) | ||
done(); | ||
}) | ||
it("gets all associated objects when no options are passed", function(done) { | ||
this.User.find({where: {username: 'John'}}).success(function (john) { | ||
john.getTasks().success(function (tasks) { | ||
expect(tasks.length).toEqual(2) | ||
done(); | ||
}) | ||
}) | ||
}) | ||
it("only get objects that fulfill the options", function(done) { | ||
this.User.find({ where: { username: 'John' } }).success(function (john) { | ||
john.getTasks({ where: { active: true }, limit: 10, order: 'id DESC' }).success(function (tasks) { | ||
expect(tasks.length).toEqual(1) | ||
done(); | ||
}) | ||
}) | ||
}) | ||
}) | ||
}) | ||
describe('(N:M)', function() { | ||
describe("getting assocations with options", function() { | ||
before(function(done) { | ||
var self = this; | ||
describe('(N:M)', function() { | ||
describe("getting assocations with options", function() { | ||
before(function(done) { | ||
var self = this; | ||
this.User = this.sequelize.define('User', { username: Sequelize.STRING }) | ||
this.Task = this.sequelize.define('Task', { title: Sequelize.STRING, active: Sequelize.BOOLEAN }) | ||
this.User = this.sequelize.define('User', { username: Sequelize.STRING }) | ||
this.Task = this.sequelize.define('Task', { title: Sequelize.STRING, active: Sequelize.BOOLEAN }) | ||
self.User.hasMany(self.Task) | ||
self.Task.hasMany(self.User) | ||
self.User.hasMany(self.Task) | ||
self.Task.hasMany(self.User) | ||
this.sequelize.sync({ force: true }).done(function() { | ||
var chainer = new Sequelize.Utils.QueryChainer([ | ||
self.User.create({ username: 'John'}), | ||
self.Task.create({ title: 'Get rich', active: true}), | ||
self.Task.create({ title: 'Die trying', active: false}) | ||
]) | ||
this.sequelize.sync({ force: true }).done(function() { | ||
var chainer = new Sequelize.Utils.QueryChainer([ | ||
self.User.create({ username: 'John'}), | ||
self.Task.create({ title: 'Get rich', active: true}), | ||
self.Task.create({ title: 'Die trying', active: false}) | ||
]) | ||
chainer.run().success(function (results, john, task1, task2) { | ||
john.setTasks([task1, task2]).success(done) | ||
}) | ||
chainer.run().success(function (results, john, task1, task2) { | ||
john.setTasks([task1, task2]).success(done) | ||
}) | ||
}) | ||
}) | ||
it("gets all associated objects when no options are passed", function(done) { | ||
this.User.find({where: {username: 'John'}}).success(function (john) { | ||
john.getTasks().success(function (tasks) { | ||
expect(tasks.length).toEqual(2) | ||
done(); | ||
}) | ||
it("gets all associated objects when no options are passed", function(done) { | ||
this.User.find({where: {username: 'John'}}).success(function (john) { | ||
john.getTasks().success(function (tasks) { | ||
expect(tasks.length).toEqual(2) | ||
done(); | ||
}) | ||
}) | ||
}) | ||
it("only get objects that fulfill the options", function(done) { | ||
this.User.find({where: {username: 'John'}}).success(function (john) { | ||
john.getTasks({where: {active: true}}).success(function (tasks) { | ||
expect(tasks.length).toEqual(1) | ||
done(); | ||
}) | ||
it("only get objects that fulfill the options", function(done) { | ||
this.User.find({where: {username: 'John'}}).success(function (john) { | ||
john.getTasks({where: {active: true}}).success(function (tasks) { | ||
expect(tasks.length).toEqual(1) | ||
done(); | ||
}) | ||
}) | ||
}) | ||
}) | ||
it("removes the reference id, which was added in the first place", function() { | ||
var User = this.sequelize.define('User', { username: Sequelize.STRING }) | ||
, Task = this.sequelize.define('Task', { title: Sequelize.STRING }) | ||
it("removes the reference id, which was added in the first place", function() { | ||
var User = this.sequelize.define('User', { username: Sequelize.STRING }) | ||
, Task = this.sequelize.define('Task', { title: Sequelize.STRING }) | ||
User.hasMany(Task) | ||
expect(Task.attributes.UserId).toBeDefined() | ||
User.hasMany(Task) | ||
expect(Task.attributes.UserId).toBeDefined() | ||
Task.hasMany(User) | ||
expect(Task.attributes.UserId).not.toBeDefined() | ||
}) | ||
Task.hasMany(User) | ||
expect(Task.attributes.UserId).not.toBeDefined() | ||
}) | ||
it("adds three items to the query chainer when calling sync", function() { | ||
var User = this.sequelize.define('User', { username: Sequelize.STRING }) | ||
, Task = this.sequelize.define('Task', { title: Sequelize.STRING }) | ||
it("adds three items to the query chainer when calling sync", function() { | ||
var User = this.sequelize.define('User', { username: Sequelize.STRING }) | ||
, Task = this.sequelize.define('Task', { title: Sequelize.STRING }) | ||
User.hasMany(Task) | ||
Task.hasMany(User) | ||
User.hasMany(Task) | ||
Task.hasMany(User) | ||
var add = this.spy() | ||
var add = this.spy() | ||
this.stub(Sequelize.Utils, 'QueryChainer').returns({ add: add, run: function(){} }) | ||
this.stub(Sequelize.Utils, 'QueryChainer').returns({ add: add, run: function(){} }) | ||
this.sequelize.sync({ force: true }) | ||
expect(add).toHaveBeenCalledThrice() | ||
}) | ||
this.sequelize.sync({ force: true }) | ||
expect(add).toHaveBeenCalledThrice() | ||
}) | ||
describe('setAssociations', function() { | ||
it("clears associations when passing null to the set-method", function(done) { | ||
var User = this.sequelize.define('User', { username: Sequelize.STRING }) | ||
, Task = this.sequelize.define('Task', { title: Sequelize.STRING }) | ||
describe('setAssociations', function() { | ||
it("clears associations when passing null to the set-method", function(done) { | ||
var User = this.sequelize.define('User', { username: Sequelize.STRING }) | ||
, Task = this.sequelize.define('Task', { title: Sequelize.STRING }) | ||
User.hasMany(Task) | ||
Task.hasMany(User) | ||
User.hasMany(Task) | ||
Task.hasMany(User) | ||
this.sequelize.sync({ force: true }).success(function() { | ||
User.create({ username: 'foo' }).success(function(user) { | ||
Task.create({ title: 'task' }).success(function(task) { | ||
task.setUsers([ user ]).success(function() { | ||
task.getUsers().success(function(_users) { | ||
expect(_users.length).toEqual(1) | ||
this.sequelize.sync({ force: true }).success(function() { | ||
User.create({ username: 'foo' }).success(function(user) { | ||
Task.create({ title: 'task' }).success(function(task) { | ||
task.setUsers([ user ]).success(function() { | ||
task.getUsers().success(function(_users) { | ||
expect(_users.length).toEqual(1) | ||
task.setUsers(null).success(function() { | ||
task.getUsers().success(function(_users) { | ||
expect(_users.length).toEqual(0) | ||
done() | ||
}) | ||
task.setUsers(null).success(function() { | ||
task.getUsers().success(function(_users) { | ||
expect(_users.length).toEqual(0) | ||
done() | ||
}) | ||
@@ -323,0 +321,0 @@ }) |
@@ -5,28 +5,28 @@ if (typeof require === 'function') { | ||
, Helpers = require('../buster-helpers') | ||
, dialects = Helpers.getSupportedDialects() | ||
, dialect = Helpers.getTestDialect() | ||
} | ||
buster.spec.expose() | ||
buster.testRunner.timeout = 500 | ||
buster.testRunner.timeout = 1500 | ||
dialects.forEach(function(dialect) { | ||
describe('HasOne@' + dialect, function() { | ||
before(function(done) { | ||
var self = this | ||
describe("[" + dialect.toUpperCase() + "] HasOne", function() { | ||
before(function(done) { | ||
var self = this | ||
Helpers.initTests({ | ||
dialect: dialect, | ||
beforeComplete: function(sequelize) { self.sequelize = sequelize }, | ||
onComplete: done | ||
}) | ||
Helpers.initTests({ | ||
dialect: dialect, | ||
beforeComplete: function(sequelize) { self.sequelize = sequelize }, | ||
onComplete: done | ||
}) | ||
}) | ||
describe('setAssociation', function() { | ||
it('clears the association if null is passed', function(done) { | ||
var User = this.sequelize.define('User', { username: Sequelize.STRING }) | ||
, Task = this.sequelize.define('Task', { title: Sequelize.STRING }) | ||
describe('setAssociation', function() { | ||
it('clears the association if null is passed', function(done) { | ||
var User = this.sequelize.define('User', { username: Sequelize.STRING }) | ||
, Task = this.sequelize.define('Task', { title: Sequelize.STRING }) | ||
User.hasOne(Task) | ||
User.hasOne(Task) | ||
this.sequelize.sync({ force: true }).success(function() { | ||
this.sequelize.sync({ force: true }).success(function() { | ||
setTimeout(function(){ | ||
User.create({ username: 'foo' }).success(function(user) { | ||
@@ -49,3 +49,3 @@ Task.create({ title: 'task' }).success(function(task) { | ||
}) | ||
}) | ||
}.bind(this), 500) | ||
}) | ||
@@ -52,0 +52,0 @@ }) |
@@ -5,3 +5,3 @@ if (typeof require === 'function') { | ||
, Sequelize = require('../../index') | ||
, dialects = Helpers.getSupportedDialects() | ||
, dialect = Helpers.getTestDialect() | ||
} | ||
@@ -11,26 +11,24 @@ | ||
dialects.forEach(function(dialect) { | ||
describe('Mixin@' + dialect, function() { | ||
before(function(done) { | ||
Helpers.initTests({ | ||
dialect: dialect, | ||
beforeComplete: function(sequelize) { | ||
this.sequelize = sequelize | ||
}.bind(this), | ||
onComplete: done | ||
}) | ||
describe("[" + dialect.toUpperCase() + "] Mixin", function() { | ||
before(function(done) { | ||
Helpers.initTests({ | ||
dialect: dialect, | ||
beforeComplete: function(sequelize) { | ||
this.sequelize = sequelize | ||
}.bind(this), | ||
onComplete: done | ||
}) | ||
}) | ||
describe('getAssociation', function() { | ||
it('returns the respective part of the association for 1:1 associations', function() { | ||
var User = this.sequelize.define('User', {}) | ||
var Task = this.sequelize.define('Task', {}) | ||
describe('getAssociation', function() { | ||
it('returns the respective part of the association for 1:1 associations', function() { | ||
var User = this.sequelize.define('User', {}) | ||
var Task = this.sequelize.define('Task', {}) | ||
User.hasOne(Task) | ||
Task.belongsTo(User) | ||
User.hasOne(Task) | ||
Task.belongsTo(User) | ||
expect(User.getAssociation(Task).target).toEqual(Task) | ||
}) | ||
expect(User.getAssociation(Task).target).toEqual(Task) | ||
}) | ||
}) | ||
}) |
@@ -29,5 +29,5 @@ const Sequelize = require(__dirname + "/../index") | ||
{ | ||
logging: options.logging, | ||
dialect: options.dialect, | ||
port: config[options.dialect].port | ||
logging: options.logging, | ||
dialect: options.dialect, | ||
port: config[options.dialect].port | ||
} | ||
@@ -34,0 +34,0 @@ ) |
@@ -5,3 +5,3 @@ if(typeof require === 'function') { | ||
, Helpers = require('./buster-helpers') | ||
, dialects = Helpers.getSupportedDialects() | ||
, dialect = Helpers.getTestDialect() | ||
} | ||
@@ -11,97 +11,133 @@ | ||
dialects.forEach(function(dialect) { | ||
describe('DAOFactory@' + dialect, function() { | ||
before(function(done) { | ||
Helpers.initTests({ | ||
dialect: dialect, | ||
beforeComplete: function(sequelize, DataTypes) { | ||
this.sequelize = sequelize | ||
this.User = sequelize.define('User', { | ||
username: DataTypes.STRING, | ||
secretValue: DataTypes.STRING, | ||
data: DataTypes.STRING | ||
}) | ||
}.bind(this), | ||
onComplete: function(sequelize) { | ||
this.User.sync({ force: true }).success(done) | ||
}.bind(this) | ||
}) | ||
describe("[" + dialect.toUpperCase() + "] DAOFactory", function() { | ||
before(function(done) { | ||
Helpers.initTests({ | ||
dialect: dialect, | ||
beforeComplete: function(sequelize, DataTypes) { | ||
this.sequelize = sequelize | ||
this.User = sequelize.define('User', { | ||
username: DataTypes.STRING, | ||
secretValue: DataTypes.STRING, | ||
data: DataTypes.STRING | ||
}) | ||
}.bind(this), | ||
onComplete: function() { | ||
this.User.sync({ force: true }).success(done) | ||
}.bind(this) | ||
}) | ||
}) | ||
describe('constructor', function() { | ||
it("uses the passed dao name as tablename if freezeTableName", function() { | ||
var User = this.sequelize.define('FrozenUser', {}, { freezeTableName: true }) | ||
expect(User.tableName).toEqual('FrozenUser') | ||
}) | ||
describe('constructor', function() { | ||
it("uses the passed dao name as tablename if freezeTableName", function() { | ||
var User = this.sequelize.define('FrozenUser', {}, { freezeTableName: true }) | ||
expect(User.tableName).toEqual('FrozenUser') | ||
}) | ||
it("uses the pluralized dao name as tablename unless freezeTableName", function() { | ||
var User = this.sequelize.define('SuperUser', {}, { freezeTableName: false }) | ||
expect(User.tableName).toEqual('SuperUsers') | ||
it("uses the pluralized dao name as tablename unless freezeTableName", function() { | ||
var User = this.sequelize.define('SuperUser', {}, { freezeTableName: false }) | ||
expect(User.tableName).toEqual('SuperUsers') | ||
}) | ||
it("attaches class and instance methods", function() { | ||
var User = this.sequelize.define('UserWithClassAndInstanceMethods', {}, { | ||
classMethods: { doSmth: function(){ return 1 } }, | ||
instanceMethods: { makeItSo: function(){ return 2}} | ||
}) | ||
it("attaches class and instance methods", function() { | ||
var User = this.sequelize.define('UserWithClassAndInstanceMethods', {}, { | ||
classMethods: { doSmth: function(){ return 1 } }, | ||
instanceMethods: { makeItSo: function(){ return 2}} | ||
expect(User.doSmth).toBeDefined() | ||
expect(User.doSmth()).toEqual(1) | ||
expect(User.makeItSo).not.toBeDefined() | ||
expect(User.build().doSmth).not.toBeDefined() | ||
expect(User.build().makeItSo).toBeDefined() | ||
expect(User.build().makeItSo()).toEqual(2) | ||
}) | ||
it("throws an error if 2 autoIncrements are passed", function() { | ||
try { | ||
var User = this.sequelize.define('UserWithTwoAutoIncrements', { | ||
userid: { type: Sequelize.INTEGER, primaryKey: true, autoIncrement: true }, | ||
userscore: { type: Sequelize.INTEGER, primaryKey: true, autoIncrement: true } | ||
}) | ||
// the parse shouldn't execute the following line | ||
// this tests needs to be refactored... | ||
// we need to use expect.toThrow when a later version than 0.6 was released | ||
expect(1).toEqual(2) | ||
} catch(e) { | ||
expect(e.message).toEqual('Invalid DAO definition. Only one autoincrement field allowed.') | ||
} | ||
}) | ||
}) | ||
expect(User.doSmth).toBeDefined() | ||
expect(User.doSmth()).toEqual(1) | ||
expect(User.makeItSo).not.toBeDefined() | ||
expect(User.build().doSmth).not.toBeDefined() | ||
expect(User.build().makeItSo).toBeDefined() | ||
expect(User.build().makeItSo()).toEqual(2) | ||
describe('build', function() { | ||
it("doesn't create database entries", function(done) { | ||
this.User.build({ username: 'John Wayne' }) | ||
this.User.all().success(function(users) { | ||
expect(users.length).toEqual(0) | ||
done() | ||
}) | ||
}) | ||
it("throws an error if 2 autoIncrements are passed", function() { | ||
try { | ||
var User = this.sequelize.define('UserWithTwoAutoIncrements', { | ||
userid: { type: Sequelize.INTEGER, primaryKey: true, autoIncrement: true }, | ||
userscore: { type: Sequelize.INTEGER, primaryKey: true, autoIncrement: true } | ||
}) | ||
// the parse shouldn't execute the following line | ||
// this tests needs to be refactored... | ||
// we need to use expect.toThrow when a later version than 0.6 was released | ||
expect(1).toEqual(2) | ||
} catch(e) { | ||
expect(e.message).toEqual('Invalid DAO definition. Only one autoincrement field allowed.') | ||
} | ||
it("fills the objects with default values", function() { | ||
var Task = this.sequelize.define('Task', { | ||
title: {type: Sequelize.STRING, defaultValue: 'a task!'}, | ||
foo: {type: Sequelize.INTEGER, defaultValue: 2}, | ||
bar: {type: Sequelize.DATE}, | ||
foobar: {type: Sequelize.TEXT, defaultValue: 'asd'}, | ||
flag: {type: Sequelize.BOOLEAN, defaultValue: false} | ||
}) | ||
expect(Task.build().title).toEqual('a task!') | ||
expect(Task.build().foo).toEqual(2) | ||
expect(Task.build().bar).toEqual(null) | ||
expect(Task.build().foobar).toEqual('asd') | ||
expect(Task.build().flag).toEqual(false) | ||
}) | ||
describe('build', function() { | ||
it("doesn't create database entries", function(done) { | ||
this.User.build({ username: 'John Wayne' }) | ||
this.User.all().success(function(users) { | ||
expect(users.length).toEqual(0) | ||
done() | ||
}) | ||
it("stores the the passed values in a special variable", function() { | ||
var user = this.User.build({ username: 'John Wayne' }) | ||
expect(user.selectedValues).toEqual({ username: 'John Wayne' }) | ||
}) | ||
}) | ||
describe('create', function() { | ||
it("doesn't allow duplicated records with unique:true", function(done) { | ||
var User = this.sequelize.define('UserWithUniqueUsername', { | ||
username: { type: Sequelize.STRING, unique: true } | ||
}) | ||
it("fills the objects with default values", function() { | ||
var Task = this.sequelize.define('Task', { | ||
title: {type: Sequelize.STRING, defaultValue: 'a task!'}, | ||
foo: {type: Sequelize.INTEGER, defaultValue: 2}, | ||
bar: {type: Sequelize.DATE}, | ||
foobar: {type: Sequelize.TEXT, defaultValue: 'asd'}, | ||
flag: {type: Sequelize.BOOLEAN, defaultValue: false} | ||
User.sync({ force: true }).success(function() { | ||
User.create({ username:'foo' }).success(function() { | ||
User.create({ username: 'foo' }).error(function(err) { | ||
expect(err).toBeDefined() | ||
Helpers.checkMatchForDialects(dialect, err.message, { | ||
sqlite: /.*SQLITE_CONSTRAINT.*/, | ||
mysql: /.*Duplicate\ entry.*/, | ||
postgres: /.*duplicate\ key\ value.*/ | ||
}) | ||
done() | ||
}) | ||
}) | ||
expect(Task.build().title).toEqual('a task!') | ||
expect(Task.build().foo).toEqual(2) | ||
expect(Task.build().bar).toEqual(null) | ||
expect(Task.build().foobar).toEqual('asd') | ||
expect(Task.build().flag).toEqual(false) | ||
}) | ||
}) | ||
describe('create', function() { | ||
it("doesn't allow duplicated records with unique:true", function(done) { | ||
var User = this.sequelize.define('UserWithUniqueUsername', { | ||
username: { type: Sequelize.STRING, unique: true } | ||
}) | ||
it("raises an error if created object breaks definition contraints", function(done) { | ||
var User = this.sequelize.define('UserWithNonNullSmth', { | ||
username: { type: Sequelize.STRING, unique: true }, | ||
smth: { type: Sequelize.STRING, allowNull: false } | ||
}) | ||
User.sync({ force: true }).success(function() { | ||
User.create({ username:'foo' }).success(function() { | ||
User.create({ username: 'foo' }).error(function(err) { | ||
User.sync({ force: true }).success(function() { | ||
User.create({ username: 'foo', smth: null }).error(function(err) { | ||
expect(err).toBeDefined() | ||
Helpers.checkMatchForDialects(dialect, err.message, { | ||
sqlite: /.*SQLITE_CONSTRAINT.*/, | ||
mysql: "Column 'smth' cannot be null", | ||
postgres: /.*column "smth" violates not-null.*/ | ||
}) | ||
User.create({ username: 'foo', smth: 'foo' }).success(function() { | ||
User.create({ username: 'foo', smth: 'bar' }).error(function(err) { | ||
expect(err).toBeDefined() | ||
@@ -111,4 +147,4 @@ | ||
sqlite: /.*SQLITE_CONSTRAINT.*/, | ||
mysql: /.*Duplicate\ entry.*/, | ||
postgres: /.*duplicate\ key\ value.*/ | ||
mysql: "Duplicate entry 'foo' for key 'username'", | ||
postgres: /.*duplicate key value violates unique constraint.*/ | ||
}) | ||
@@ -121,159 +157,119 @@ | ||
}) | ||
}) | ||
it("raises an error if created object breaks definition contraints", function(done) { | ||
var User = this.sequelize.define('UserWithNonNullSmth', { | ||
username: { type: Sequelize.STRING, unique: true }, | ||
smth: { type: Sequelize.STRING, allowNull: false } | ||
}) | ||
User.sync({ force: true }).success(function() { | ||
User.create({ username: 'foo', smth: null }).error(function(err) { | ||
expect(err).toBeDefined() | ||
Helpers.checkMatchForDialects(dialect, err.message, { | ||
sqlite: /.*SQLITE_CONSTRAINT.*/, | ||
mysql: "Column 'smth' cannot be null", | ||
postgres: /.*column "smth" violates not-null.*/ | ||
}) | ||
User.create({ username: 'foo', smth: 'foo' }).success(function() { | ||
User.create({ username: 'foo', smth: 'bar' }).error(function(err) { | ||
expect(err).toBeDefined() | ||
Helpers.checkMatchForDialects(dialect, err.message, { | ||
sqlite: /.*SQLITE_CONSTRAINT.*/, | ||
mysql: "Duplicate entry 'foo' for key 'username'", | ||
postgres: /.*duplicate key value violates unique constraint.*/ | ||
}) | ||
done() | ||
}) | ||
}) | ||
}) | ||
}) | ||
it('sets auto increment fields', function(done) { | ||
var User = this.sequelize.define('UserWithAutoIncrementField', { | ||
userid: { type: Sequelize.INTEGER, autoIncrement: true, primaryKey: true, allowNull: false } | ||
}) | ||
it('sets auto increment fields', function(done) { | ||
var User = this.sequelize.define('UserWithAutoIncrementField', { | ||
userid: { type: Sequelize.INTEGER, autoIncrement: true, primaryKey: true, allowNull: false } | ||
}) | ||
User.sync({ force: true }).success(function() { | ||
User.create({}).on('success', function(user) { | ||
expect(user.userid).toEqual(1) | ||
User.sync({ force: true }).success(function() { | ||
User.create({}).on('success', function(user) { | ||
expect(user.userid).toEqual(1) | ||
User.create({}).on('success', function(user) { | ||
expect(user.userid).toEqual(2) | ||
done() | ||
}) | ||
expect(user.userid).toEqual(2) | ||
done() | ||
}) | ||
}) | ||
}) | ||
}) | ||
it('allows the usage of options as attribute', function(done) { | ||
var User = this.sequelize.define('UserWithNameAndOptions', { | ||
name: Sequelize.STRING, | ||
options: Sequelize.TEXT | ||
}) | ||
var options = JSON.stringify({ foo: 'bar', bar: 'foo' }) | ||
User.sync({ force: true }).success(function() { | ||
User | ||
.create({ name: 'John Doe', options: options }) | ||
.success(function(user) { | ||
expect(user.options).toEqual(options) | ||
done() | ||
}) | ||
}) | ||
it('allows the usage of options as attribute', function(done) { | ||
var User = this.sequelize.define('UserWithNameAndOptions', { | ||
name: Sequelize.STRING, | ||
options: Sequelize.TEXT | ||
}) | ||
it('allows sql logging', function(done) { | ||
var User = this.sequelize.define('UserWithUniqueNameAndNonNullSmth', { | ||
name: {type: Sequelize.STRING, unique: true}, | ||
smth: {type: Sequelize.STRING, allowNull: false} | ||
}) | ||
var options = JSON.stringify({ foo: 'bar', bar: 'foo' }) | ||
User.sync({ force: true }).success(function() { | ||
User | ||
.create({ name: 'Fluffy Bunny', smth: 'else' }) | ||
.on('sql', function(sql) { | ||
expect(sql).toBeDefined() | ||
expect(sql.toUpperCase().indexOf("INSERT")).toBeGreaterThan(-1) | ||
done() | ||
}) | ||
User.sync({ force: true }).success(function() { | ||
User | ||
.create({ name: 'John Doe', options: options }) | ||
.success(function(user) { | ||
expect(user.options).toEqual(options) | ||
done() | ||
}) | ||
}) | ||
}) | ||
it('should only store the values passed in the witelist', function(done) { | ||
var self = this | ||
, data = { username: 'Peter', secretValue: '42' } | ||
it('allows sql logging', function(done) { | ||
var User = this.sequelize.define('UserWithUniqueNameAndNonNullSmth', { | ||
name: {type: Sequelize.STRING, unique: true}, | ||
smth: {type: Sequelize.STRING, allowNull: false} | ||
}) | ||
this.User.create(data, ['username']).success(function(user) { | ||
self.User.find(user.id).success(function(_user) { | ||
expect(_user.username).toEqual(data.username) | ||
expect(_user.secretValue).not.toEqual(data.secretValue) | ||
expect(_user.secretValue).toEqual(null) | ||
User.sync({ force: true }).success(function() { | ||
User | ||
.create({ name: 'Fluffy Bunny', smth: 'else' }) | ||
.on('sql', function(sql) { | ||
expect(sql).toBeDefined() | ||
expect(sql.toUpperCase().indexOf("INSERT")).toBeGreaterThan(-1) | ||
done() | ||
}) | ||
}) | ||
}) | ||
}) | ||
it('should store all values if no whitelist is specified', function(done) { | ||
var self = this | ||
, data = { username: 'Peter', secretValue: '42' } | ||
it('should only store the values passed in the witelist', function(done) { | ||
var self = this | ||
, data = { username: 'Peter', secretValue: '42' } | ||
this.User.create(data).success(function(user) { | ||
self.User.find(user.id).success(function(_user) { | ||
expect(_user.username).toEqual(data.username) | ||
expect(_user.secretValue).toEqual(data.secretValue) | ||
done() | ||
}) | ||
this.User.create(data, ['username']).success(function(user) { | ||
self.User.find(user.id).success(function(_user) { | ||
expect(_user.username).toEqual(data.username) | ||
expect(_user.secretValue).not.toEqual(data.secretValue) | ||
expect(_user.secretValue).toEqual(null) | ||
done() | ||
}) | ||
}) | ||
}) | ||
it('saves data with single quote', function(done) { | ||
var quote = "single'quote" | ||
, self = this | ||
it('should store all values if no whitelist is specified', function(done) { | ||
var self = this | ||
, data = { username: 'Peter', secretValue: '42' } | ||
this.User.create({ data: quote }).success(function(user) { | ||
expect(user.data).toEqual(quote, 'memory single quote') | ||
self.User.find({where: { id: user.id }}).success(function(user) { | ||
expect(user.data).toEqual(quote, 'SQL single quote') | ||
done() | ||
}) | ||
this.User.create(data).success(function(user) { | ||
self.User.find(user.id).success(function(_user) { | ||
expect(_user.username).toEqual(data.username) | ||
expect(_user.secretValue).toEqual(data.secretValue) | ||
done() | ||
}) | ||
}) | ||
}) | ||
it('saves data with double quote', function(done) { | ||
var quote = 'double"quote' | ||
, self = this | ||
it('saves data with single quote', function(done) { | ||
var quote = "single'quote" | ||
, self = this | ||
this.User.create({ data: quote }).success(function(user) { | ||
expect(user.data).toEqual(quote, 'memory double quote') | ||
this.User.create({ data: quote }).success(function(user) { | ||
expect(user.data).toEqual(quote, 'memory single quote') | ||
self.User.find({where: { id: user.id }}).success(function(user) { | ||
expect(user.data).toEqual(quote, 'SQL double quote') | ||
done() | ||
}) | ||
self.User.find({where: { id: user.id }}).success(function(user) { | ||
expect(user.data).toEqual(quote, 'SQL single quote') | ||
done() | ||
}) | ||
}) | ||
}) | ||
it('saves stringified JSON data', function(done) { | ||
var json = JSON.stringify({ key: 'value' }) | ||
, self = this | ||
it('saves data with double quote', function(done) { | ||
var quote = 'double"quote' | ||
, self = this | ||
this.User.create({ data: json }).success(function(user) { | ||
expect(user.data).toEqual(json, 'memory data') | ||
self.User.find({where: { id: user.id }}).success(function(user) { | ||
expect(user.data).toEqual(json, 'SQL data') | ||
done() | ||
}) | ||
this.User.create({ data: quote }).success(function(user) { | ||
expect(user.data).toEqual(quote, 'memory double quote') | ||
self.User.find({where: { id: user.id }}).success(function(user) { | ||
expect(user.data).toEqual(quote, 'SQL double quote') | ||
done() | ||
}) | ||
}) | ||
}) | ||
it('stores the current date in createdAt', function(done) { | ||
this.User.create({ username: 'foo' }).success(function(user) { | ||
expect(parseInt(+user.createdAt/5000)).toEqual(parseInt(+new Date()/5000)) | ||
it('saves stringified JSON data', function(done) { | ||
var json = JSON.stringify({ key: 'value' }) | ||
, self = this | ||
this.User.create({ data: json }).success(function(user) { | ||
expect(user.data).toEqual(json, 'memory data') | ||
self.User.find({where: { id: user.id }}).success(function(user) { | ||
expect(user.data).toEqual(json, 'SQL data') | ||
done() | ||
@@ -284,104 +280,171 @@ }) | ||
describe('find', function find() { | ||
before(function(done) { | ||
this.User.create({ | ||
username: 'barfooz' | ||
}).success(function(user) { | ||
this.user = user | ||
done() | ||
}.bind(this)) | ||
it('stores the current date in createdAt', function(done) { | ||
this.User.create({ username: 'foo' }).success(function(user) { | ||
expect(parseInt(+user.createdAt/5000)).toEqual(parseInt(+new Date()/5000)) | ||
done() | ||
}) | ||
}) | ||
}) | ||
it('returns a single dao', function(done) { | ||
this.User.find(this.user.id).success(function(user) { | ||
expect(Array.isArray(user)).toBeFalsy() | ||
expect(user.id).toEqual(this.user.id) | ||
expect(user.id).toEqual(1) | ||
done() | ||
}.bind(this)) | ||
describe('find', function find() { | ||
before(function(done) { | ||
this.User.create({ | ||
username: 'barfooz' | ||
}).success(function(user) { | ||
this.user = user | ||
done() | ||
}.bind(this)) | ||
}) | ||
it('returns a single dao', function(done) { | ||
this.User.find(this.user.id).success(function(user) { | ||
expect(Array.isArray(user)).toBeFalsy() | ||
expect(user.id).toEqual(this.user.id) | ||
expect(user.id).toEqual(1) | ||
done() | ||
}.bind(this)) | ||
}) | ||
it("should make aliased attributes available", function(done) { | ||
this.User.find({ | ||
where: { id: 1 }, | ||
attributes: ['id', ['username', 'name']] | ||
}).success(function(user) { | ||
expect(user.name).toEqual('barfooz') | ||
done() | ||
}) | ||
}) | ||
it("should make aliased attributes available", function(done) { | ||
this.User.find({ | ||
where: { id: 1 }, | ||
attributes: ['id', ['username', 'name']] | ||
}).success(function(user) { | ||
expect(user.name).toEqual('barfooz') | ||
done() | ||
}) | ||
it('finds a specific user via where option', function(done) { | ||
this.User.find({ where: { username: 'barfooz' } }).success(function(user) { | ||
expect(user.username).toEqual('barfooz') | ||
done() | ||
}) | ||
}) | ||
it('finds a specific user via where option', function(done) { | ||
this.User.find({ where: { username: 'barfooz' } }).success(function(user) { | ||
expect(user.username).toEqual('barfooz') | ||
done() | ||
}) | ||
it("doesn't find a user if conditions are not matching", function(done) { | ||
this.User.find({ where: { username: 'foo' } }).success(function(user) { | ||
expect(user).toBeNull() | ||
done() | ||
}) | ||
}) | ||
it("doesn't find a user if conditions are not matching", function(done) { | ||
this.User.find({ where: { username: 'foo' } }).success(function(user) { | ||
expect(user).toBeNull() | ||
it('allows sql logging', function(done) { | ||
this.User.find({ where: { username: 'foo' } }) | ||
.on('sql', function(sql) { | ||
expect(sql).toBeDefined() | ||
expect(sql.toUpperCase().indexOf("SELECT")).toBeGreaterThan(-1) | ||
done() | ||
}) | ||
}) | ||
it('ignores passed limit option', function(done) { | ||
this.User.find({ limit: 10 }).success(function(user) { | ||
// it returns an object instead of an array | ||
expect(Array.isArray(user)).toBeFalsy() | ||
expect(user.hasOwnProperty('username')).toBeTruthy() | ||
done() | ||
}) | ||
}) | ||
it('allows sql logging', function(done) { | ||
this.User.find({ where: { username: 'foo' } }) | ||
.on('sql', function(sql) { | ||
expect(sql).toBeDefined() | ||
expect(sql.toUpperCase().indexOf("SELECT")).toBeGreaterThan(-1) | ||
it('finds entries via primary keys', function(done) { | ||
var User = this.sequelize.define('UserWithPrimaryKey', { | ||
identifier: {type: Sequelize.STRING, primaryKey: true}, | ||
name: Sequelize.STRING | ||
}) | ||
User.sync({ force: true }).success(function() { | ||
User.create({ | ||
identifier: 'an identifier', | ||
name: 'John' | ||
}).success(function(u) { | ||
expect(u.id).not.toBeDefined() | ||
User.find('an identifier').success(function(u2) { | ||
expect(u2.identifier).toEqual('an identifier') | ||
expect(u2.name).toEqual('John') | ||
done() | ||
}) | ||
}) | ||
}) | ||
}) | ||
it('ignores passed limit option', function(done) { | ||
this.User.find({ limit: 10 }).success(function(user) { | ||
// it returns an object instead of an array | ||
expect(Array.isArray(user)).toBeFalsy() | ||
expect(user.hasOwnProperty('username')).toBeTruthy() | ||
it('//returns the selected fields as instance.selectedValues', function(done) { | ||
this.User.create({ | ||
username: 'JohnXOXOXO' | ||
}).success(function() { | ||
this.User.find({ | ||
where: { username: 'JohnXOXOXO' }, | ||
select: ['username'] | ||
}).success(function(user) { | ||
expect(user.selectedValues).toEqual({ username: 'JohnXOXOXO' }) | ||
done() | ||
}) | ||
}) | ||
}.bind(this)) | ||
}) | ||
it('finds entries via primary keys', function(done) { | ||
var User = this.sequelize.define('UserWithPrimaryKey', { | ||
identifier: {type: Sequelize.STRING, primaryKey: true}, | ||
describe('association fetching', function() { | ||
before(function() { | ||
this.Task = this.sequelize.define('Task', { | ||
title: Sequelize.STRING | ||
}) | ||
this.User = this.sequelize.define('UserWithName', { | ||
name: Sequelize.STRING | ||
}) | ||
}) | ||
User.sync({ force: true }).success(function() { | ||
User.create({ | ||
identifier: 'an identifier', | ||
name: 'John' | ||
}).success(function(u) { | ||
expect(u.id).not.toBeDefined() | ||
it('fetches associated objects for 1:1 associations (1st direction)', function(done) { | ||
this.User.hasOne(this.Task) | ||
this.Task.belongsTo(this.User) | ||
User.find('an identifier').success(function(u2) { | ||
expect(u2.identifier).toEqual('an identifier') | ||
expect(u2.name).toEqual('John') | ||
done() | ||
}) | ||
}) | ||
}) | ||
this.sequelize.sync({ force: true }).success(function() { | ||
this.User.create({ name: 'barfooz' }).success(function(user) { | ||
this.Task.create({ title: 'task' }).success(function(task) { | ||
user.setTask(task).success(function() { | ||
this.User.find({ | ||
where: { 'UserWithNames.id': 1 }, | ||
include: [ 'Task' ] | ||
}).success(function(user) { | ||
expect(user.task).toBeDefined() | ||
expect(user.task.id).toEqual(task.id) | ||
done() | ||
}) | ||
}.bind(this)) //- setTask | ||
}.bind(this)) //- Task.create | ||
}.bind(this)) //- User.create | ||
}.bind(this)) //- sequelize.sync | ||
}) | ||
describe('association fetching', function() { | ||
before(function() { | ||
this.Task = this.sequelize.define('Task', { | ||
title: Sequelize.STRING | ||
}) | ||
it('fetches associated objects for 1:1 associations (2nd direction)', function(done) { | ||
this.User.hasOne(this.Task) | ||
this.Task.belongsTo(this.User) | ||
this.User = this.sequelize.define('UserWithName', { | ||
name: Sequelize.STRING | ||
}) | ||
}) | ||
this.sequelize.sync({ force: true }).success(function() { | ||
this.User.create({ name: 'barfooz' }).success(function(user) { | ||
this.Task.create({ title: 'task' }).success(function(task) { | ||
user.setTask(task).success(function() { | ||
this.Task.find({ | ||
where: { 'Tasks.id': 1 }, | ||
include: [ 'UserWithName' ] | ||
}).success(function(task) { | ||
expect(task.userWithName).toBeDefined() | ||
expect(task.userWithName.id).toEqual(user.id) | ||
done() | ||
}) | ||
}.bind(this)) //- setTask | ||
}.bind(this)) //- Task.create | ||
}.bind(this)) //- User.create | ||
}.bind(this)) //- sequelize.sync | ||
}) | ||
it('fetches associated objects for 1:1 associations (1st direction)', function(done) { | ||
this.User.hasOne(this.Task) | ||
this.Task.belongsTo(this.User) | ||
it('fetches associated objects for 1:N associations (1st direction)', function(done) { | ||
this.User.hasMany(this.Task) | ||
this.Task.belongsTo(this.User) | ||
this.sequelize.sync({ force: true }).success(function() { | ||
this.User.create({ name: 'barfooz' }).success(function(user) { | ||
this.Task.create({ title: 'task' }).success(function(task) { | ||
user.setTask(task).success(function() { | ||
this.sequelize.sync({ force: true }).success(function() { | ||
this.User.create({ name: 'barfooz' }).success(function(user) { | ||
this.Task.create({ title: 'task1' }).success(function(task1) { | ||
this.Task.create({ title: 'task2' }).success(function(task2) { | ||
user.setTasks([task1, task2]).success(function() { | ||
this.User.find({ | ||
@@ -391,4 +454,8 @@ where: { 'UserWithNames.id': 1 }, | ||
}).success(function(user) { | ||
expect(user.task).toBeDefined() | ||
expect(user.task.id).toEqual(task.id) | ||
expect(user.tasks).toBeDefined() | ||
expect( | ||
user.tasks.map(function(t) { return t.id }) | ||
).toEqual( | ||
[ task1.id, task2.id ] | ||
) | ||
done() | ||
@@ -398,14 +465,16 @@ }) | ||
}.bind(this)) //- Task.create | ||
}.bind(this)) //- User.create | ||
}.bind(this)) //- sequelize.sync | ||
}) | ||
}.bind(this)) //- Task.create | ||
}.bind(this)) //- User.create | ||
}.bind(this)) //- sequelize.sync | ||
}) | ||
it('fetches associated objects for 1:1 associations (2nd direction)', function(done) { | ||
this.User.hasOne(this.Task) | ||
this.Task.belongsTo(this.User) | ||
it('fetches associated objects for 1:N associations (2nd direction)', function(done) { | ||
this.User.hasMany(this.Task) | ||
this.Task.belongsTo(this.User) | ||
this.sequelize.sync({ force: true }).success(function() { | ||
this.User.create({ name: 'barfooz' }).success(function(user) { | ||
this.Task.create({ title: 'task' }).success(function(task) { | ||
user.setTask(task).success(function() { | ||
this.sequelize.sync({ force: true }).success(function() { | ||
this.User.create({ name: 'barfooz' }).success(function(user) { | ||
this.Task.create({ title: 'task1' }).success(function(task1) { | ||
this.Task.create({ title: 'task2' }).success(function(task2) { | ||
user.setTasks([task1, task2]).success(function() { | ||
this.Task.find({ | ||
@@ -416,3 +485,3 @@ where: { 'Tasks.id': 1 }, | ||
expect(task.userWithName).toBeDefined() | ||
expect(task.userWithName.id).toEqual(user.id) | ||
expect(task.userWithName.name).toEqual(user.name) | ||
done() | ||
@@ -422,140 +491,164 @@ }) | ||
}.bind(this)) //- Task.create | ||
}.bind(this)) //- User.create | ||
}.bind(this)) //- sequelize.sync | ||
}) | ||
}.bind(this)) //- Task.create | ||
}.bind(this)) //- User.create | ||
}.bind(this)) //- sequelize.sync | ||
}) | ||
it('fetches associated objects for 1:N associations (1st direction)', function(done) { | ||
this.User.hasMany(this.Task) | ||
this.Task.belongsTo(this.User) | ||
it('fetches associated objects for N:M associations (1st direction)', function(done) { | ||
this.User.hasMany(this.Task) | ||
this.Task.hasMany(this.User) | ||
this.sequelize.sync({ force: true }).success(function() { | ||
this.User.create({ name: 'barfooz' }).success(function(user) { | ||
this.Task.create({ title: 'task1' }).success(function(task1) { | ||
this.Task.create({ title: 'task2' }).success(function(task2) { | ||
user.setTasks([task1, task2]).success(function() { | ||
this.User.find({ | ||
where: { 'UserWithNames.id': 1 }, | ||
include: [ 'Task' ] | ||
}).success(function(user) { | ||
expect(user.tasks).toBeDefined() | ||
expect( | ||
user.tasks.map(function(t) { return t.id }) | ||
).toEqual( | ||
[ task1.id, task2.id ] | ||
) | ||
done() | ||
}) | ||
}.bind(this)) //- setTask | ||
}.bind(this)) //- Task.create | ||
this.sequelize.sync({ force: true }).success(function() { | ||
this.User.create({ name: 'barfooz' }).success(function(user1) { | ||
this.Task.create({ title: 'task1' }).success(function(task1) { | ||
this.Task.create({ title: 'task2' }).success(function(task2) { | ||
user1.setTasks([task1, task2]).success(function() { | ||
this.User.find({ | ||
where: { 'UserWithNames.id': user1.id }, | ||
include: [ 'Task' ] | ||
}).success(function(user) { | ||
expect(user.tasks).toBeDefined() | ||
expect( | ||
user.tasks.map(function(t) { return t.id }) | ||
).toEqual( | ||
[ task1.id, task2.id ] | ||
) | ||
done() | ||
}) | ||
}.bind(this)) //- setTask | ||
}.bind(this)) //- Task.create | ||
}.bind(this)) //- User.create | ||
}.bind(this)) //- sequelize.sync | ||
}) | ||
}.bind(this)) //- Task.create | ||
it('fetches associated objects for 1:N associations (2nd direction)', function(done) { | ||
this.User.hasMany(this.Task) | ||
this.Task.belongsTo(this.User) | ||
}.bind(this)) //- User.create | ||
}.bind(this)) //- sequelize.sync | ||
}) | ||
this.sequelize.sync({ force: true }).success(function() { | ||
this.User.create({ name: 'barfooz' }).success(function(user) { | ||
this.Task.create({ title: 'task1' }).success(function(task1) { | ||
this.Task.create({ title: 'task2' }).success(function(task2) { | ||
user.setTasks([task1, task2]).success(function() { | ||
this.Task.find({ | ||
where: { 'Tasks.id': 1 }, | ||
include: [ 'UserWithName' ] | ||
}).success(function(task) { | ||
expect(task.userWithName).toBeDefined() | ||
expect(task.userWithName.name).toEqual(user.name) | ||
done() | ||
}) | ||
}.bind(this)) //- setTask | ||
}.bind(this)) //- Task.create | ||
it('fetches associated objects for N:M associations (2nd direction)', function(done) { | ||
this.User.hasMany(this.Task) | ||
this.Task.hasMany(this.User) | ||
this.sequelize.sync({ force: true }).success(function() { | ||
this.User.create({ name: 'barfooz' }).success(function(user1) { | ||
this.Task.create({ title: 'task1' }).success(function(task1) { | ||
this.Task.create({ title: 'task2' }).success(function(task2) { | ||
user1.setTasks([task1, task2]).success(function() { | ||
this.Task.find({ | ||
where: { 'Tasks.id': task1.id }, | ||
include: [ 'UserWithName' ] | ||
}).success(function(task) { | ||
expect(task.userWithNames).toBeDefined() | ||
expect( | ||
task.userWithNames.map(function(u) { return u.id }) | ||
).toEqual( | ||
[ user1.id ] | ||
) | ||
done() | ||
}) | ||
}.bind(this)) //- setTask | ||
}.bind(this)) //- Task.create | ||
}.bind(this)) //- User.create | ||
}.bind(this)) //- sequelize.sync | ||
}) | ||
}.bind(this)) //- Task.create | ||
it('fetches associated objects for N:M associations (1st direction)', function(done) { | ||
this.User.hasMany(this.Task) | ||
this.Task.hasMany(this.User) | ||
}.bind(this)) //- User.create | ||
}.bind(this)) //- sequelize.sync | ||
}) | ||
}) | ||
this.sequelize.sync({ force: true }).success(function() { | ||
this.User.create({ name: 'barfooz' }).success(function(user1) { | ||
this.Task.create({ title: 'task1' }).success(function(task1) { | ||
this.Task.create({ title: 'task2' }).success(function(task2) { | ||
user1.setTasks([task1, task2]).success(function() { | ||
this.User.find({ | ||
where: { 'UserWithNames.id': user1.id }, | ||
include: [ 'Task' ] | ||
}).success(function(user) { | ||
expect(user.tasks).toBeDefined() | ||
expect( | ||
user.tasks.map(function(t) { return t.id }) | ||
).toEqual( | ||
[ task1.id, task2.id ] | ||
) | ||
done() | ||
}) | ||
}.bind(this)) //- setTask | ||
}.bind(this)) //- Task.create | ||
}.bind(this)) //- Task.create | ||
}) //- describe: find | ||
}.bind(this)) //- User.create | ||
}.bind(this)) //- sequelize.sync | ||
describe('findAll', function findAll() { | ||
describe('include', function() { | ||
before(function() { | ||
this.Task = this.sequelize.define('Task', { | ||
title: Sequelize.STRING | ||
}) | ||
it('fetches associated objects for N:M associations (2nd direction)', function(done) { | ||
this.User.hasMany(this.Task) | ||
this.Task.hasMany(this.User) | ||
this.User = this.sequelize.define('UserWithName', { | ||
name: Sequelize.STRING | ||
}) | ||
}) | ||
this.sequelize.sync({ force: true }).success(function() { | ||
this.User.create({ name: 'barfooz' }).success(function(user1) { | ||
it('fetches data only for the relevant where clause', function(done) { | ||
this.User.hasOne(this.Task) | ||
this.Task.belongsTo(this.User) | ||
this.Task.create({ title: 'task1' }).success(function(task1) { | ||
this.Task.create({ title: 'task2' }).success(function(task2) { | ||
user1.setTasks([task1, task2]).success(function() { | ||
this.Task.find({ | ||
where: { 'Tasks.id': task1.id }, | ||
include: [ 'UserWithName' ] | ||
}).success(function(task) { | ||
expect(task.userWithNames).toBeDefined() | ||
expect( | ||
task.userWithNames.map(function(u) { return u.id }) | ||
).toEqual( | ||
[ user1.id ] | ||
) | ||
done() | ||
}) | ||
}.bind(this)) //- setTask | ||
}.bind(this)) //- Task.create | ||
}.bind(this)) //- Task.create | ||
this.sequelize.sync({ force: true }).success(function() { | ||
this.User.create({ name: 'barfooz' }).success(function(user1) { | ||
this.User.create({ name: 'barfooz' }).success(function(user2) { | ||
this.Task.create({ title: 'task' }).success(function(task) { | ||
var where = [Sequelize.Utils.addTicks(this.User.tableName) + ".`id`=?", user1.id] | ||
}.bind(this)) //- User.create | ||
}.bind(this)) //- sequelize.sync | ||
}) | ||
if (dialect === 'postgres') { | ||
where = ['"' + this.User.tableName + '"."id"=?', user1.id] | ||
} | ||
this.User.findAll({ | ||
where: where, | ||
include: [ 'Task' ] | ||
}).success(function(users){ | ||
expect(users.length).toEqual(1) | ||
// console.log(users[0]) | ||
done() | ||
}.bind(this)) | ||
}.bind(this)) | ||
}.bind(this)) | ||
}.bind(this)) | ||
}.bind(this)) | ||
}) | ||
}) //- describe: find | ||
describe('findAll', function findAll() { | ||
describe('association fetching', function() { | ||
before(function() { | ||
this.Task = this.sequelize.define('Task', { | ||
title: Sequelize.STRING | ||
}) | ||
it('fetches associated objects for 1:1 associations (1st direction)', function(done) { | ||
this.User.hasOne(this.Task) | ||
this.Task.belongsTo(this.User) | ||
this.User = this.sequelize.define('UserWithName', { | ||
name: Sequelize.STRING | ||
}) | ||
}) | ||
this.sequelize.sync({ force: true }).success(function() { | ||
this.User.create({ name: 'barfooz' }).success(function(user) { | ||
this.Task.create({ title: 'task' }).success(function(task) { | ||
user.setTask(task).success(function() { | ||
this.User.findAll({ | ||
where: { 'UserWithNames.id': 1 }, | ||
include: [ 'Task' ] | ||
}).success(function(users) { | ||
expect(users[0].task).toBeDefined() | ||
expect(users[0].task.id).toEqual(task.id) | ||
done() | ||
}) | ||
}.bind(this)) //- setTask | ||
}.bind(this)) //- Task.create | ||
}.bind(this)) //- User.create | ||
}.bind(this)) //- sequelize.sync | ||
}) | ||
it('fetches associated objects for 1:1 associations (1st direction)', function(done) { | ||
this.User.hasOne(this.Task) | ||
this.Task.belongsTo(this.User) | ||
it('fetches associated objects for 1:1 associations (2nd direction)', function(done) { | ||
this.User.hasOne(this.Task) | ||
this.Task.belongsTo(this.User) | ||
this.sequelize.sync({ force: true }).success(function() { | ||
this.User.create({ name: 'barfooz' }).success(function(user) { | ||
this.Task.create({ title: 'task' }).success(function(task) { | ||
user.setTask(task).success(function() { | ||
this.sequelize.sync({ force: true }).success(function() { | ||
this.User.create({ name: 'barfooz' }).success(function(user) { | ||
this.Task.create({ title: 'task' }).success(function(task) { | ||
user.setTask(task).success(function() { | ||
this.Task.findAll({ | ||
where: { 'Tasks.id': 1 }, | ||
include: [ 'UserWithName' ] | ||
}).success(function(tasks) { | ||
expect(tasks[0].userWithName).toBeDefined() | ||
expect(tasks[0].userWithName.id).toEqual(user.id) | ||
done() | ||
}) | ||
}.bind(this)) //- setTask | ||
}.bind(this)) //- Task.create | ||
}.bind(this)) //- User.create | ||
}.bind(this)) //- sequelize.sync | ||
}) | ||
it('fetches associated objects for 1:N associations (1st direction)', function(done) { | ||
this.User.hasMany(this.Task) | ||
this.Task.belongsTo(this.User) | ||
this.sequelize.sync({ force: true }).success(function() { | ||
this.User.create({ name: 'barfooz' }).success(function(user) { | ||
this.Task.create({ title: 'task1' }).success(function(task1) { | ||
this.Task.create({ title: 'task2' }).success(function(task2) { | ||
user.setTasks([task1, task2]).success(function() { | ||
this.User.findAll({ | ||
@@ -565,4 +658,8 @@ where: { 'UserWithNames.id': 1 }, | ||
}).success(function(users) { | ||
expect(users[0].task).toBeDefined() | ||
expect(users[0].task.id).toEqual(task.id) | ||
expect(users[0].tasks).toBeDefined() | ||
expect( | ||
users[0].tasks.map(function(t) { return t.id }) | ||
).toEqual( | ||
[ task1.id, task2.id ] | ||
) | ||
done() | ||
@@ -572,14 +669,16 @@ }) | ||
}.bind(this)) //- Task.create | ||
}.bind(this)) //- User.create | ||
}.bind(this)) //- sequelize.sync | ||
}) | ||
}.bind(this)) //- Task.create | ||
}.bind(this)) //- User.create | ||
}.bind(this)) //- sequelize.sync | ||
}) | ||
it('fetches associated objects for 1:1 associations (2nd direction)', function(done) { | ||
this.User.hasOne(this.Task) | ||
this.Task.belongsTo(this.User) | ||
it('fetches associated objects for 1:N associations (2nd direction)', function(done) { | ||
this.User.hasMany(this.Task) | ||
this.Task.belongsTo(this.User) | ||
this.sequelize.sync({ force: true }).success(function() { | ||
this.User.create({ name: 'barfooz' }).success(function(user) { | ||
this.Task.create({ title: 'task' }).success(function(task) { | ||
user.setTask(task).success(function() { | ||
this.sequelize.sync({ force: true }).success(function() { | ||
this.User.create({ name: 'barfooz' }).success(function(user) { | ||
this.Task.create({ title: 'task1' }).success(function(task1) { | ||
this.Task.create({ title: 'task2' }).success(function(task2) { | ||
user.setTasks([task1, task2]).success(function() { | ||
this.Task.findAll({ | ||
@@ -590,3 +689,3 @@ where: { 'Tasks.id': 1 }, | ||
expect(tasks[0].userWithName).toBeDefined() | ||
expect(tasks[0].userWithName.id).toEqual(user.id) | ||
expect(tasks[0].userWithName.name).toEqual(user.name) | ||
done() | ||
@@ -596,178 +695,126 @@ }) | ||
}.bind(this)) //- Task.create | ||
}.bind(this)) //- User.create | ||
}.bind(this)) //- sequelize.sync | ||
}) | ||
}.bind(this)) //- Task.create | ||
}.bind(this)) //- User.create | ||
}.bind(this)) //- sequelize.sync | ||
}) | ||
it('fetches associated objects for 1:N associations (1st direction)', function(done) { | ||
this.User.hasMany(this.Task) | ||
this.Task.belongsTo(this.User) | ||
it('fetches associated objects for N:M associations (1st direction)', function(done) { | ||
this.User.hasMany(this.Task) | ||
this.Task.hasMany(this.User) | ||
this.sequelize.sync({ force: true }).success(function() { | ||
this.User.create({ name: 'barfooz' }).success(function(user) { | ||
this.Task.create({ title: 'task1' }).success(function(task1) { | ||
this.Task.create({ title: 'task2' }).success(function(task2) { | ||
user.setTasks([task1, task2]).success(function() { | ||
this.User.findAll({ | ||
where: { 'UserWithNames.id': 1 }, | ||
include: [ 'Task' ] | ||
}).success(function(users) { | ||
expect(users[0].tasks).toBeDefined() | ||
expect( | ||
users[0].tasks.map(function(t) { return t.id }) | ||
).toEqual( | ||
[ task1.id, task2.id ] | ||
) | ||
done() | ||
}) | ||
}.bind(this)) //- setTask | ||
}.bind(this)) //- Task.create | ||
}.bind(this)) //- Task.create | ||
}.bind(this)) //- User.create | ||
}.bind(this)) //- sequelize.sync | ||
}) | ||
this.sequelize.sync({ force: true }).success(function() { | ||
this.User.create({ name: 'barfooz' }).success(function(user1) { | ||
it('fetches associated objects for 1:N associations (2nd direction)', function(done) { | ||
this.User.hasMany(this.Task) | ||
this.Task.belongsTo(this.User) | ||
this.sequelize.sync({ force: true }).success(function() { | ||
this.User.create({ name: 'barfooz' }).success(function(user) { | ||
this.Task.create({ title: 'task1' }).success(function(task1) { | ||
this.Task.create({ title: 'task2' }).success(function(task2) { | ||
user.setTasks([task1, task2]).success(function() { | ||
this.Task.findAll({ | ||
where: { 'Tasks.id': 1 }, | ||
include: [ 'UserWithName' ] | ||
}).success(function(tasks) { | ||
expect(tasks[0].userWithName).toBeDefined() | ||
expect(tasks[0].userWithName.name).toEqual(user.name) | ||
done() | ||
}) | ||
}.bind(this)) //- setTask | ||
}.bind(this)) //- Task.create | ||
this.Task.create({ title: 'task1' }).success(function(task1) { | ||
this.Task.create({ title: 'task2' }).success(function(task2) { | ||
user1.setTasks([task1, task2]).success(function() { | ||
this.User.findAll({ | ||
where: { 'UserWithNames.id': user1.id }, | ||
include: [ 'Task' ] | ||
}).success(function(users) { | ||
expect(users[0].tasks).toBeDefined() | ||
expect( | ||
users[0].tasks.map(function(t) { return t.id }) | ||
).toEqual( | ||
[ task1.id, task2.id ] | ||
) | ||
done() | ||
}) | ||
}.bind(this)) //- setTask | ||
}.bind(this)) //- Task.create | ||
}.bind(this)) //- User.create | ||
}.bind(this)) //- sequelize.sync | ||
}) | ||
}.bind(this)) //- Task.create | ||
it('fetches associated objects for N:M associations (1st direction)', function(done) { | ||
this.User.hasMany(this.Task) | ||
this.Task.hasMany(this.User) | ||
}.bind(this)) //- User.create | ||
}.bind(this)) //- sequelize.sync | ||
}) | ||
this.sequelize.sync({ force: true }).success(function() { | ||
this.User.create({ name: 'barfooz' }).success(function(user1) { | ||
it('fetches associated objects for N:M associations (2nd direction)', function(done) { | ||
this.User.hasMany(this.Task) | ||
this.Task.hasMany(this.User) | ||
this.Task.create({ title: 'task1' }).success(function(task1) { | ||
this.Task.create({ title: 'task2' }).success(function(task2) { | ||
user1.setTasks([task1, task2]).success(function() { | ||
this.User.findAll({ | ||
where: { 'UserWithNames.id': user1.id }, | ||
include: [ 'Task' ] | ||
}).success(function(users) { | ||
expect(users[0].tasks).toBeDefined() | ||
expect( | ||
users[0].tasks.map(function(t) { return t.id }) | ||
).toEqual( | ||
[ task1.id, task2.id ] | ||
) | ||
done() | ||
}) | ||
}.bind(this)) //- setTask | ||
}.bind(this)) //- Task.create | ||
}.bind(this)) //- Task.create | ||
this.sequelize.sync({ force: true }).success(function() { | ||
this.User.create({ name: 'barfooz' }).success(function(user1) { | ||
}.bind(this)) //- User.create | ||
}.bind(this)) //- sequelize.sync | ||
}) | ||
it('fetches associated objects for N:M associations (2nd direction)', function(done) { | ||
this.User.hasMany(this.Task) | ||
this.Task.hasMany(this.User) | ||
this.sequelize.sync({ force: true }).success(function() { | ||
this.User.create({ name: 'barfooz' }).success(function(user1) { | ||
this.Task.create({ title: 'task1' }).success(function(task1) { | ||
this.Task.create({ title: 'task2' }).success(function(task2) { | ||
user1.setTasks([task1, task2]).success(function() { | ||
this.Task.findAll({ | ||
where: { 'Tasks.id': task1.id }, | ||
include: [ 'UserWithName' ] | ||
}).success(function(tasks) { | ||
expect(tasks[0].userWithNames).toBeDefined() | ||
expect( | ||
tasks[0].userWithNames.map(function(u) { return u.id }) | ||
).toEqual( | ||
[ user1.id ] | ||
) | ||
done() | ||
}) | ||
}.bind(this)) //- setTask | ||
}.bind(this)) //- Task.create | ||
this.Task.create({ title: 'task1' }).success(function(task1) { | ||
this.Task.create({ title: 'task2' }).success(function(task2) { | ||
user1.setTasks([task1, task2]).success(function() { | ||
this.Task.findAll({ | ||
where: { 'Tasks.id': task1.id }, | ||
include: [ 'UserWithName' ] | ||
}).success(function(tasks) { | ||
expect(tasks[0].userWithNames).toBeDefined() | ||
expect( | ||
tasks[0].userWithNames.map(function(u) { return u.id }) | ||
).toEqual( | ||
[ user1.id ] | ||
) | ||
done() | ||
}) | ||
}.bind(this)) //- setTask | ||
}.bind(this)) //- Task.create | ||
}.bind(this)) //- Task.create | ||
}.bind(this)) //- User.create | ||
}.bind(this)) //- sequelize.sync | ||
}) | ||
}.bind(this)) //- User.create | ||
}.bind(this)) //- sequelize.sync | ||
}) | ||
}) //- describe: findAll | ||
}) | ||
}) //- describe: findAll | ||
describe('min', function() { | ||
before(function(done) { | ||
this.UserWithAge = this.sequelize.define('UserWithAge', { | ||
age: Sequelize.INTEGER | ||
}) | ||
this.UserWithAge.sync({ force: true }).success(done) | ||
describe('min', function() { | ||
before(function(done) { | ||
this.UserWithAge = this.sequelize.define('UserWithAge', { | ||
age: Sequelize.INTEGER | ||
}) | ||
it("should return the min value", function(done) { | ||
this.UserWithAge.create({ age: 2 }).success(function() { | ||
this.UserWithAge.create({ age: 3 }).success(function() { | ||
this.UserWithAge.min('age').success(function(min) { | ||
expect(min).toEqual(2) | ||
done() | ||
}) | ||
}.bind(this)) | ||
this.UserWithAge.sync({ force: true }).success(done) | ||
}) | ||
it("should return the min value", function(done) { | ||
this.UserWithAge.create({ age: 2 }).success(function() { | ||
this.UserWithAge.create({ age: 3 }).success(function() { | ||
this.UserWithAge.min('age').success(function(min) { | ||
expect(min).toEqual(2) | ||
done() | ||
}) | ||
}.bind(this)) | ||
}.bind(this)) | ||
}) | ||
it('allows sql logging', function(done) { | ||
this.UserWithAge.min('age').on('sql', function(sql) { | ||
expect(sql).toBeDefined() | ||
expect(sql.toUpperCase().indexOf("SELECT")).toBeGreaterThan(-1) | ||
done() | ||
}) | ||
}) | ||
}) //- describe: min | ||
it('allows sql logging', function(done) { | ||
this.UserWithAge.min('age').on('sql', function(sql) { | ||
expect(sql).toBeDefined() | ||
expect(sql.toUpperCase().indexOf("SELECT")).toBeGreaterThan(-1) | ||
done() | ||
}) | ||
describe('max', function() { | ||
before(function(done) { | ||
this.UserWithAge = this.sequelize.define('UserWithAge', { | ||
age: Sequelize.INTEGER | ||
}) | ||
}) //- describe: min | ||
describe('max', function() { | ||
before(function(done) { | ||
this.UserWithAge = this.sequelize.define('UserWithAge', { | ||
age: Sequelize.INTEGER | ||
}) | ||
this.UserWithAge.sync({ force: true }).success(done) | ||
}) | ||
this.UserWithAge.sync({ force: true }).success(done) | ||
}) | ||
it("should return the max value", function(done) { | ||
this.UserWithAge.create({ age: 2 }).success(function() { | ||
this.UserWithAge.create({ age: 3 }).success(function() { | ||
this.UserWithAge.max('age').success(function(max) { | ||
expect(max).toEqual(3) | ||
done() | ||
}) | ||
}.bind(this)) | ||
it("should return the max value", function(done) { | ||
this.UserWithAge.create({ age: 2 }).success(function() { | ||
this.UserWithAge.create({ age: 3 }).success(function() { | ||
this.UserWithAge.max('age').success(function(max) { | ||
expect(max).toEqual(3) | ||
done() | ||
}) | ||
}.bind(this)) | ||
}) | ||
}.bind(this)) | ||
}) | ||
it('allows sql logging', function(done) { | ||
this.UserWithAge.max('age').on('sql', function(sql) { | ||
expect(sql).toBeDefined() | ||
expect(sql.toUpperCase().indexOf("SELECT")).toBeGreaterThan(-1) | ||
done() | ||
}) | ||
it('allows sql logging', function(done) { | ||
this.UserWithAge.max('age').on('sql', function(sql) { | ||
expect(sql).toBeDefined() | ||
expect(sql.toUpperCase().indexOf("SELECT")).toBeGreaterThan(-1) | ||
done() | ||
}) | ||
}) //- describe: max | ||
}) | ||
}) | ||
}) //- describe: max | ||
}) |
if(typeof require === 'function') { | ||
const buster = require("buster") | ||
, dialects = ['sqlite', 'mysql', 'postgres'] | ||
, Helpers = require('./buster-helpers') | ||
const buster = require("buster") | ||
, Helpers = require('./buster-helpers') | ||
, dialect = Helpers.getTestDialect() | ||
} | ||
@@ -9,96 +9,94 @@ | ||
dialects.forEach(function(dialect) { | ||
describe('DAO@' + dialect, function() { | ||
before(function(done) { | ||
var self = this | ||
describe("[" + dialect.toUpperCase() + "] DAO", function() { | ||
before(function(done) { | ||
var self = this | ||
Helpers.initTests({ | ||
dialect: dialect, | ||
beforeComplete: function(sequelize, DataTypes) { | ||
self.sequelize = sequelize | ||
self.User = sequelize.define('User', { | ||
username: { type: DataTypes.STRING }, | ||
touchedAt: { type: DataTypes.DATE, defaultValue: DataTypes.NOW }, | ||
aNumber: { type: DataTypes.INTEGER } | ||
}) | ||
}, | ||
onComplete: function(sequelize) { | ||
self.User.sync({ force: true }).success(done) | ||
} | ||
}) | ||
Helpers.initTests({ | ||
dialect: dialect, | ||
beforeComplete: function(sequelize, DataTypes) { | ||
self.sequelize = sequelize | ||
self.User = sequelize.define('User', { | ||
username: { type: DataTypes.STRING }, | ||
touchedAt: { type: DataTypes.DATE, defaultValue: DataTypes.NOW }, | ||
aNumber: { type: DataTypes.INTEGER } | ||
}) | ||
}, | ||
onComplete: function() { | ||
self.User.sync({ force: true }).success(done) | ||
} | ||
}) | ||
}) | ||
describe('default values', function() { | ||
describe('current date', function() { | ||
it('should store a date in touchedAt', function() { | ||
var user = this.User.build({ username: 'a user'}) | ||
expect(user.touchedAt instanceof Date).toBeTrue() | ||
}) | ||
describe('default values', function() { | ||
describe('current date', function() { | ||
it('should store a date in touchedAt', function() { | ||
var user = this.User.build({ username: 'a user'}) | ||
expect(user.touchedAt instanceof Date).toBeTrue() | ||
}) | ||
it("should store the current date in touchedAt", function() { | ||
this.useFakeTimers().tick(5000) | ||
it("should store the current date in touchedAt", function() { | ||
this.useFakeTimers().tick(5000) | ||
var user = this.User.build({ username: 'a user'}) | ||
expect(+user.touchedAt).toBe(5000) | ||
}) | ||
var user = this.User.build({ username: 'a user'}) | ||
expect(+user.touchedAt).toBe(5000) | ||
}) | ||
}) | ||
}) | ||
describe('complete', function() { | ||
it("gets triggered if an error occurs", function(done) { | ||
this.User.find({ where: "asdasdasd" }).complete(function(err, result) { | ||
expect(err).toBeDefined() | ||
expect(err.message).toBeDefined() | ||
done() | ||
}) | ||
describe('complete', function() { | ||
it("gets triggered if an error occurs", function(done) { | ||
this.User.find({ where: "asdasdasd" }).complete(function(err, result) { | ||
expect(err).toBeDefined() | ||
expect(err.message).toBeDefined() | ||
done() | ||
}) | ||
}) | ||
it("gets triggered if everything was ok", function(done) { | ||
this.User.count().complete(function(err, result) { | ||
expect(err).toBeNull() | ||
expect(result).toBeDefined() | ||
done() | ||
}) | ||
it("gets triggered if everything was ok", function(done) { | ||
this.User.count().complete(function(err, result) { | ||
expect(err).toBeNull() | ||
expect(result).toBeDefined() | ||
done() | ||
}) | ||
}) | ||
}) | ||
describe('save', function() { | ||
it('takes zero into account', function(done) { | ||
this.User.build({ aNumber: 0 }).save([ 'aNumber' ]).success(function(user) { | ||
expect(user.aNumber).toEqual(0) | ||
done() | ||
}) | ||
describe('save', function() { | ||
it('takes zero into account', function(done) { | ||
this.User.build({ aNumber: 0 }).save([ 'aNumber' ]).success(function(user) { | ||
expect(user.aNumber).toEqual(0) | ||
done() | ||
}) | ||
}) | ||
}) | ||
describe('toJSON', function toJSON() { | ||
before(function(done) { | ||
this.User = this.sequelize.define('UserWithUsernameAndAgeAndIsAdmin', { | ||
username: Helpers.Sequelize.STRING, | ||
age: Helpers.Sequelize.INTEGER, | ||
isAdmin: Helpers.Sequelize.BOOLEAN | ||
}, { | ||
timestamps: false, | ||
logging: true | ||
}) | ||
this.User.sync({ force: true }).success(done) | ||
describe('toJSON', function toJSON() { | ||
before(function(done) { | ||
this.User = this.sequelize.define('UserWithUsernameAndAgeAndIsAdmin', { | ||
username: Helpers.Sequelize.STRING, | ||
age: Helpers.Sequelize.INTEGER, | ||
isAdmin: Helpers.Sequelize.BOOLEAN | ||
}, { | ||
timestamps: false, | ||
logging: true | ||
}) | ||
it('returns an object containing all values', function() { | ||
var user = this.User.build({ username: 'test.user', age: 99, isAdmin: true }) | ||
expect(user.toJSON()).toEqual({ username: 'test.user', age: 99, isAdmin: true, id: null }) | ||
}) | ||
this.User.sync({ force: true }).success(done) | ||
}) | ||
it('returns a response that can be stringified', function() { | ||
var user = this.User.build({ username: 'test.user', age: 99, isAdmin: true }) | ||
expect(JSON.stringify(user)).toEqual('{"username":"test.user","age":99,"isAdmin":true,"id":null}') | ||
}) | ||
it('returns an object containing all values', function() { | ||
var user = this.User.build({ username: 'test.user', age: 99, isAdmin: true }) | ||
expect(user.toJSON()).toEqual({ username: 'test.user', age: 99, isAdmin: true, id: null }) | ||
}) | ||
it('returns a response that can be stringified and then parsed', function() { | ||
var user = this.User.build({ username: 'test.user', age: 99, isAdmin: true }) | ||
expect(JSON.parse(JSON.stringify(user))).toEqual({ username: 'test.user', age: 99, isAdmin: true, id: null }) | ||
}) | ||
it('returns a response that can be stringified', function() { | ||
var user = this.User.build({ username: 'test.user', age: 99, isAdmin: true }) | ||
expect(JSON.stringify(user)).toEqual('{"username":"test.user","age":99,"isAdmin":true,"id":null}') | ||
}) | ||
it('returns a response that can be stringified and then parsed', function() { | ||
var user = this.User.build({ username: 'test.user', age: 99, isAdmin: true }) | ||
expect(JSON.parse(JSON.stringify(user))).toEqual({ username: 'test.user', age: 99, isAdmin: true, id: null }) | ||
}) | ||
}) | ||
}) |
@@ -10,260 +10,258 @@ if(typeof require === 'function') { | ||
describe(dialect, function() { | ||
describe('=>DAO', function() { | ||
describe('validations', function() { | ||
before(function(done) { | ||
Helpers.initTests({ | ||
dialect: dialect, | ||
onComplete: function(sequelize) { | ||
this.sequelize = sequelize | ||
done() | ||
}.bind(this) | ||
}) | ||
}) //- before | ||
describe("[" + dialect.toUpperCase() + "] DAO", function() { | ||
describe('validations', function() { | ||
before(function(done) { | ||
Helpers.initTests({ | ||
dialect: dialect, | ||
onComplete: function(sequelize) { | ||
this.sequelize = sequelize | ||
done() | ||
}.bind(this) | ||
}) | ||
}) //- before | ||
var checks = { | ||
is: { | ||
spec: { args: ["[a-z]",'i'] }, | ||
fail: "0", | ||
pass: "a" | ||
}, | ||
not: { | ||
spec: { args: ["[a-z]",'i'] }, | ||
fail: "a", | ||
pass: "0" | ||
}, | ||
isEmail : { | ||
fail: "a", | ||
pass: "abc@abc.com" | ||
} | ||
, isUrl : { | ||
fail: "abc", | ||
pass: "http://abc.com" | ||
} | ||
, isIP : { | ||
fail: "abc", | ||
pass: "129.89.23.1" | ||
} | ||
, isAlpha : { | ||
fail: "012", | ||
pass: "abc" | ||
} | ||
, isAlphanumeric : { | ||
fail: "_abc019", | ||
pass: "abc019" | ||
} | ||
, isNumeric : { | ||
fail: "abc", | ||
pass: "019" | ||
} | ||
, isInt : { | ||
fail: "9.2", | ||
pass: "-9" | ||
} | ||
, isLowercase : { | ||
fail: "AB", | ||
pass: "ab" | ||
} | ||
, isUppercase : { | ||
fail: "ab", | ||
pass: "AB" | ||
} | ||
, isDecimal : { | ||
fail: "a", | ||
pass: "0.2" | ||
} | ||
, isFloat : { | ||
fail: "a", | ||
pass: "9.2" | ||
} | ||
, notNull : { | ||
fail: null, | ||
pass: 0 | ||
} | ||
, isNull : { | ||
fail: 0, | ||
pass: null | ||
} | ||
, notEmpty : { | ||
fail: " ", | ||
pass: "a" | ||
} | ||
, equals : { | ||
spec : { args : "bla bla bla" }, | ||
fail: "bla", | ||
pass: "bla bla bla" | ||
} | ||
, contains : { | ||
spec : { args : "bla" }, | ||
fail: "la", | ||
pass: "0bla23" | ||
} | ||
, notContains : { | ||
spec : { args : "bla" }, | ||
fail: "0bla23", | ||
pass: "la" | ||
} | ||
, regex : { | ||
spec : { args: ["[a-z]",'i'] }, | ||
fail: "0", | ||
pass: "a" | ||
} | ||
, notRegex : { | ||
spec: { args: ["[a-z]",'i'] }, | ||
fail: "a", | ||
pass: "0" | ||
} | ||
, len : { | ||
spec: { args: [2,4] }, | ||
fail: ["1", "12345"], | ||
pass: ["12", "123", "1234"], | ||
raw: true | ||
} | ||
, isUUID : { | ||
spec: { args: 4 }, | ||
fail: "f47ac10b-58cc-3372-a567-0e02b2c3d479", | ||
pass: "f47ac10b-58cc-4372-a567-0e02b2c3d479" | ||
} | ||
, isDate : { | ||
fail: "not a date", | ||
pass: "2011-02-04" | ||
} | ||
, isAfter : { | ||
spec: { args: "2011-11-05" }, | ||
fail: "2011-11-04", | ||
pass: "2011-11-05" | ||
} | ||
, isBefore : { | ||
spec: { args: "2011-11-05" }, | ||
fail: "2011-11-06", | ||
pass: "2011-11-05" | ||
} | ||
, isIn : { | ||
spec: { args: "abcdefghijk" }, | ||
fail: "ghik", | ||
pass: "ghij" | ||
} | ||
, notIn : { | ||
spec: { args: "abcdefghijk" }, | ||
fail: "ghij", | ||
pass: "ghik" | ||
} | ||
, max : { | ||
spec: { args: 23 }, | ||
fail: "24", | ||
pass: "23" | ||
} | ||
, min : { | ||
spec: { args: 23 }, | ||
fail: "22", | ||
pass: "23" | ||
} | ||
, isArray : { | ||
fail: 22, | ||
pass: [22] | ||
} | ||
, isCreditCard : { | ||
fail: "401288888888188f", | ||
pass: "4012888888881881" | ||
} | ||
var checks = { | ||
is: { | ||
spec: { args: ["[a-z]",'i'] }, | ||
fail: "0", | ||
pass: "a" | ||
}, | ||
not: { | ||
spec: { args: ["[a-z]",'i'] }, | ||
fail: "a", | ||
pass: "0" | ||
}, | ||
isEmail : { | ||
fail: "a", | ||
pass: "abc@abc.com" | ||
} | ||
, isUrl : { | ||
fail: "abc", | ||
pass: "http://abc.com" | ||
} | ||
, isIP : { | ||
fail: "abc", | ||
pass: "129.89.23.1" | ||
} | ||
, isAlpha : { | ||
fail: "012", | ||
pass: "abc" | ||
} | ||
, isAlphanumeric : { | ||
fail: "_abc019", | ||
pass: "abc019" | ||
} | ||
, isNumeric : { | ||
fail: "abc", | ||
pass: "019" | ||
} | ||
, isInt : { | ||
fail: "9.2", | ||
pass: "-9" | ||
} | ||
, isLowercase : { | ||
fail: "AB", | ||
pass: "ab" | ||
} | ||
, isUppercase : { | ||
fail: "ab", | ||
pass: "AB" | ||
} | ||
, isDecimal : { | ||
fail: "a", | ||
pass: "0.2" | ||
} | ||
, isFloat : { | ||
fail: "a", | ||
pass: "9.2" | ||
} | ||
, notNull : { | ||
fail: null, | ||
pass: 0 | ||
} | ||
, isNull : { | ||
fail: 0, | ||
pass: null | ||
} | ||
, notEmpty : { | ||
fail: " ", | ||
pass: "a" | ||
} | ||
, equals : { | ||
spec : { args : "bla bla bla" }, | ||
fail: "bla", | ||
pass: "bla bla bla" | ||
} | ||
, contains : { | ||
spec : { args : "bla" }, | ||
fail: "la", | ||
pass: "0bla23" | ||
} | ||
, notContains : { | ||
spec : { args : "bla" }, | ||
fail: "0bla23", | ||
pass: "la" | ||
} | ||
, regex : { | ||
spec : { args: ["[a-z]",'i'] }, | ||
fail: "0", | ||
pass: "a" | ||
} | ||
, notRegex : { | ||
spec: { args: ["[a-z]",'i'] }, | ||
fail: "a", | ||
pass: "0" | ||
} | ||
, len : { | ||
spec: { args: [2,4] }, | ||
fail: ["1", "12345"], | ||
pass: ["12", "123", "1234"], | ||
raw: true | ||
} | ||
, isUUID : { | ||
spec: { args: 4 }, | ||
fail: "f47ac10b-58cc-3372-a567-0e02b2c3d479", | ||
pass: "f47ac10b-58cc-4372-a567-0e02b2c3d479" | ||
} | ||
, isDate : { | ||
fail: "not a date", | ||
pass: "2011-02-04" | ||
} | ||
, isAfter : { | ||
spec: { args: "2011-11-05" }, | ||
fail: "2011-11-04", | ||
pass: "2011-11-05" | ||
} | ||
, isBefore : { | ||
spec: { args: "2011-11-05" }, | ||
fail: "2011-11-06", | ||
pass: "2011-11-05" | ||
} | ||
, isIn : { | ||
spec: { args: "abcdefghijk" }, | ||
fail: "ghik", | ||
pass: "ghij" | ||
} | ||
, notIn : { | ||
spec: { args: "abcdefghijk" }, | ||
fail: "ghij", | ||
pass: "ghik" | ||
} | ||
, max : { | ||
spec: { args: 23 }, | ||
fail: "24", | ||
pass: "23" | ||
} | ||
, min : { | ||
spec: { args: 23 }, | ||
fail: "22", | ||
pass: "23" | ||
} | ||
, isArray : { | ||
fail: 22, | ||
pass: [22] | ||
} | ||
, isCreditCard : { | ||
fail: "401288888888188f", | ||
pass: "4012888888881881" | ||
} | ||
} | ||
for (var validator in checks) { | ||
if (checks.hasOwnProperty(validator)) { | ||
var validatorDetails = checks[validator] | ||
for (var validator in checks) { | ||
if (checks.hasOwnProperty(validator)) { | ||
var validatorDetails = checks[validator] | ||
if (!validatorDetails.hasOwnProperty("raw")) { | ||
validatorDetails.fail = [ validatorDetails.fail ] | ||
validatorDetails.pass = [ validatorDetails.pass ] | ||
} | ||
if (!validatorDetails.hasOwnProperty("raw")) { | ||
validatorDetails.fail = [ validatorDetails.fail ] | ||
validatorDetails.pass = [ validatorDetails.pass ] | ||
} | ||
////////////////////////// | ||
// test the error cases // | ||
////////////////////////// | ||
for (var i = 0; i < validatorDetails.fail.length; i++) { | ||
var failingValue = validatorDetails.fail[i] | ||
////////////////////////// | ||
// test the error cases // | ||
////////////////////////// | ||
for (var i = 0; i < validatorDetails.fail.length; i++) { | ||
var failingValue = validatorDetails.fail[i] | ||
it('correctly specifies an instance as invalid using a value of "' + failingValue + '" for the validation "' + validator + '"', function() { | ||
var validations = {} | ||
, message = validator + "(" + failingValue + ")" | ||
it('correctly specifies an instance as invalid using a value of "' + failingValue + '" for the validation "' + validator + '"', function() { | ||
var validations = {} | ||
, message = validator + "(" + failingValue + ")" | ||
if (validatorDetails.hasOwnProperty('spec')) { | ||
validations[validator] = validatorDetails.spec | ||
} else { | ||
validations[validator] = {} | ||
if (validatorDetails.hasOwnProperty('spec')) { | ||
validations[validator] = validatorDetails.spec | ||
} else { | ||
validations[validator] = {} | ||
} | ||
validations[validator].msg = message | ||
var UserFail = this.sequelize.define('User' + Math.random(), { | ||
name: { | ||
type: Sequelize.STRING, | ||
validate: validations | ||
} | ||
}) | ||
validations[validator].msg = message | ||
var failingUser = UserFail.build({ name : failingValue }) | ||
, errors = failingUser.validate() | ||
var UserFail = this.sequelize.define('User' + Math.random(), { | ||
name: { | ||
type: Sequelize.STRING, | ||
validate: validations | ||
} | ||
}) | ||
expect(errors).not.toBeNull() | ||
expect(errors).toEqual({ name : [message] }) | ||
}) | ||
} | ||
var failingUser = UserFail.build({ name : failingValue }) | ||
, errors = failingUser.validate() | ||
//////////////////////////// | ||
// test the success cases // | ||
//////////////////////////// | ||
for (var j = 0; j < validatorDetails.pass.length; j++) { | ||
var succeedingValue = validatorDetails.pass[j] | ||
expect(errors).not.toBeNull() | ||
expect(errors).toEqual({ name : [message] }) | ||
}) | ||
} | ||
it('correctly specifies an instance as valid using a value of "' + succeedingValue + '" for the validation "' + validator + '"', function() { | ||
var validations = {} | ||
//////////////////////////// | ||
// test the success cases // | ||
//////////////////////////// | ||
for (var j = 0; j < validatorDetails.pass.length; j++) { | ||
var succeedingValue = validatorDetails.pass[j] | ||
if (validatorDetails.hasOwnProperty('spec')) { | ||
validations[validator] = validatorDetails.spec | ||
} else { | ||
validations[validator] = {} | ||
} | ||
it('correctly specifies an instance as valid using a value of "' + succeedingValue + '" for the validation "' + validator + '"', function() { | ||
var validations = {} | ||
validations[validator].msg = validator + "(" + succeedingValue + ")" | ||
if (validatorDetails.hasOwnProperty('spec')) { | ||
validations[validator] = validatorDetails.spec | ||
} else { | ||
validations[validator] = {} | ||
var UserSuccess = this.sequelize.define('User' + Math.random(), { | ||
name: { | ||
type: Sequelize.STRING, | ||
validate: validations | ||
} | ||
}) | ||
validations[validator].msg = validator + "(" + succeedingValue + ")" | ||
var UserSuccess = this.sequelize.define('User' + Math.random(), { | ||
name: { | ||
type: Sequelize.STRING, | ||
validate: validations | ||
} | ||
}) | ||
var successfulUser = UserSuccess.build({ name: succeedingValue }) | ||
expect(successfulUser.validate()).toBeNull() | ||
}) | ||
} | ||
var successfulUser = UserSuccess.build({ name: succeedingValue }) | ||
expect(successfulUser.validate()).toBeNull() | ||
}) | ||
} | ||
} | ||
} | ||
it('correctly validates using custom validation methods', function() { | ||
var User = this.sequelize.define('User' + Math.random(), { | ||
name: { | ||
type: Sequelize.STRING, | ||
validate: { | ||
customFn: function(val) { | ||
if (val !== "2") { | ||
throw new Error("name should equal '2'") | ||
} | ||
it('correctly validates using custom validation methods', function() { | ||
var User = this.sequelize.define('User' + Math.random(), { | ||
name: { | ||
type: Sequelize.STRING, | ||
validate: { | ||
customFn: function(val) { | ||
if (val !== "2") { | ||
throw new Error("name should equal '2'") | ||
} | ||
} | ||
} | ||
}) | ||
} | ||
}) | ||
var failingUser = User.build({ name : "3" }) | ||
, errors = failingUser.validate() | ||
var failingUser = User.build({ name : "3" }) | ||
, errors = failingUser.validate() | ||
expect(errors).not.toBeNull(null) | ||
expect(errors).toEqual({ name: ["name should equal '2'"] }) | ||
expect(errors).not.toBeNull(null) | ||
expect(errors).toEqual({ name: ["name should equal '2'"] }) | ||
var successfulUser = User.build({ name : "2" }) | ||
expect(successfulUser.validate()).toBeNull() | ||
}) | ||
var successfulUser = User.build({ name : "2" }) | ||
expect(successfulUser.validate()).toBeNull() | ||
}) | ||
}) | ||
}) |
@@ -5,2 +5,4 @@ if(typeof require === 'function') { | ||
, CustomEventEmitter = require("../lib/emitters/custom-event-emitter") | ||
, Helpers = require('./buster-helpers') | ||
, dialect = Helpers.getTestDialect() | ||
} | ||
@@ -11,4 +13,3 @@ | ||
describe('QueryChainer', function() { | ||
describe("[" + dialect.toUpperCase() + "] QueryChainer", function() { | ||
before(function() { | ||
@@ -15,0 +16,0 @@ this.queryChainer = new QueryChainer() |
if(typeof require === 'function') { | ||
const buster = require("buster") | ||
, Helpers = require('./buster-helpers') | ||
const buster = require("buster") | ||
, Helpers = require('./buster-helpers') | ||
, dialect = Helpers.getTestDialect() | ||
} | ||
@@ -8,8 +10,6 @@ | ||
describe('Sequelize', function() { | ||
describe("[" + dialect.toUpperCase() + "] Sequelize", function() { | ||
before(function(done) { | ||
var self = this | ||
Helpers.initTests({ | ||
beforeComplete: function(sequelize) { self.sequelize = sequelize }, | ||
beforeComplete: function(sequelize) { this.sequelize = sequelize }.bind(this), | ||
onComplete: done | ||
@@ -31,2 +31,44 @@ }) | ||
}) | ||
describe('query', function() { | ||
before(function(done) { | ||
this.User = this.sequelize.define('User', { | ||
username: Helpers.Sequelize.STRING | ||
}) | ||
this.insertQuery = "INSERT INTO " + this.User.tableName + " (username) VALUES ('john')" | ||
this.User.sync().success(done) | ||
}) | ||
it('//executes a query the internal way', function(done) { | ||
this.sequelize.query(this.insertQuery, null, { raw: true }).success(function(result) { | ||
expect(result).toBeNull() | ||
done() | ||
}) | ||
}) | ||
it('//executes a query if only the sql is passed', function(done) { | ||
this.sequelize.query(this.insertQuery).success(function(result) { | ||
expect(result).toBeNull() | ||
done() | ||
}) | ||
}) | ||
it('//executes select queries correctly', function(done) { | ||
this.sequelize.query(this.insertQuery).success(function() { | ||
this.sequelize | ||
.query("select * from " + this.User.tableName) | ||
.success(function(users) { | ||
expect(users.map(function(u){ return u.username })).toEqual(['john']) | ||
done() | ||
}) | ||
.error(function(err) { | ||
console.log(err) | ||
expect(err).not.toBeDefined() | ||
done() | ||
}) | ||
}.bind(this)) | ||
}) | ||
}) | ||
}) |
if(typeof require === 'function') { | ||
const buster = require("buster") | ||
, Helpers = require('../buster-helpers') | ||
, dialect = Helpers.getTestDialect() | ||
} | ||
@@ -8,44 +9,46 @@ | ||
describe('DAO@sqlite', function() { | ||
before(function(done) { | ||
var self = this | ||
if (dialect === 'sqlite') { | ||
describe('[SQLITE] DAO', function() { | ||
before(function(done) { | ||
var self = this | ||
Helpers.initTests({ | ||
dialect: 'sqlite', | ||
beforeComplete: function(sequelize, DataTypes) { | ||
self.sequelize = sequelize | ||
Helpers.initTests({ | ||
dialect: 'sqlite', | ||
beforeComplete: function(sequelize, DataTypes) { | ||
self.sequelize = sequelize | ||
self.User = sequelize.define('User', { | ||
username: DataTypes.STRING | ||
}) | ||
}, | ||
onComplete: function(sequelize) { | ||
self.User.sync({ force: true }).success(done) | ||
} | ||
self.User = sequelize.define('User', { | ||
username: DataTypes.STRING | ||
}) | ||
}, | ||
onComplete: function() { | ||
self.User.sync({ force: true }).success(done) | ||
} | ||
}) | ||
}) | ||
}) | ||
describe('findAll', function() { | ||
it("handles dates correctly", function(done) { | ||
var self = this | ||
describe('findAll', function() { | ||
it("handles dates correctly", function(done) { | ||
var self = this | ||
this.User | ||
.create({ username: 'user', createdAt: new Date(2011, 04, 04) }) | ||
.success(function(oldUser) { | ||
self.User | ||
.create({ username: 'new user' }) | ||
.success(function(newUser) { | ||
self.User.findAll({ | ||
where: ['createdAt > ?', new Date(2012, 01, 01)] | ||
}).success(function(users) { | ||
expect(users.length).toEqual(1) | ||
done() | ||
this.User | ||
.create({ username: 'user', createdAt: new Date(2011, 04, 04) }) | ||
.success(function(oldUser) { | ||
self.User | ||
.create({ username: 'new user' }) | ||
.success(function(newUser) { | ||
self.User.findAll({ | ||
where: ['createdAt > ?', new Date(2012, 01, 01)] | ||
}).success(function(users) { | ||
expect(users.length).toEqual(1) | ||
done() | ||
}) | ||
}) | ||
}) | ||
}) | ||
.error(function(err) { | ||
console.log(err) | ||
}) | ||
}) | ||
.error(function(err) { | ||
console.log(err) | ||
}) | ||
}) | ||
}) | ||
}) | ||
}) | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
2508656
8812