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

Commit f5fc5010 by Mick Hansen

Merge pull request #3443 from BridgeAR/master

WIP Refactor almost all tests to use promise style
2 parents 768c4400 3ce25c28
...@@ -52,11 +52,10 @@ describe(Support.getTestDialectTeaser('Configuration'), function() { ...@@ -52,11 +52,10 @@ describe(Support.getTestDialectTeaser('Configuration'), function() {
} }
}); });
it('when we don\'t have a valid dialect.', function(done) { it('when we don\'t have a valid dialect.', function() {
expect(function() { expect(function() {
new Sequelize(config[dialect].database, config[dialect].username, config[dialect].password, {host: '0.0.0.1', port: config[dialect].port, dialect: undefined}); new Sequelize(config[dialect].database, config[dialect].username, config[dialect].password, {host: '0.0.0.1', port: config[dialect].port, dialect: undefined});
}).to.throw(Error, 'The dialect undefined is not supported.'); }).to.throw(Error, 'The dialect undefined is not supported.');
done();
}); });
}); });
...@@ -75,13 +74,12 @@ describe(Support.getTestDialectTeaser('Configuration'), function() { ...@@ -75,13 +74,12 @@ describe(Support.getTestDialectTeaser('Configuration'), function() {
expect(config.port).to.equal('9821'); expect(config.port).to.equal('9821');
}); });
it('should work with no authentication options', function(done) { it('should work with no authentication options', function() {
var sequelize = new Sequelize('mysql://example.com:9821/dbname'); var sequelize = new Sequelize('mysql://example.com:9821/dbname');
var config = sequelize.config; var config = sequelize.config;
expect(config.username).to.not.be.ok; expect(config.username).to.not.be.ok;
expect(config.password).to.be.null; expect(config.password).to.be.null;
done();
}); });
it('should work with no authentication options and passing additional options', function() { it('should work with no authentication options and passing additional options', function() {
...@@ -113,26 +111,24 @@ describe(Support.getTestDialectTeaser('Configuration'), function() { ...@@ -113,26 +111,24 @@ describe(Support.getTestDialectTeaser('Configuration'), function() {
}); });
describe('Intantiation with arguments', function() { describe('Intantiation with arguments', function() {
it('should accept two parameters (database, username)', function(done) { it('should accept two parameters (database, username)', function() {
var sequelize = new Sequelize('dbname', 'root'); var sequelize = new Sequelize('dbname', 'root');
var config = sequelize.config; var config = sequelize.config;
expect(config.database).to.equal('dbname'); expect(config.database).to.equal('dbname');
expect(config.username).to.equal('root'); expect(config.username).to.equal('root');
done();
}); });
it('should accept three parameters (database, username, password)', function(done) { it('should accept three parameters (database, username, password)', function() {
var sequelize = new Sequelize('dbname', 'root', 'pass'); var sequelize = new Sequelize('dbname', 'root', 'pass');
var config = sequelize.config; var config = sequelize.config;
expect(config.database).to.equal('dbname'); expect(config.database).to.equal('dbname');
expect(config.username).to.equal('root'); expect(config.username).to.equal('root');
expect(config.password).to.equal('pass'); expect(config.password).to.equal('pass');
done();
}); });
it('should accept four parameters (database, username, password, options)', function(done) { it('should accept four parameters (database, username, password, options)', function() {
var sequelize = new Sequelize('dbname', 'root', 'pass', { var sequelize = new Sequelize('dbname', 'root', 'pass', {
port: 999, port: 999,
dialectOptions: { dialectOptions: {
...@@ -148,7 +144,6 @@ describe(Support.getTestDialectTeaser('Configuration'), function() { ...@@ -148,7 +144,6 @@ describe(Support.getTestDialectTeaser('Configuration'), function() {
expect(config.port).to.equal(999); expect(config.port).to.equal(999);
expect(config.dialectOptions.supportBigNumbers).to.be.true; expect(config.dialectOptions.supportBigNumbers).to.be.true;
expect(config.dialectOptions.bigNumberStrings).to.be.true; expect(config.dialectOptions.bigNumberStrings).to.be.true;
done();
}); });
}); });
......
...@@ -11,33 +11,30 @@ if (Support.dialectIsMySQL()) { ...@@ -11,33 +11,30 @@ if (Support.dialectIsMySQL()) {
describe('[MYSQL Specific] Associations', function() { describe('[MYSQL Specific] Associations', function() {
describe('many-to-many', function() { describe('many-to-many', function() {
describe('where tables have the same prefix', function() { describe('where tables have the same prefix', function() {
it('should create a table wp_table1wp_table2s', function(done) { it('should create a table wp_table1wp_table2s', function() {
var Table2 = this.sequelize.define('wp_table2', {foo: DataTypes.STRING}) var Table2 = this.sequelize.define('wp_table2', {foo: DataTypes.STRING})
, Table1 = this.sequelize.define('wp_table1', {foo: DataTypes.STRING}) , Table1 = this.sequelize.define('wp_table1', {foo: DataTypes.STRING})
, self = this; , self = this;
Table1.hasMany(Table2); Table1.hasMany(Table2);
Table2.hasMany(Table1); Table2.hasMany(Table1);
Table1.sync({ force: true }).success(function() { return Table1.sync({ force: true }).then(function() {
Table2.sync({ force: true }).success(function() { return Table2.sync({ force: true }).then(function() {
expect(self.sequelize.daoFactoryManager.getDAO('wp_table1swp_table2s')).to.exist; expect(self.sequelize.daoFactoryManager.getDAO('wp_table1swp_table2s')).to.exist;
done();
}); });
}); });
}); });
}); });
describe('when join table name is specified', function() { describe('when join table name is specified', function() {
beforeEach(function(done) { beforeEach(function() {
var Table2 = this.sequelize.define('ms_table1', {foo: DataTypes.STRING}) var Table2 = this.sequelize.define('ms_table1', {foo: DataTypes.STRING})
, Table1 = this.sequelize.define('ms_table2', {foo: DataTypes.STRING}); , Table1 = this.sequelize.define('ms_table2', {foo: DataTypes.STRING});
Table1.hasMany(Table2, {joinTableName: 'table1_to_table2'}); Table1.hasMany(Table2, {joinTableName: 'table1_to_table2'});
Table2.hasMany(Table1, {joinTableName: 'table1_to_table2'}); Table2.hasMany(Table1, {joinTableName: 'table1_to_table2'});
Table1.sync({ force: true }).success(function() { return Table1.sync({ force: true }).then(function() {
Table2.sync({ force: true }).success(function() { return Table2.sync({ force: true });
done();
});
}); });
}); });
...@@ -50,7 +47,7 @@ if (Support.dialectIsMySQL()) { ...@@ -50,7 +47,7 @@ if (Support.dialectIsMySQL()) {
describe('HasMany', function() { describe('HasMany', function() {
beforeEach(function(done) { beforeEach(function() {
//prevent periods from occurring in the table name since they are used to delimit (table.column) //prevent periods from occurring in the table name since they are used to delimit (table.column)
this.User = this.sequelize.define('User' + Math.ceil(Math.random() * 10000000), { name: DataTypes.STRING }); this.User = this.sequelize.define('User' + Math.ceil(Math.random() * 10000000), { name: DataTypes.STRING });
this.Task = this.sequelize.define('Task' + Math.ceil(Math.random() * 10000000), { name: DataTypes.STRING }); this.Task = this.sequelize.define('Task' + Math.ceil(Math.random() * 10000000), { name: DataTypes.STRING });
...@@ -72,40 +69,36 @@ if (Support.dialectIsMySQL()) { ...@@ -72,40 +69,36 @@ if (Support.dialectIsMySQL()) {
tasks[tasks.length] = {name: 'Task' + Math.random()}; tasks[tasks.length] = {name: 'Task' + Math.random()};
} }
this.sequelize.sync({ force: true }).success(function() { return this.sequelize.sync({ force: true }).then(function() {
self.User.bulkCreate(users).success(function() { return self.User.bulkCreate(users).then(function() {
self.Task.bulkCreate(tasks).success(function() { return self.Task.bulkCreate(tasks);
done();
});
}); });
}); });
}); });
describe('addDAO / getDAO', function() { describe('addDAO / getDAO', function() {
beforeEach(function(done) { beforeEach(function() {
var self = this; var self = this;
self.user = null; self.user = null;
self.task = null; self.task = null;
self.User.all().success(function(_users) { return self.User.findAll().then(function(_users) {
self.Task.all().success(function(_tasks) { return self.Task.findAll().then(function(_tasks) {
self.user = _users[0]; self.user = _users[0];
self.task = _tasks[0]; self.task = _tasks[0];
done();
}); });
}); });
}); });
it('should correctly add an association to the dao', function(done) { it('should correctly add an association to the dao', function() {
var self = this; var self = this;
self.user.getTasks().on('success', function(_tasks) { return self.user.getTasks().then(function(_tasks) {
expect(_tasks.length).to.equal(0); expect(_tasks.length).to.equal(0);
self.user.addTask(self.task).on('success', function() { return self.user.addTask(self.task).then(function() {
self.user.getTasks().on('success', function(_tasks) { return self.user.getTasks().then(function(_tasks) {
expect(_tasks.length).to.equal(1); expect(_tasks.length).to.equal(1);
done();
}); });
}); });
}); });
...@@ -113,36 +106,34 @@ if (Support.dialectIsMySQL()) { ...@@ -113,36 +106,34 @@ if (Support.dialectIsMySQL()) {
}); });
describe('removeDAO', function() { describe('removeDAO', function() {
beforeEach(function(done) { beforeEach(function() {
var self = this; var self = this;
self.user = null; self.user = null;
self.tasks = null; self.tasks = null;
self.User.all().success(function(_users) { return self.User.findAll().then(function(_users) {
self.Task.all().success(function(_tasks) { return self.Task.findAll().then(function(_tasks) {
self.user = _users[0]; self.user = _users[0];
self.tasks = _tasks; self.tasks = _tasks;
done();
}); });
}); });
}); });
it('should correctly remove associated objects', function(done) { it('should correctly remove associated objects', function() {
var self = this; var self = this;
self.user.getTasks().on('success', function(__tasks) { return self.user.getTasks().then(function(__tasks) {
expect(__tasks.length).to.equal(0); expect(__tasks.length).to.equal(0);
self.user.setTasks(self.tasks).on('success', function() { return self.user.setTasks(self.tasks).then(function() {
self.user.getTasks().on('success', function(_tasks) { return self.user.getTasks().then(function(_tasks) {
expect(_tasks.length).to.equal(self.tasks.length); expect(_tasks.length).to.equal(self.tasks.length);
self.user.removeTask(self.tasks[0]).on('success', function() { return self.user.removeTask(self.tasks[0]).then(function() {
self.user.getTasks().on('success', function(_tasks) { return self.user.getTasks().then(function(_tasks) {
expect(_tasks.length).to.equal(self.tasks.length - 1); expect(_tasks.length).to.equal(self.tasks.length - 1);
self.user.removeTasks([self.tasks[1], self.tasks[2]]).on('success', function() { return self.user.removeTasks([self.tasks[1], self.tasks[2]]).then(function() {
self.user.getTasks().on('success', function(_tasks) { return self.user.getTasks().then(function(_tasks) {
expect(_tasks).to.have.length(self.tasks.length - 3); expect(_tasks).to.have.length(self.tasks.length - 3);
done();
}); });
}); });
}); });
......
...@@ -10,25 +10,25 @@ chai.config.includeStack = true; ...@@ -10,25 +10,25 @@ chai.config.includeStack = true;
if (Support.dialectIsMySQL()) { if (Support.dialectIsMySQL()) {
describe('[MYSQL Specific] Connector Manager', function() { describe('[MYSQL Specific] Connector Manager', function() {
it('works correctly after being idle', function(done) { it('works correctly after being idle', function() {
var User = this.sequelize.define('User', { username: DataTypes.STRING }) var User = this.sequelize.define('User', { username: DataTypes.STRING })
, spy = sinon.spy(); , spy = sinon.spy()
, self = this;
User.sync({force: true}).on('success', function() { return User.sync({force: true}).then(function() {
User.create({username: 'user1'}).on('success', function() { return User.create({username: 'user1'}).then(function() {
User.count().on('success', function(count) { return User.count().then(function(count) {
expect(count).to.equal(1); expect(count).to.equal(1);
spy(); spy();
return self.sequelize.Promise.delay(1000).then(function() {
setTimeout(function() { return User.count().then(function(count) {
User.count().on('success', function(count) {
expect(count).to.equal(1); expect(count).to.equal(1);
spy(); spy();
if (spy.calledTwice) { if (!spy.calledTwice) {
done(); throw new Error('Spy was not called twice');
} }
}); });
}, 1000); });
}); });
}); });
}); });
......
...@@ -11,81 +11,71 @@ chai.config.includeStack = true; ...@@ -11,81 +11,71 @@ chai.config.includeStack = true;
if (Support.dialectIsMySQL()) { if (Support.dialectIsMySQL()) {
describe('[MYSQL Specific] DAOFactory', function() { describe('[MYSQL Specific] DAOFactory', function() {
describe('constructor', function() { describe('constructor', function() {
it('handles extended attributes (unique)', function(done) { it('handles extended attributes (unique)', function() {
var User = this.sequelize.define('User' + config.rand(), { var User = this.sequelize.define('User' + config.rand(), {
username: { type: DataTypes.STRING, unique: true } username: { type: DataTypes.STRING, unique: true }
}, { timestamps: false }); }, { timestamps: false });
expect(this.sequelize.getQueryInterface().QueryGenerator.attributesToSQL(User.attributes)).to.deep.equal({username: 'VARCHAR(255) UNIQUE', id: 'INTEGER NOT NULL auto_increment PRIMARY KEY'}); expect(this.sequelize.getQueryInterface().QueryGenerator.attributesToSQL(User.attributes)).to.deep.equal({username: 'VARCHAR(255) UNIQUE', id: 'INTEGER NOT NULL auto_increment PRIMARY KEY'});
done();
}); });
it('handles extended attributes (default)', function(done) { it('handles extended attributes (default)', function() {
var User = this.sequelize.define('User' + config.rand(), { var User = this.sequelize.define('User' + config.rand(), {
username: {type: DataTypes.STRING, defaultValue: 'foo'} username: {type: DataTypes.STRING, defaultValue: 'foo'}
}, { timestamps: false }); }, { timestamps: false });
expect(this.sequelize.getQueryInterface().QueryGenerator.attributesToSQL(User.attributes)).to.deep.equal({username: "VARCHAR(255) DEFAULT 'foo'", id: 'INTEGER NOT NULL auto_increment PRIMARY KEY'}); expect(this.sequelize.getQueryInterface().QueryGenerator.attributesToSQL(User.attributes)).to.deep.equal({username: "VARCHAR(255) DEFAULT 'foo'", id: 'INTEGER NOT NULL auto_increment PRIMARY KEY'});
done();
}); });
it('handles extended attributes (null)', function(done) { it('handles extended attributes (null)', function() {
var User = this.sequelize.define('User' + config.rand(), { var User = this.sequelize.define('User' + config.rand(), {
username: {type: DataTypes.STRING, allowNull: false} username: {type: DataTypes.STRING, allowNull: false}
}, { timestamps: false }); }, { timestamps: false });
expect(this.sequelize.getQueryInterface().QueryGenerator.attributesToSQL(User.attributes)).to.deep.equal({username: 'VARCHAR(255) NOT NULL', id: 'INTEGER NOT NULL auto_increment PRIMARY KEY'}); expect(this.sequelize.getQueryInterface().QueryGenerator.attributesToSQL(User.attributes)).to.deep.equal({username: 'VARCHAR(255) NOT NULL', id: 'INTEGER NOT NULL auto_increment PRIMARY KEY'});
done();
}); });
it('handles extended attributes (primaryKey)', function(done) { it('handles extended attributes (primaryKey)', function() {
var User = this.sequelize.define('User' + config.rand(), { var User = this.sequelize.define('User' + config.rand(), {
username: {type: DataTypes.STRING, primaryKey: true} username: {type: DataTypes.STRING, primaryKey: true}
}, { timestamps: false }); }, { timestamps: false });
expect(this.sequelize.getQueryInterface().QueryGenerator.attributesToSQL(User.attributes)).to.deep.equal({username: 'VARCHAR(255) PRIMARY KEY'}); expect(this.sequelize.getQueryInterface().QueryGenerator.attributesToSQL(User.attributes)).to.deep.equal({username: 'VARCHAR(255) PRIMARY KEY'});
done();
}); });
it('adds timestamps', function(done) { it('adds timestamps', function() {
var User1 = this.sequelize.define('User' + config.rand(), {}); var User1 = this.sequelize.define('User' + config.rand(), {});
var User2 = this.sequelize.define('User' + config.rand(), {}, { timestamps: true }); var User2 = this.sequelize.define('User' + config.rand(), {}, { timestamps: true });
expect(this.sequelize.getQueryInterface().QueryGenerator.attributesToSQL(User1.attributes)).to.deep.equal({id: 'INTEGER NOT NULL auto_increment PRIMARY KEY', updatedAt: 'DATETIME NOT NULL', createdAt: 'DATETIME NOT NULL'}); expect(this.sequelize.getQueryInterface().QueryGenerator.attributesToSQL(User1.attributes)).to.deep.equal({id: 'INTEGER NOT NULL auto_increment PRIMARY KEY', updatedAt: 'DATETIME NOT NULL', createdAt: 'DATETIME NOT NULL'});
expect(this.sequelize.getQueryInterface().QueryGenerator.attributesToSQL(User2.attributes)).to.deep.equal({id: 'INTEGER NOT NULL auto_increment PRIMARY KEY', updatedAt: 'DATETIME NOT NULL', createdAt: 'DATETIME NOT NULL'}); expect(this.sequelize.getQueryInterface().QueryGenerator.attributesToSQL(User2.attributes)).to.deep.equal({id: 'INTEGER NOT NULL auto_increment PRIMARY KEY', updatedAt: 'DATETIME NOT NULL', createdAt: 'DATETIME NOT NULL'});
done();
}); });
it('adds deletedAt if paranoid', function(done) { it('adds deletedAt if paranoid', function() {
var User = this.sequelize.define('User' + config.rand(), {}, { paranoid: true }); var User = this.sequelize.define('User' + config.rand(), {}, { paranoid: true });
expect(this.sequelize.getQueryInterface().QueryGenerator.attributesToSQL(User.attributes)).to.deep.equal({id: 'INTEGER NOT NULL auto_increment PRIMARY KEY', deletedAt: 'DATETIME', updatedAt: 'DATETIME NOT NULL', createdAt: 'DATETIME NOT NULL'}); expect(this.sequelize.getQueryInterface().QueryGenerator.attributesToSQL(User.attributes)).to.deep.equal({id: 'INTEGER NOT NULL auto_increment PRIMARY KEY', deletedAt: 'DATETIME', updatedAt: 'DATETIME NOT NULL', createdAt: 'DATETIME NOT NULL'});
done();
}); });
it('underscores timestamps if underscored', function(done) { it('underscores timestamps if underscored', function() {
var User = this.sequelize.define('User' + config.rand(), {}, { paranoid: true, underscored: true }); var User = this.sequelize.define('User' + config.rand(), {}, { paranoid: true, underscored: true });
expect(this.sequelize.getQueryInterface().QueryGenerator.attributesToSQL(User.attributes)).to.deep.equal({id: 'INTEGER NOT NULL auto_increment PRIMARY KEY', deleted_at: 'DATETIME', updated_at: 'DATETIME NOT NULL', created_at: 'DATETIME NOT NULL'}); expect(this.sequelize.getQueryInterface().QueryGenerator.attributesToSQL(User.attributes)).to.deep.equal({id: 'INTEGER NOT NULL auto_increment PRIMARY KEY', deleted_at: 'DATETIME', updated_at: 'DATETIME NOT NULL', created_at: 'DATETIME NOT NULL'});
done();
}); });
it('omits text fields with defaultValues', function(done) { it('omits text fields with defaultValues', function() {
var User = this.sequelize.define('User' + config.rand(), {name: {type: DataTypes.TEXT, defaultValue: 'helloworld'}}); var User = this.sequelize.define('User' + config.rand(), {name: {type: DataTypes.TEXT, defaultValue: 'helloworld'}});
expect(User.attributes.name.type.toString()).to.equal('TEXT'); expect(User.attributes.name.type.toString()).to.equal('TEXT');
done();
}); });
it('omits blobs fields with defaultValues', function(done) { it('omits blobs fields with defaultValues', function() {
var User = this.sequelize.define('User' + config.rand(), {name: {type: DataTypes.STRING.BINARY, defaultValue: 'helloworld'}}); var User = this.sequelize.define('User' + config.rand(), {name: {type: DataTypes.STRING.BINARY, defaultValue: 'helloworld'}});
expect(User.attributes.name.type.toString()).to.equal('VARCHAR(255) BINARY'); expect(User.attributes.name.type.toString()).to.equal('VARCHAR(255) BINARY');
done();
}); });
}); });
describe('primaryKeys', function() { describe('primaryKeys', function() {
it('determines the correct primaryKeys', function(done) { it('determines the correct primaryKeys', function() {
var User = this.sequelize.define('User' + config.rand(), { var User = this.sequelize.define('User' + config.rand(), {
foo: {type: DataTypes.STRING, primaryKey: true}, foo: {type: DataTypes.STRING, primaryKey: true},
bar: DataTypes.STRING bar: DataTypes.STRING
}); });
expect(this.sequelize.getQueryInterface().QueryGenerator.attributesToSQL(User.primaryKeys)).to.deep.equal({'foo': 'VARCHAR(255) PRIMARY KEY'}); expect(this.sequelize.getQueryInterface().QueryGenerator.attributesToSQL(User.primaryKeys)).to.deep.equal({'foo': 'VARCHAR(255) PRIMARY KEY'});
done();
}); });
}); });
}); });
......
...@@ -56,7 +56,7 @@ if (dialect.match(/^postgres/)) { ...@@ -56,7 +56,7 @@ if (dialect.match(/^postgres/)) {
describe('HasMany', function() { describe('HasMany', function() {
describe('addDAO / getDAO', function() { describe('addDAO / getDAO', function() {
beforeEach(function(done) { beforeEach(function() {
var self = this; var self = this;
//prevent periods from occurring in the table name since they are used to delimit (table.column) //prevent periods from occurring in the table name since they are used to delimit (table.column)
...@@ -79,14 +79,13 @@ if (dialect.match(/^postgres/)) { ...@@ -79,14 +79,13 @@ if (dialect.match(/^postgres/)) {
tasks[tasks.length] = {name: 'Task' + Math.random()}; tasks[tasks.length] = {name: 'Task' + Math.random()};
} }
this.sequelize.sync({ force: true }).success(function() { return this.sequelize.sync({ force: true }).then(function() {
self.User.bulkCreate(users).success(function() { return self.User.bulkCreate(users).then(function() {
self.Task.bulkCreate(tasks).success(function() { return self.Task.bulkCreate(tasks).then(function() {
self.User.all().success(function(_users) { return self.User.findAll().then(function(_users) {
self.Task.all().success(function(_tasks) { return self.Task.findAll().then(function(_tasks) {
self.user = _users[0]; self.user = _users[0];
self.task = _tasks[0]; self.task = _tasks[0];
done();
}); });
}); });
}); });
...@@ -94,15 +93,14 @@ if (dialect.match(/^postgres/)) { ...@@ -94,15 +93,14 @@ if (dialect.match(/^postgres/)) {
}); });
}); });
it('should correctly add an association to the dao', function(done) { it('should correctly add an association to the dao', function() {
var self = this; var self = this;
self.user.getTasks().on('success', function(_tasks) { return self.user.getTasks().then(function(_tasks) {
expect(_tasks).to.have.length(0); expect(_tasks).to.have.length(0);
self.user.addTask(self.task).on('success', function() { return self.user.addTask(self.task).then(function() {
self.user.getTasks().on('success', function(_tasks) { return self.user.getTasks().then(function(_tasks) {
expect(_tasks).to.have.length(1); expect(_tasks).to.have.length(1);
done();
}); });
}); });
}); });
...@@ -110,7 +108,7 @@ if (dialect.match(/^postgres/)) { ...@@ -110,7 +108,7 @@ if (dialect.match(/^postgres/)) {
}); });
describe('removeDAO', function() { describe('removeDAO', function() {
it('should correctly remove associated objects', function(done) { it('should correctly remove associated objects', function() {
var self = this var self = this
, users = [] , users = []
, tasks = []; , tasks = [];
...@@ -132,30 +130,27 @@ if (dialect.match(/^postgres/)) { ...@@ -132,30 +130,27 @@ if (dialect.match(/^postgres/)) {
tasks[tasks.length] = {id: x + 1, name: 'Task' + Math.random()}; tasks[tasks.length] = {id: x + 1, name: 'Task' + Math.random()};
} }
this.sequelize.sync({ force: true }).success(function() { return this.sequelize.sync({ force: true }).then(function() {
self.User.bulkCreate(users).done(function(err) { return self.User.bulkCreate(users).then(function() {
expect(err).not.to.be.ok; return self.Task.bulkCreate(tasks).then(function() {
self.Task.bulkCreate(tasks).done(function(err) { return self.User.findAll().then(function(_users) {
expect(err).not.to.be.ok; return self.Task.findAll().then(function(_tasks) {
self.User.all().success(function(_users) {
self.Task.all().success(function(_tasks) {
self.user = _users[0]; self.user = _users[0];
self.task = _tasks[0]; self.task = _tasks[0];
self.users = _users; self.users = _users;
self.tasks = _tasks; self.tasks = _tasks;
self.user.getTasks().on('success', function(__tasks) { return self.user.getTasks().then(function(__tasks) {
expect(__tasks).to.have.length(0); expect(__tasks).to.have.length(0);
self.user.setTasks(self.tasks).on('success', function() { return self.user.setTasks(self.tasks).then(function() {
self.user.getTasks().on('success', function(_tasks) { return self.user.getTasks().then(function(_tasks) {
expect(_tasks).to.have.length(self.tasks.length); expect(_tasks).to.have.length(self.tasks.length);
self.user.removeTask(self.tasks[0]).on('success', function() { return self.user.removeTask(self.tasks[0]).then(function() {
self.user.getTasks().on('success', function(_tasks) { return self.user.getTasks().then(function(_tasks) {
expect(_tasks).to.have.length(self.tasks.length - 1); expect(_tasks).to.have.length(self.tasks.length - 1);
self.user.removeTasks([self.tasks[1], self.tasks[2]]).on('success', function() { return self.user.removeTasks([self.tasks[1], self.tasks[2]]).then(function() {
self.user.getTasks().on('success', function(_tasks) { return self.user.getTasks().then(function(_tasks) {
expect(_tasks).to.have.length(self.tasks.length - 3); expect(_tasks).to.have.length(self.tasks.length - 3);
done();
}); });
}); });
}); });
......
...@@ -23,9 +23,8 @@ if (dialect.match(/^postgres/)) { ...@@ -23,9 +23,8 @@ if (dialect.match(/^postgres/)) {
expect(hstore.stringify({ foo: null })).to.equal('"foo"=>NULL'); expect(hstore.stringify({ foo: null })).to.equal('"foo"=>NULL');
}); });
it('should handle empty string correctly', function(done) { it('should handle empty string correctly', function() {
expect(hstore.stringify({foo: ''})).to.equal('"foo"=>\"\"'); expect(hstore.stringify({foo: ''})).to.equal('"foo"=>\"\"');
done();
}); });
it('should handle a string with backslashes correctly', function() { it('should handle a string with backslashes correctly', function() {
......
...@@ -26,11 +26,10 @@ if (dialect.match(/^postgres/)) { ...@@ -26,11 +26,10 @@ if (dialect.match(/^postgres/)) {
expect(range.stringify([1, 2, 3])).to.equal(''); expect(range.stringify([1, 2, 3])).to.equal('');
}); });
it('should return empty string when non-array parameter is passed', function (done) { it('should return empty string when non-array parameter is passed', function () {
expect(range.stringify({})).to.equal(''); expect(range.stringify({})).to.equal('');
expect(range.stringify('test')).to.equal(''); expect(range.stringify('test')).to.equal('');
expect(range.stringify(undefined)).to.equal(''); expect(range.stringify(undefined)).to.equal('');
done();
}); });
it('should handle array of objects with `inclusive` and `value` properties', function () { it('should handle array of objects with `inclusive` and `value` properties', function () {
......
...@@ -12,147 +12,131 @@ chai.config.includeStack = true; ...@@ -12,147 +12,131 @@ chai.config.includeStack = true;
if (dialect === 'sqlite') { if (dialect === 'sqlite') {
describe('[SQLITE Specific] DAOFactory', function() { describe('[SQLITE Specific] DAOFactory', function() {
after(function(done) { after(function() {
this.sequelize.options.storage = ':memory:'; this.sequelize.options.storage = ':memory:';
done();
}); });
beforeEach(function(done) { beforeEach(function() {
this.sequelize.options.storage = dbFile; this.sequelize.options.storage = dbFile;
this.User = this.sequelize.define('User', { this.User = this.sequelize.define('User', {
age: DataTypes.INTEGER, age: DataTypes.INTEGER,
name: DataTypes.STRING, name: DataTypes.STRING,
bio: DataTypes.TEXT bio: DataTypes.TEXT
}); });
this.User.sync({ force: true }).success(function() { return this.User.sync({ force: true });
done();
});
}); });
storages.forEach(function(storage) { storages.forEach(function(storage) {
describe('with storage "' + storage + '"', function() { describe('with storage "' + storage + '"', function() {
after(function(done) { after(function() {
if (storage === dbFile) { if (storage === dbFile) {
require('fs').writeFile(dbFile, '', function() { require('fs').writeFileSync(dbFile, '');
done();
});
} }
}); });
describe('create', function() { describe('create', function() {
it('creates a table entry', function(done) { it('creates a table entry', function() {
var self = this; var self = this;
this.User.create({ age: 21, name: 'John Wayne', bio: 'noot noot' }).success(function(user) { return this.User.create({ age: 21, name: 'John Wayne', bio: 'noot noot' }).then(function(user) {
expect(user.age).to.equal(21); expect(user.age).to.equal(21);
expect(user.name).to.equal('John Wayne'); expect(user.name).to.equal('John Wayne');
expect(user.bio).to.equal('noot noot'); expect(user.bio).to.equal('noot noot');
self.User.all().success(function(users) { return self.User.findAll().then(function(users) {
var usernames = users.map(function(user) { var usernames = users.map(function(user) {
return user.name; return user.name;
}); });
expect(usernames).to.contain('John Wayne'); expect(usernames).to.contain('John Wayne');
done();
}); });
}); });
}); });
it('should allow the creation of an object with options as attribute', function(done) { it('should allow the creation of an object with options as attribute', function() {
var Person = this.sequelize.define('Person', { var Person = this.sequelize.define('Person', {
name: DataTypes.STRING, name: DataTypes.STRING,
options: DataTypes.TEXT options: DataTypes.TEXT
}); });
Person.sync({ force: true }).success(function() { return Person.sync({ force: true }).then(function() {
var options = JSON.stringify({ foo: 'bar', bar: 'foo' }); var options = JSON.stringify({ foo: 'bar', bar: 'foo' });
Person.create({ return Person.create({
name: 'John Doe', name: 'John Doe',
options: options options: options
}).success(function(people) { }).then(function(people) {
expect(people.options).to.deep.equal(options); expect(people.options).to.deep.equal(options);
done();
}); });
}); });
}); });
it('should allow the creation of an object with a boolean (true) as attribute', function(done) { it('should allow the creation of an object with a boolean (true) as attribute', function() {
var Person = this.sequelize.define('Person', { var Person = this.sequelize.define('Person', {
name: DataTypes.STRING, name: DataTypes.STRING,
has_swag: DataTypes.BOOLEAN has_swag: DataTypes.BOOLEAN
}); });
Person.sync({ force: true }).success(function() { return Person.sync({ force: true }).then(function() {
Person.create({ return Person.create({
name: 'John Doe', name: 'John Doe',
has_swag: true has_swag: true
}).success(function(people) { }).then(function(people) {
expect(people.has_swag).to.be.ok; expect(people.has_swag).to.be.ok;
done();
}); });
}); });
}); });
it('should allow the creation of an object with a boolean (false) as attribute', function(done) { it('should allow the creation of an object with a boolean (false) as attribute', function() {
var Person = this.sequelize.define('Person', { var Person = this.sequelize.define('Person', {
name: DataTypes.STRING, name: DataTypes.STRING,
has_swag: DataTypes.BOOLEAN has_swag: DataTypes.BOOLEAN
}); });
Person.sync({ force: true }).success(function() { return Person.sync({ force: true }).then(function() {
Person.create({ return Person.create({
name: 'John Doe', name: 'John Doe',
has_swag: false has_swag: false
}).success(function(people) { }).then(function(people) {
expect(people.has_swag).to.not.be.ok; expect(people.has_swag).to.not.be.ok;
done();
}); });
}); });
}); });
}); });
describe('.find', function() { describe('.find', function() {
beforeEach(function(done) { beforeEach(function() {
this.User.create({name: 'user', bio: 'footbar'}).success(function() { return this.User.create({name: 'user', bio: 'footbar'});
done();
});
}); });
it('finds normal lookups', function(done) { it('finds normal lookups', function() {
this.User.find({ where: { name: 'user' } }).success(function(user) { return this.User.find({ where: { name: 'user' } }).then(function(user) {
expect(user.name).to.equal('user'); expect(user.name).to.equal('user');
done();
}); });
}); });
it.skip('should make aliased attributes available', function(done) { it.skip('should make aliased attributes available', function() {
this.User.find({ where: { name: 'user' }, attributes: ['id', ['name', 'username']] }).success(function(user) { return this.User.find({ where: { name: 'user' }, attributes: ['id', ['name', 'username']] }).then(function(user) {
expect(user.username).to.equal('user'); expect(user.username).to.equal('user');
done();
}); });
}); });
}); });
describe('.all', function() { describe('.all', function() {
beforeEach(function(done) { beforeEach(function() {
this.User.bulkCreate([ return this.User.bulkCreate([
{name: 'user', bio: 'foobar'}, {name: 'user', bio: 'foobar'},
{name: 'user', bio: 'foobar'} {name: 'user', bio: 'foobar'}
]).success(function() { ]);
done();
});
}); });
it('should return all users', function(done) { it('should return all users', function() {
this.User.all().on('success', function(users) { return this.User.findAll().then(function(users) {
expect(users).to.have.length(2); expect(users).to.have.length(2);
done();
}); });
}); });
}); });
describe('.min', function() { describe('.min', function() {
it('should return the min value', function(done) { it('should return the min value', function() {
var self = this var self = this
, users = []; , users = [];
...@@ -160,17 +144,16 @@ if (dialect === 'sqlite') { ...@@ -160,17 +144,16 @@ if (dialect === 'sqlite') {
users[users.length] = {age: i}; users[users.length] = {age: i};
} }
this.User.bulkCreate(users).success(function() { return this.User.bulkCreate(users).then(function() {
self.User.min('age').on('success', function(min) { return self.User.min('age').then(function(min) {
expect(min).to.equal(2); expect(min).to.equal(2);
done();
}); });
}); });
}); });
}); });
describe('.max', function() { describe('.max', function() {
it('should return the max value', function(done) { it('should return the max value', function() {
var self = this var self = this
, users = []; , users = [];
...@@ -178,10 +161,9 @@ if (dialect === 'sqlite') { ...@@ -178,10 +161,9 @@ if (dialect === 'sqlite') {
users[users.length] = {age: i}; users[users.length] = {age: i};
} }
this.User.bulkCreate(users).success(function() { return this.User.bulkCreate(users).then(function() {
self.User.max('age').on('success', function(min) { return self.User.max('age').then(function(min) {
expect(min).to.equal(5); expect(min).to.equal(5);
done();
}); });
}); });
}); });
......
...@@ -10,29 +10,26 @@ chai.config.includeStack = true; ...@@ -10,29 +10,26 @@ chai.config.includeStack = true;
if (dialect === 'sqlite') { if (dialect === 'sqlite') {
describe('[SQLITE Specific] DAO', function() { describe('[SQLITE Specific] DAO', function() {
beforeEach(function(done) { beforeEach(function() {
this.User = this.sequelize.define('User', { this.User = this.sequelize.define('User', {
username: DataTypes.STRING username: DataTypes.STRING
}); });
this.User.sync({ force: true }).success(function() { return this.User.sync({ force: true });
done();
});
}); });
describe('findAll', function() { describe('findAll', function() {
it('handles dates correctly', function(done) { it('handles dates correctly', function() {
var self = this var self = this
, user = this.User.build({ username: 'user' }); , user = this.User.build({ username: 'user' });
user.dataValues['createdAt'] = new Date(2011, 4, 4); user.dataValues['createdAt'] = new Date(2011, 4, 4);
user.save().success(function() { return user.save().then(function() {
self.User.create({ username: 'new user' }).success(function() { return self.User.create({ username: 'new user' }).then(function() {
self.User.findAll({ return self.User.findAll({
where: ['createdAt > ?', new Date(2012, 1, 1)] where: ['createdAt > ?', new Date(2012, 1, 1)]
}).success(function(users) { }).then(function(users) {
expect(users).to.have.length(1); expect(users).to.have.length(1);
done();
}); });
}); });
}); });
......
This diff could not be displayed because it is too large.
...@@ -7,7 +7,6 @@ var chai = require('chai') ...@@ -7,7 +7,6 @@ var chai = require('chai')
, Support = require(__dirname + '/support') , Support = require(__dirname + '/support')
, DataTypes = require(__dirname + '/../../lib/data-types') , DataTypes = require(__dirname + '/../../lib/data-types')
, datetime = require('chai-datetime') , datetime = require('chai-datetime')
, async = require('async')
, _ = require('lodash') , _ = require('lodash')
, dialect = Support.getTestDialect(); , dialect = Support.getTestDialect();
......
...@@ -6,8 +6,7 @@ var chai = require('chai') ...@@ -6,8 +6,7 @@ var chai = require('chai')
, Sequelize = require(__dirname + '/../../../index') , Sequelize = require(__dirname + '/../../../index')
, Promise = Sequelize.Promise , Promise = Sequelize.Promise
, DataTypes = require(__dirname + '/../../../lib/data-types') , DataTypes = require(__dirname + '/../../../lib/data-types')
, datetime = require('chai-datetime') , datetime = require('chai-datetime');
, async = require('async');
chai.use(datetime); chai.use(datetime);
chai.config.includeStack = true; chai.config.includeStack = true;
......
...@@ -210,8 +210,8 @@ describe(Support.getTestDialectTeaser('Includes with schemas'), function() { ...@@ -210,8 +210,8 @@ describe(Support.getTestDialectTeaser('Includes with schemas'), function() {
it('should support an include with multiple different association types', function(done) { it('should support an include with multiple different association types', function(done) {
var self = this; var self = this;
self.sequelize.dropAllSchemas().success(function() { self.sequelize.dropAllSchemas().then(function() {
self.sequelize.createSchema('account').success(function() { self.sequelize.createSchema('account').then(function() {
var AccUser = self.sequelize.define('AccUser', {}, {schema: 'account'}) var AccUser = self.sequelize.define('AccUser', {}, {schema: 'account'})
, Product = self.sequelize.define('Product', { , Product = self.sequelize.define('Product', {
title: DataTypes.STRING title: DataTypes.STRING
......
...@@ -60,19 +60,19 @@ describe(Support.getTestDialectTeaser('Instance'), function() { ...@@ -60,19 +60,19 @@ describe(Support.getTestDialectTeaser('Instance'), function() {
}); });
if (current.dialect.supports.transactions) { if (current.dialect.supports.transactions) {
it('supports transactions', function(done) { it('supports transactions', function() {
Support.prepareTransactionTest(this.sequelize, function(sequelize) { return Support.prepareTransactionTest(this.sequelize).bind({}).then(function(sequelize) {
var User = sequelize.define('User', { username: Support.Sequelize.STRING }); var User = sequelize.define('User', { username: Support.Sequelize.STRING });
User.sync({ force: true }).success(function() { return User.sync({ force: true }).then(function() {
User.create({ username: 'foo' }).success(function(user) { return User.create({ username: 'foo' }).then(function(user) {
sequelize.transaction().then(function(t) { return sequelize.transaction().then(function(t) {
user.update({ username: 'bar' }, { transaction: t }).success(function() { return user.update({ username: 'bar' }, { transaction: t }).then(function() {
User.all().success(function(users1) { return User.findAll().then(function(users1) {
User.all({ transaction: t }).success(function(users2) { return User.findAll({ transaction: t }).then(function(users2) {
expect(users1[0].username).to.equal('foo'); expect(users1[0].username).to.equal('foo');
expect(users2[0].username).to.equal('bar'); expect(users2[0].username).to.equal('bar');
t.rollback().success(function() { done(); }); return t.rollback();
}); });
}); });
}); });
...@@ -325,88 +325,84 @@ describe(Support.getTestDialectTeaser('Instance'), function() { ...@@ -325,88 +325,84 @@ describe(Support.getTestDialectTeaser('Instance'), function() {
}); });
}); });
it('updates attributes in the database', function(done) { it('updates attributes in the database', function() {
this.User.create({ username: 'user' }).success(function(user) { return this.User.create({ username: 'user' }).then(function(user) {
expect(user.username).to.equal('user'); expect(user.username).to.equal('user');
user.update({ username: 'person' }).success(function(user) { return user.update({ username: 'person' }).then(function(user) {
expect(user.username).to.equal('person'); expect(user.username).to.equal('person');
done();
}); });
}); });
}); });
it('ignores unknown attributes', function(done) { it('ignores unknown attributes', function() {
this.User.create({ username: 'user' }).success(function(user) { return this.User.create({ username: 'user' }).then(function(user) {
user.update({ username: 'person', foo: 'bar'}).success(function(user) { return user.update({ username: 'person', foo: 'bar'}).then(function(user) {
expect(user.username).to.equal('person'); expect(user.username).to.equal('person');
expect(user.foo).not.to.exist; expect(user.foo).not.to.exist;
done();
}); });
}); });
}); });
it("doesn't update primary keys or timestamps", function(done) { it("doesn't update primary keys or timestamps", function() {
var User = this.sequelize.define('User' + config.rand(), { var User = this.sequelize.define('User' + config.rand(), {
name: DataTypes.STRING, name: DataTypes.STRING,
bio: DataTypes.TEXT, bio: DataTypes.TEXT,
identifier: {type: DataTypes.STRING, primaryKey: true} identifier: {type: DataTypes.STRING, primaryKey: true}
}); });
User.sync({ force: true }).success(function() { return User.sync({ force: true }).then(function() {
User.create({ return User.create({
name: 'snafu', name: 'snafu',
identifier: 'identifier' identifier: 'identifier'
}).success(function(user) { }).then(function(user) {
var oldCreatedAt = user.createdAt var oldCreatedAt = user.createdAt
, oldUpdatedAt = user.updatedAt , oldUpdatedAt = user.updatedAt
, oldIdentifier = user.identifier; , oldIdentifier = user.identifier;
setTimeout(function() { return this.sequelize.Promise.delay(1000).then(function() {
user.update({ return user.update({
name: 'foobar', name: 'foobar',
createdAt: new Date(2000, 1, 1), createdAt: new Date(2000, 1, 1),
identifier: 'another identifier' identifier: 'another identifier'
}).success(function(user) { }).then(function(user) {
expect(new Date(user.createdAt)).to.equalDate(new Date(oldCreatedAt)); expect(new Date(user.createdAt)).to.equalDate(new Date(oldCreatedAt));
expect(new Date(user.updatedAt)).to.not.equalTime(new Date(oldUpdatedAt)); expect(new Date(user.updatedAt)).to.not.equalTime(new Date(oldUpdatedAt));
expect(user.identifier).to.equal(oldIdentifier); expect(user.identifier).to.equal(oldIdentifier);
done();
}); });
}, 1000); });
}); });
}); });
}); });
it('stores and restores null values', function(done) { it('stores and restores null values', function() {
var Download = this.sequelize.define('download', { var Download = this.sequelize.define('download', {
startedAt: DataTypes.DATE, startedAt: DataTypes.DATE,
canceledAt: DataTypes.DATE, canceledAt: DataTypes.DATE,
finishedAt: DataTypes.DATE finishedAt: DataTypes.DATE
}); });
Download.sync().success(function() { return Download.sync().then(function() {
Download.create({ return Download.create({
startedAt: new Date() startedAt: new Date()
}).success(function(download) { }).then(function(download) {
expect(download.startedAt instanceof Date).to.be.true; expect(download.startedAt instanceof Date).to.be.true;
expect(download.canceledAt).to.not.be.ok; expect(download.canceledAt).to.not.be.ok;
expect(download.finishedAt).to.not.be.ok; expect(download.finishedAt).to.not.be.ok;
download.update({ return download.update({
canceledAt: new Date() canceledAt: new Date()
}).success(function(download) { }).then(function(download) {
expect(download.startedAt instanceof Date).to.be.true; expect(download.startedAt instanceof Date).to.be.true;
expect(download.canceledAt instanceof Date).to.be.true; expect(download.canceledAt instanceof Date).to.be.true;
expect(download.finishedAt).to.not.be.ok; expect(download.finishedAt).to.not.be.ok;
Download.all({ return Download.findAll({
where: (dialect === 'postgres' || dialect === 'mssql' ? '"finishedAt" IS NULL' : '`finishedAt` IS NULL') where: (dialect === 'postgres' || dialect === 'mssql' ? '"finishedAt" IS NULL' : '`finishedAt` IS NULL')
}).success(function(downloads) { }).then(function(downloads) {
downloads.forEach(function(download) { downloads.forEach(function(download) {
expect(download.startedAt instanceof Date).to.be.true; expect(download.startedAt instanceof Date).to.be.true;
expect(download.canceledAt instanceof Date).to.be.true; expect(download.canceledAt instanceof Date).to.be.true;
expect(download.finishedAt).to.not.be.ok; expect(download.finishedAt).to.not.be.ok;
done();
}); });
}); });
}); });
......
...@@ -295,7 +295,7 @@ describe(Support.getTestDialectTeaser('DAO'), function() { ...@@ -295,7 +295,7 @@ describe(Support.getTestDialectTeaser('DAO'), function() {
expect(product.toJSON()).to.deep.equal({withTaxes: 1250, price: 1000, id: null}); expect(product.toJSON()).to.deep.equal({withTaxes: 1250, price: 1000, id: null});
}); });
it('should work with save', function(done) { it('should work with save', function() {
var Contact = this.sequelize.define('Contact', { var Contact = this.sequelize.define('Contact', {
first: { type: Sequelize.STRING }, first: { type: Sequelize.STRING },
last: { type: Sequelize.STRING }, last: { type: Sequelize.STRING },
...@@ -311,7 +311,7 @@ describe(Support.getTestDialectTeaser('DAO'), function() { ...@@ -311,7 +311,7 @@ describe(Support.getTestDialectTeaser('DAO'), function() {
} }
}); });
this.sequelize.sync().done(function() { return this.sequelize.sync().then(function() {
var contact = Contact.build({ var contact = Contact.build({
first: 'My', first: 'My',
last: 'Name', last: 'Name',
...@@ -319,10 +319,8 @@ describe(Support.getTestDialectTeaser('DAO'), function() { ...@@ -319,10 +319,8 @@ describe(Support.getTestDialectTeaser('DAO'), function() {
}); });
expect(contact.get('tags')).to.deep.equal(['yes', 'no']); expect(contact.get('tags')).to.deep.equal(['yes', 'no']);
contact.save().done(function(err, me) { return contact.save().then(function(me) {
expect(err).not.to.be.ok;
expect(me.get('tags')).to.deep.equal(['yes', 'no']); expect(me.get('tags')).to.deep.equal(['yes', 'no']);
done();
}); });
}); });
}); });
...@@ -380,18 +378,16 @@ describe(Support.getTestDialectTeaser('DAO'), function() { ...@@ -380,18 +378,16 @@ describe(Support.getTestDialectTeaser('DAO'), function() {
}); });
describe('changed', function() { describe('changed', function() {
it('should return false if object was built from database', function(done) { it('should return false if object was built from database', function() {
var User = this.sequelize.define('User', { var User = this.sequelize.define('User', {
name: {type: DataTypes.STRING} name: {type: DataTypes.STRING}
}); });
User.sync().done(function() { return User.sync().then(function() {
User.create({name: 'Jan Meier'}).done(function(err, user) { return User.create({name: 'Jan Meier'}).then(function(user) {
expect(err).not.to.be.ok;
expect(user.changed('name')).to.be.false; expect(user.changed('name')).to.be.false;
expect(user.changed()).not.to.be.ok; expect(user.changed()).not.to.be.ok;
expect(user.isDirty).to.be.false; expect(user.isDirty).to.be.false;
done();
}); });
}); });
}); });
...@@ -410,12 +406,12 @@ describe(Support.getTestDialectTeaser('DAO'), function() { ...@@ -410,12 +406,12 @@ describe(Support.getTestDialectTeaser('DAO'), function() {
expect(user.isDirty).to.be.true; expect(user.isDirty).to.be.true;
}); });
it('should return false immediately after saving', function(done) { it('should return false immediately after saving', function() {
var User = this.sequelize.define('User', { var User = this.sequelize.define('User', {
name: {type: DataTypes.STRING} name: {type: DataTypes.STRING}
}); });
User.sync().done(function() { return User.sync().then(function() {
var user = User.build({ var user = User.build({
name: 'Jan Meier' name: 'Jan Meier'
}); });
...@@ -424,12 +420,10 @@ describe(Support.getTestDialectTeaser('DAO'), function() { ...@@ -424,12 +420,10 @@ describe(Support.getTestDialectTeaser('DAO'), function() {
expect(user.changed()).to.be.ok; expect(user.changed()).to.be.ok;
expect(user.isDirty).to.be.true; expect(user.isDirty).to.be.true;
user.save().done(function(err) { return user.save().then(function() {
expect(err).not.to.be.ok;
expect(user.changed('name')).to.be.false; expect(user.changed('name')).to.be.false;
expect(user.changed()).not.to.be.ok; expect(user.changed()).not.to.be.ok;
expect(user.isDirty).to.be.false; expect(user.isDirty).to.be.false;
done();
}); });
}); });
}); });
...@@ -472,7 +466,6 @@ describe(Support.getTestDialectTeaser('DAO'), function() { ...@@ -472,7 +466,6 @@ describe(Support.getTestDialectTeaser('DAO'), function() {
expect(changed).to.be.ok; expect(changed).to.be.ok;
expect(changed.length).to.be.ok; expect(changed.length).to.be.ok;
expect(changed.indexOf('name') > -1).to.be.ok; expect(changed.indexOf('name') > -1).to.be.ok;
expect(user.changed()).not.to.be.ok; expect(user.changed()).not.to.be.ok;
}); });
}); });
......
...@@ -12,7 +12,7 @@ chai.use(datetime); ...@@ -12,7 +12,7 @@ chai.use(datetime);
chai.config.includeStack = true; chai.config.includeStack = true;
describe(Support.getTestDialectTeaser('Model'), function() { describe(Support.getTestDialectTeaser('Model'), function() {
beforeEach(function(done) { beforeEach(function() {
this.User = this.sequelize.define('User', { this.User = this.sequelize.define('User', {
username: DataTypes.STRING, username: DataTypes.STRING,
secretValue: DataTypes.STRING, secretValue: DataTypes.STRING,
...@@ -22,17 +22,15 @@ describe(Support.getTestDialectTeaser('Model'), function() { ...@@ -22,17 +22,15 @@ describe(Support.getTestDialectTeaser('Model'), function() {
aBool: DataTypes.BOOLEAN aBool: DataTypes.BOOLEAN
}); });
this.User.sync({ force: true }).success(function() { return this.User.sync({ force: true });
done();
});
}); });
(['or', 'and']).forEach(function(method) { (['or', 'and']).forEach(function(method) {
var word = method.toUpperCase(); var word = method.toUpperCase();
describe.skip('Sequelize.' + method, function() { describe.skip('Sequelize.' + method, function() {
it('can handle plain strings', function(done) { it('can handle plain strings', function() {
this.User.find({ return this.User.find({
where: Sequelize[method]('1=1', '2=2') where: Sequelize[method]('1=1', '2=2')
}).on('sql', function(sql) { }).on('sql', function(sql) {
if (dialect === 'mssql') { if (dialect === 'mssql') {
...@@ -40,12 +38,11 @@ describe(Support.getTestDialectTeaser('Model'), function() { ...@@ -40,12 +38,11 @@ describe(Support.getTestDialectTeaser('Model'), function() {
}else { }else {
expect(sql).to.contain('WHERE (1=1 ' + word + ' 2=2) LIMIT 1'); expect(sql).to.contain('WHERE (1=1 ' + word + ' 2=2) LIMIT 1');
} }
done();
}); });
}); });
it('can handle arrays', function(done) { it('can handle arrays', function() {
this.User.find({ return this.User.find({
where: Sequelize[method](['1=?', 1], ['2=?', 2]) where: Sequelize[method](['1=?', 1], ['2=?', 2])
}).on('sql', function(sql) { }).on('sql', function(sql) {
if (dialect === 'mssql') { if (dialect === 'mssql') {
...@@ -53,12 +50,11 @@ describe(Support.getTestDialectTeaser('Model'), function() { ...@@ -53,12 +50,11 @@ describe(Support.getTestDialectTeaser('Model'), function() {
}else { }else {
expect(sql).to.contain('WHERE (1=1 ' + word + ' 2=2) LIMIT 1'); expect(sql).to.contain('WHERE (1=1 ' + word + ' 2=2) LIMIT 1');
} }
done();
}); });
}); });
it('can handle objects', function(done) { it('can handle objects', function() {
this.User.find({ return this.User.find({
where: Sequelize[method]({ username: 'foo', intVal: 2 }, { secretValue: 'bar' }) where: Sequelize[method]({ username: 'foo', intVal: 2 }, { secretValue: 'bar' })
}).on('sql', function(sql) { }).on('sql', function(sql) {
var expectation = ({ var expectation = ({
...@@ -75,13 +71,11 @@ describe(Support.getTestDialectTeaser('Model'), function() { ...@@ -75,13 +71,11 @@ describe(Support.getTestDialectTeaser('Model'), function() {
} }
expect(sql).to.contain(expectation); expect(sql).to.contain(expectation);
done();
}); });
}); });
it('can handle numbers', function(done) { it('can handle numbers', function() {
this.User.find({ return this.User.find({
where: Sequelize[method](1, 2) where: Sequelize[method](1, 2)
}).on('sql', function(sql) { }).on('sql', function(sql) {
var expectation = ({ var expectation = ({
...@@ -98,16 +92,14 @@ describe(Support.getTestDialectTeaser('Model'), function() { ...@@ -98,16 +92,14 @@ describe(Support.getTestDialectTeaser('Model'), function() {
} }
expect(sql).to.contain(expectation); expect(sql).to.contain(expectation);
done();
}); });
}); });
}); });
}); });
describe.skip('Combinations of Sequelize.and and Sequelize.or', function() { describe.skip('Combinations of Sequelize.and and Sequelize.or', function() {
it('allows nesting of Sequelize.or', function(done) { it('allows nesting of Sequelize.or', function() {
this.User.find({ return this.User.find({
where: Sequelize.and(Sequelize.or('1=1', '2=2'), Sequelize.or('3=3', '4=4')) where: Sequelize.and(Sequelize.or('1=1', '2=2'), Sequelize.or('3=3', '4=4'))
}).on('sql', function(sql) { }).on('sql', function(sql) {
if (dialect === 'mssql') { if (dialect === 'mssql') {
...@@ -115,12 +107,11 @@ describe(Support.getTestDialectTeaser('Model'), function() { ...@@ -115,12 +107,11 @@ describe(Support.getTestDialectTeaser('Model'), function() {
}else { }else {
expect(sql).to.contain('WHERE ((1=1 OR 2=2) AND (3=3 OR 4=4)) LIMIT 1'); expect(sql).to.contain('WHERE ((1=1 OR 2=2) AND (3=3 OR 4=4)) LIMIT 1');
} }
done();
}); });
}); });
it('allows nesting of Sequelize.or using object notation', function(done) { it('allows nesting of Sequelize.or using object notation', function() {
this.User.find({ return this.User.find({
where: Sequelize.and(Sequelize.or({username: {eq: 'foo'}}, {username: {eq: 'bar'}}), where: Sequelize.and(Sequelize.or({username: {eq: 'foo'}}, {username: {eq: 'bar'}}),
Sequelize.or({id: {eq: 1}}, {id: {eq: 4}})) Sequelize.or({id: {eq: 1}}, {id: {eq: 4}}))
}).on('sql', function(sql) { }).on('sql', function(sql) {
...@@ -138,12 +129,11 @@ describe(Support.getTestDialectTeaser('Model'), function() { ...@@ -138,12 +129,11 @@ describe(Support.getTestDialectTeaser('Model'), function() {
} }
expect(sql).to.contain(expectation); expect(sql).to.contain(expectation);
done();
}); });
}); });
it('allows nesting of Sequelize.and', function(done) { it('allows nesting of Sequelize.and', function() {
this.User.find({ return this.User.find({
where: Sequelize.or(Sequelize.and('1=1', '2=2'), Sequelize.and('3=3', '4=4')) where: Sequelize.or(Sequelize.and('1=1', '2=2'), Sequelize.and('3=3', '4=4'))
}).on('sql', function(sql) { }).on('sql', function(sql) {
if (dialect === 'mssql') { if (dialect === 'mssql') {
...@@ -151,12 +141,11 @@ describe(Support.getTestDialectTeaser('Model'), function() { ...@@ -151,12 +141,11 @@ describe(Support.getTestDialectTeaser('Model'), function() {
}else { }else {
expect(sql).to.contain('WHERE ((1=1 AND 2=2) OR (3=3 AND 4=4)) LIMIT 1'); expect(sql).to.contain('WHERE ((1=1 AND 2=2) OR (3=3 AND 4=4)) LIMIT 1');
} }
done();
}); });
}); });
it('allows nesting of Sequelize.and using object notation', function(done) { it('allows nesting of Sequelize.and using object notation', function() {
this.User.find({ return this.User.find({
where: Sequelize.or(Sequelize.and({username: {eq: 'foo'}}, {username: {eq: 'bar'}}), where: Sequelize.or(Sequelize.and({username: {eq: 'foo'}}, {username: {eq: 'bar'}}),
Sequelize.and({id: {eq: 1}}, {id: {eq: 4}})) Sequelize.and({id: {eq: 1}}, {id: {eq: 4}}))
}).on('sql', function(sql) { }).on('sql', function(sql) {
...@@ -174,24 +163,22 @@ describe(Support.getTestDialectTeaser('Model'), function() { ...@@ -174,24 +163,22 @@ describe(Support.getTestDialectTeaser('Model'), function() {
} }
expect(sql).to.contain(expectation); expect(sql).to.contain(expectation);
done();
}); });
}); });
if (dialect !== 'postgres') { if (dialect !== 'postgres') {
it('still allows simple arrays lookups', function(done) { it('still allows simple arrays lookups', function() {
this.User.find({ return this.User.find({
where: ['id IN (?) OR id IN (?)', [1, 2], [3, 4]] where: ['id IN (?) OR id IN (?)', [1, 2], [3, 4]]
}).on('sql', function(sql) { }).on('sql', function(sql) {
expect(sql).to.contain('id IN (1, 2) OR id IN (3, 4)'); expect(sql).to.contain('id IN (1, 2) OR id IN (3, 4)');
done();
}); });
}); });
} }
(['find', 'findAll']).forEach(function(finderMethod) { (['find', 'findAll']).forEach(function(finderMethod) {
it('correctly handles complex combinations', function(done) { it('correctly handles complex combinations', function() {
this.User[finderMethod]({ return this.User[finderMethod]({
where: [ where: [
42, '2=2', ['1=?', 1], { username: 'foo' }, 42, '2=2', ['1=?', 1], { username: 'foo' },
Sequelize.or( Sequelize.or(
...@@ -258,8 +245,6 @@ describe(Support.getTestDialectTeaser('Model'), function() { ...@@ -258,8 +245,6 @@ describe(Support.getTestDialectTeaser('Model'), function() {
')' ')'
); );
} }
done();
}); });
}); });
}); });
......
...@@ -10,7 +10,6 @@ var chai = require('chai') ...@@ -10,7 +10,6 @@ var chai = require('chai')
, datetime = require('chai-datetime') , datetime = require('chai-datetime')
, _ = require('lodash') , _ = require('lodash')
, moment = require('moment') , moment = require('moment')
, async = require('async')
, current = Support.sequelize; , current = Support.sequelize;
chai.use(datetime); chai.use(datetime);
......
...@@ -383,7 +383,7 @@ describe(Support.getTestDialectTeaser('Promise'), function() { ...@@ -383,7 +383,7 @@ describe(Support.getTestDialectTeaser('Promise'), function() {
resolve('yoohoo'); resolve('yoohoo');
}); });
promise.on('success', spy); promise.then(spy);
promise.then(function() { promise.then(function() {
expect(spy.calledOnce).to.be.true; expect(spy.calledOnce).to.be.true;
expect(spy.firstCall.args).to.deep.equal(['yoohoo']); expect(spy.firstCall.args).to.deep.equal(['yoohoo']);
......
...@@ -10,36 +10,23 @@ var chai = require('chai') ...@@ -10,36 +10,23 @@ var chai = require('chai')
chai.config.includeStack = true; chai.config.includeStack = true;
describe(Support.getTestDialectTeaser('QueryInterface'), function() { describe(Support.getTestDialectTeaser('QueryInterface'), function() {
beforeEach(function(done) { beforeEach(function() {
this.sequelize.options.quoteIdenifiers = true; this.sequelize.options.quoteIdenifiers = true;
this.queryInterface = this.sequelize.getQueryInterface(); this.queryInterface = this.sequelize.getQueryInterface();
done();
}); });
describe('dropAllTables', function() { describe('dropAllTables', function() {
it('should drop all tables', function(done) { it('should drop all tables', function() {
var self = this; var self = this;
this.queryInterface.dropAllTables().complete(function(err) { return this.queryInterface.dropAllTables().then(function() {
expect(err).to.be.null; return self.queryInterface.showAllTables().then(function(tableNames) {
self.queryInterface.showAllTables().complete(function(err, tableNames) {
expect(err).to.be.null;
expect(tableNames).to.be.empty; expect(tableNames).to.be.empty;
return self.queryInterface.createTable('table', { name: DataTypes.STRING }).then(function() {
self.queryInterface.createTable('table', { name: DataTypes.STRING }).complete(function(err) { return self.queryInterface.showAllTables().then(function(tableNames) {
expect(err).to.be.null;
self.queryInterface.showAllTables().complete(function(err, tableNames) {
expect(err).to.be.null;
expect(tableNames).to.have.length(1); expect(tableNames).to.have.length(1);
return self.queryInterface.dropAllTables().then(function() {
self.queryInterface.dropAllTables().complete(function(err) { return self.queryInterface.showAllTables().then(function(tableNames) {
expect(err).to.be.null;
self.queryInterface.showAllTables().complete(function(err, tableNames) {
expect(err).to.be.null;
expect(tableNames).to.be.empty; expect(tableNames).to.be.empty;
done();
}); });
}); });
}); });
...@@ -48,23 +35,17 @@ describe(Support.getTestDialectTeaser('QueryInterface'), function() { ...@@ -48,23 +35,17 @@ describe(Support.getTestDialectTeaser('QueryInterface'), function() {
}); });
}); });
it('should be able to skip given tables', function(done) { it('should be able to skip given tables', function() {
var self = this; var self = this;
self.queryInterface.createTable('skipme', { return self.queryInterface.createTable('skipme', {
name: DataTypes.STRING name: DataTypes.STRING
}).success(function() { }).then(function() {
self.queryInterface.dropAllTables({skip: ['skipme']}).complete(function(err) { return self.queryInterface.dropAllTables({skip: ['skipme']}).then(function() {
expect(err).to.be.null; return self.queryInterface.showAllTables().then(function(tableNames) {
self.queryInterface.showAllTables().complete(function(err, tableNames) {
expect(err).to.be.null;
if (dialect === 'mssql' /* current.dialect.supports.schemas */) { if (dialect === 'mssql' /* current.dialect.supports.schemas */) {
tableNames = _.pluck(tableNames, 'tableName'); tableNames = _.pluck(tableNames, 'tableName');
} }
expect(tableNames).to.contain('skipme'); expect(tableNames).to.contain('skipme');
done();
}); });
}); });
}); });
...@@ -72,41 +53,27 @@ describe(Support.getTestDialectTeaser('QueryInterface'), function() { ...@@ -72,41 +53,27 @@ describe(Support.getTestDialectTeaser('QueryInterface'), function() {
}); });
describe('indexes', function() { describe('indexes', function() {
beforeEach(function(done) { beforeEach(function() {
var self = this; var self = this;
this.queryInterface.dropTable('Group').success(function() { return this.queryInterface.dropTable('Group').then(function() {
self.queryInterface.createTable('Group', { return self.queryInterface.createTable('Group', {
username: DataTypes.STRING, username: DataTypes.STRING,
isAdmin: DataTypes.BOOLEAN, isAdmin: DataTypes.BOOLEAN,
from: DataTypes.STRING from: DataTypes.STRING
}).success(function() {
done();
}); });
}); });
}); });
it('adds, reads and removes an index to the table', function(done) { it('adds, reads and removes an index to the table', function() {
var self = this; var self = this;
return this.queryInterface.addIndex('Group', ['username', 'isAdmin']).then(function() {
this.queryInterface.addIndex('Group', ['username', 'isAdmin']).complete(function(err) { return self.queryInterface.showIndex('Group').then(function(indexes) {
expect(err).to.be.null;
self.queryInterface.showIndex('Group').complete(function(err, indexes) {
expect(err).to.be.null;
var indexColumns = _.uniq(indexes.map(function(index) { return index.name; })); var indexColumns = _.uniq(indexes.map(function(index) { return index.name; }));
expect(indexColumns).to.include('group_username_is_admin'); expect(indexColumns).to.include('group_username_is_admin');
return self.queryInterface.removeIndex('Group', ['username', 'isAdmin']).then(function() {
self.queryInterface.removeIndex('Group', ['username', 'isAdmin']).complete(function(err) { return self.queryInterface.showIndex('Group').then(function(indexes) {
expect(err).to.be.null;
self.queryInterface.showIndex('Group').complete(function(err, indexes) {
expect(err).to.be.null;
indexColumns = _.uniq(indexes.map(function(index) { return index.name; })); indexColumns = _.uniq(indexes.map(function(index) { return index.name; }));
expect(indexColumns).to.be.empty; expect(indexColumns).to.be.empty;
done();
}); });
}); });
}); });
...@@ -119,7 +86,7 @@ describe(Support.getTestDialectTeaser('QueryInterface'), function() { ...@@ -119,7 +86,7 @@ describe(Support.getTestDialectTeaser('QueryInterface'), function() {
}); });
describe('describeTable', function() { describe('describeTable', function() {
it('reads the metadata of the table', function(done) { it('reads the metadata of the table', function() {
var self = this; var self = this;
var Users = self.sequelize.define('_Users', { var Users = self.sequelize.define('_Users', {
username: DataTypes.STRING, username: DataTypes.STRING,
...@@ -127,9 +94,8 @@ describe(Support.getTestDialectTeaser('QueryInterface'), function() { ...@@ -127,9 +94,8 @@ describe(Support.getTestDialectTeaser('QueryInterface'), function() {
enumVals: DataTypes.ENUM('hello', 'world') enumVals: DataTypes.ENUM('hello', 'world')
}, { freezeTableName: true }); }, { freezeTableName: true });
Users.sync({ force: true }).success(function() { return Users.sync({ force: true }).then(function() {
self.queryInterface.describeTable('_Users').complete(function(err, metadata) { return self.queryInterface.describeTable('_Users').then(function(metadata) {
expect(err).to.be.null;
var username = metadata.username; var username = metadata.username;
var isAdmin = metadata.isAdmin; var isAdmin = metadata.isAdmin;
var enumVals = metadata.enumVals; var enumVals = metadata.enumVals;
...@@ -164,7 +130,6 @@ describe(Support.getTestDialectTeaser('QueryInterface'), function() { ...@@ -164,7 +130,6 @@ describe(Support.getTestDialectTeaser('QueryInterface'), function() {
expect(enumVals.special).to.be.instanceof(Array); expect(enumVals.special).to.be.instanceof(Array);
expect(enumVals.special).to.have.length(2); expect(enumVals.special).to.have.length(2);
} }
done();
}); });
}); });
}); });
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!