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

Commit c4cbb3f3 by Ruben Bridgewater

Remove done from sync tests

Refactor another test to use promises

Remove done from sync tests

Refactor the last non promise style find test

Refactor almost all schema tests to use promises

Refactor another schema test to use promises

Insert missing semicolon

Refactor all schema tests

Insert missing epect statement

Rewrite multiple increments / decrements to be more readable

Refactor last create test to use promises
1 parent 50b23bc6
...@@ -2,4 +2,4 @@ ...@@ -2,4 +2,4 @@
The entry point. The entry point.
@module Sequelize @module Sequelize
**/ **/
module.exports = require("./lib/sequelize") module.exports = require("./lib/sequelize");
...@@ -13,7 +13,7 @@ if (dialect.match(/^postgres/)) { ...@@ -13,7 +13,7 @@ if (dialect.match(/^postgres/)) {
describe('[POSTGRES Specific] associations', function() { describe('[POSTGRES 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});
...@@ -21,35 +21,24 @@ if (dialect.match(/^postgres/)) { ...@@ -21,35 +21,24 @@ if (dialect.match(/^postgres/)) {
Table2.hasMany(Table1); Table2.hasMany(Table1);
expect(this.sequelize.daoFactoryManager.getDAO('wp_table1swp_table2s')).to.exist; expect(this.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'});
setTimeout(function() {
done();
}, 50);
}); });
it('should not use a combined name', function(done) { it('should not use a combined name', function() {
expect(this.sequelize.daoFactoryManager.getDAO('ms_table1sms_table2s')).not.to.exist; expect(this.sequelize.daoFactoryManager.getDAO('ms_table1sms_table2s')).not.to.exist;
setTimeout(function() {
done();
}, 50);
}); });
it('should use the specified name', function(done) { it('should use the specified name', function() {
expect(this.sequelize.daoFactoryManager.getDAO('table1_to_table2')).to.exist; expect(this.sequelize.daoFactoryManager.getDAO('table1_to_table2')).to.exist;
setTimeout(function() {
done();
}, 50);
}); });
}); });
}); });
......
...@@ -363,38 +363,37 @@ if (dialect.match(/^postgres/)) { ...@@ -363,38 +363,37 @@ if (dialect.match(/^postgres/)) {
}); });
}); });
it('should be able to add enum types', function(done) { it('should be able to add enum types', function() {
var self = this var self = this
, User = this.sequelize.define('UserEnums', { , User = this.sequelize.define('UserEnums', {
mood: DataTypes.ENUM('happy', 'sad', 'meh') mood: DataTypes.ENUM('happy', 'sad', 'meh')
}); })
, count = 0;
var _done = _.after(4, function() {
done();
});
User.sync({ force: true }).then(function() { return User.sync({ force: true }).then(function() {
User = self.sequelize.define('UserEnums', { User = self.sequelize.define('UserEnums', {
mood: DataTypes.ENUM('neutral', 'happy', 'sad', 'ecstatic', 'meh', 'joyful') mood: DataTypes.ENUM('neutral', 'happy', 'sad', 'ecstatic', 'meh', 'joyful')
}); });
User.sync().then(function() { return User.sync().then(function() {
expect(User.rawAttributes.mood.values).to.deep.equal(['neutral', 'happy', 'sad', 'ecstatic', 'meh', 'joyful']); expect(User.rawAttributes.mood.values).to.deep.equal(['neutral', 'happy', 'sad', 'ecstatic', 'meh', 'joyful']);
_done(); count++;
}).on('sql', function(sql) { }).on('sql', function(sql) {
if (sql.indexOf('neutral') > -1) { if (sql.indexOf('neutral') > -1) {
expect(sql).to.equal("ALTER TYPE \"enum_UserEnums_mood\" ADD VALUE 'neutral' BEFORE 'happy'"); expect(sql).to.equal("ALTER TYPE \"enum_UserEnums_mood\" ADD VALUE 'neutral' BEFORE 'happy'");
_done(); count++;
} }
else if (sql.indexOf('ecstatic') > -1) { else if (sql.indexOf('ecstatic') > -1) {
expect(sql).to.equal("ALTER TYPE \"enum_UserEnums_mood\" ADD VALUE 'ecstatic' BEFORE 'meh'"); expect(sql).to.equal("ALTER TYPE \"enum_UserEnums_mood\" ADD VALUE 'ecstatic' BEFORE 'meh'");
_done(); count++;
} }
else if (sql.indexOf('joyful') > -1) { else if (sql.indexOf('joyful') > -1) {
expect(sql).to.equal("ALTER TYPE \"enum_UserEnums_mood\" ADD VALUE 'joyful' AFTER 'meh'"); expect(sql).to.equal("ALTER TYPE \"enum_UserEnums_mood\" ADD VALUE 'joyful' AFTER 'meh'");
_done(); count++;
} }
}); });
}).then(function() {
expect(count).to.equal(4);
}); });
}); });
}); });
......
...@@ -6,8 +6,8 @@ var chai = require('chai') ...@@ -6,8 +6,8 @@ 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')
, Promise = Sequelize.Promise , Promise = Sequelize.Promise
, async = require('async')
, _ = require('lodash'); , _ = require('lodash');
chai.use(datetime); chai.use(datetime);
...@@ -93,63 +93,53 @@ describe(Support.getTestDialectTeaser('Includes with schemas'), function() { ...@@ -93,63 +93,53 @@ describe(Support.getTestDialectTeaser('Includes with schemas'), function() {
Group.hasMany(GroupMember, {as: 'Memberships'}); Group.hasMany(GroupMember, {as: 'Memberships'});
return self.sequelize.sync({force: true}).then(function() { return self.sequelize.sync({force: true}).then(function() {
return Promise.props({ return Promise.all([
groups: Group.bulkCreate([ Group.bulkCreate([
{name: 'Developers'}, {name: 'Developers'},
{name: 'Designers'}, {name: 'Designers'},
{name: 'Managers'} {name: 'Managers'}
]).then(function() { ]),
return Group.findAll(); Company.bulkCreate([
}),
companies: Company.bulkCreate([
{name: 'Sequelize'}, {name: 'Sequelize'},
{name: 'Coca Cola'}, {name: 'Coca Cola'},
{name: 'Bonanza'}, {name: 'Bonanza'},
{name: 'NYSE'}, {name: 'NYSE'},
{name: 'Coshopr'} {name: 'Coshopr'}
]).then(function() { ]),
return Company.findAll(); Rank.bulkCreate([
}),
ranks: Rank.bulkCreate([
{name: 'Admin', canInvite: 1, canRemove: 1, canPost: 1}, {name: 'Admin', canInvite: 1, canRemove: 1, canPost: 1},
{name: 'Trustee', canInvite: 1, canRemove: 0, canPost: 1}, {name: 'Trustee', canInvite: 1, canRemove: 0, canPost: 1},
{name: 'Member', canInvite: 1, canRemove: 0, canPost: 0} {name: 'Member', canInvite: 1, canRemove: 0, canPost: 0}
]).then(function() { ]),
return Rank.findAll(); Tag.bulkCreate([
}),
tags: Tag.bulkCreate([
{name: 'A'}, {name: 'A'},
{name: 'B'}, {name: 'B'},
{name: 'C'}, {name: 'C'},
{name: 'D'}, {name: 'D'},
{name: 'E'} {name: 'E'}
])
]).then(function() { ]).then(function() {
return Tag.findAll(); return Promise.all([
}) Group.findAll(),
}).then(function (results) { Company.findAll(),
var groups = results.groups Rank.findAll(),
, ranks = results.ranks Tag.findAll()
, tags = results.tags ]);
, companies = results.companies; }).spread(function (groups, companies, ranks, tags) {
return Promise.reduce(_.range(5), function (memo, i) { return Promise.reduce(_.range(5), function (memo, i) {
return Promise.props({ return Promise.all([
user: AccUser.create(), AccUser.create(),
products: Product.bulkCreate([ Product.bulkCreate([
{title: 'Chair'}, {title: 'Chair'},
{title: 'Desk'}, {title: 'Desk'},
{title: 'Bed'}, {title: 'Bed'},
{title: 'Pen'}, {title: 'Pen'},
{title: 'Monitor'} {title: 'Monitor'}
]).then(function(err) { ]).then(function() {
return Product.findAll(); return Product.findAll();
}) })
}).then(function (results) { ]).spread(function (user, products) {
var user = results.user var groupMembers = [
, products = results.products
, groupMembers;
groupMembers = [
{AccUserId: user.id, GroupId: groups[0].id, RankId: ranks[0].id}, {AccUserId: user.id, GroupId: groups[0].id, RankId: ranks[0].id},
{AccUserId: user.id, GroupId: groups[1].id, RankId: ranks[2].id} {AccUserId: user.id, GroupId: groups[1].id, RankId: ranks[2].id}
]; ];
...@@ -401,7 +391,7 @@ describe(Support.getTestDialectTeaser('Includes with schemas'), function() { ...@@ -401,7 +391,7 @@ describe(Support.getTestDialectTeaser('Includes with schemas'), function() {
}); });
}); });
it('should support many levels of belongsTo', function(done) { it('should support many levels of belongsTo', function() {
var A = this.sequelize.define('a', {}, {schema: 'account'}) var A = this.sequelize.define('a', {}, {schema: 'account'})
, B = this.sequelize.define('b', {}, {schema: 'account'}) , B = this.sequelize.define('b', {}, {schema: 'account'})
, C = this.sequelize.define('c', {}, {schema: 'account'}) , C = this.sequelize.define('c', {}, {schema: 'account'})
...@@ -429,51 +419,32 @@ describe(Support.getTestDialectTeaser('Includes with schemas'), function() { ...@@ -429,51 +419,32 @@ describe(Support.getTestDialectTeaser('Includes with schemas'), function() {
H H
]; ];
this.sequelize.sync().done(function() { return this.sequelize.sync().then(function() {
async.auto({ return A.bulkCreate([
as: function(callback) { {}, {}, {}, {}, {}, {}, {}, {}
A.bulkCreate([ ]).then(function() {
{},
{},
{},
{},
{},
{},
{},
{}
]).done(function() {
A.findAll().done(callback);
});
},
singleChain: function(callback) {
var previousInstance; var previousInstance;
return Promise.resolve(singles).each(function(model) {
async.eachSeries(singles, function(model, callback) { return model.create({}).then(function(instance) {
model.create({}).done(function(err, instance) {
if (previousInstance) { if (previousInstance) {
previousInstance['set'+ Sequelize.Utils.uppercaseFirst(model.name)](instance).done(function() { return previousInstance['set'+ Sequelize.Utils.uppercaseFirst(model.name)](instance).then(function() {
previousInstance = instance; previousInstance = instance;
callback();
}); });
} else {
previousInstance = b = instance;
callback();
} }
previousInstance = b = instance;
return void(0);
}); });
}, callback);
},
abs: ['as', 'singleChain', function(callback, results) {
var chainer = new Sequelize.Utils.QueryChainer();
results.as.forEach(function(a) {
chainer.add(a.setB(b));
}); });
}).then(function() {
chainer.run().done(callback); return A.findAll();
}] }).then(function(as) {
}, function() { var promises = [];
as.forEach(function(a) {
A.findAll({ promises.push(a.setB(b));
});
return Promise.all(promises);
}).then(function() {
return A.findAll({
include: [ include: [
{model: B, include: [ {model: B, include: [
{model: C, include: [ {model: C, include: [
...@@ -489,20 +460,17 @@ describe(Support.getTestDialectTeaser('Includes with schemas'), function() { ...@@ -489,20 +460,17 @@ describe(Support.getTestDialectTeaser('Includes with schemas'), function() {
]} ]}
]} ]}
] ]
}).done(function(err, as) { }).then(function(as) {
expect(err).not.to.be.ok;
expect(as.length).to.be.ok; expect(as.length).to.be.ok;
as.forEach(function(a) { as.forEach(function(a) {
expect(a.b.c.d.e.f.g.h).to.be.ok; expect(a.b.c.d.e.f.g.h).to.be.ok;
}); });
done();
}); });
}); });
}); });
}); });
it('should support ordering with only belongsTo includes', function(done) { it('should support ordering with only belongsTo includes', function() {
var User = this.sequelize.define('SpecialUser', {}, {schema: 'account'}) var User = this.sequelize.define('SpecialUser', {}, {schema: 'account'})
, Item = this.sequelize.define('Item', {'test': DataTypes.STRING}, {schema: 'account'}) , Item = this.sequelize.define('Item', {'test': DataTypes.STRING}, {schema: 'account'})
, Order = this.sequelize.define('Order', {'position': DataTypes.INTEGER}, {schema: 'account'}); , Order = this.sequelize.define('Order', {'position': DataTypes.INTEGER}, {schema: 'account'});
...@@ -511,64 +479,40 @@ describe(Support.getTestDialectTeaser('Includes with schemas'), function() { ...@@ -511,64 +479,40 @@ describe(Support.getTestDialectTeaser('Includes with schemas'), function() {
User.belongsTo(Item, {'as': 'itemB', foreignKey: 'itemB_id'}); User.belongsTo(Item, {'as': 'itemB', foreignKey: 'itemB_id'});
User.belongsTo(Order); User.belongsTo(Order);
this.sequelize.sync().done(function() { return this.sequelize.sync().then(function() {
async.auto({ return Promise.all([
users: function(callback) { User.bulkCreate([{}, {}, {}]),
User.bulkCreate([{}, {}, {}]).done(function() {
User.findAll().done(callback);
});
},
items: function(callback) {
Item.bulkCreate([ Item.bulkCreate([
{'test': 'abc'}, {'test': 'abc'},
{'test': 'def'}, {'test': 'def'},
{'test': 'ghi'}, {'test': 'ghi'},
{'test': 'jkl'} {'test': 'jkl'}
]).done(function() { ]),
Item.findAll({order: ['id']}).done(callback);
});
},
orders: function(callback) {
Order.bulkCreate([ Order.bulkCreate([
{'position': 2}, {'position': 2},
{'position': 3}, {'position': 3},
{'position': 1} {'position': 1}
]).done(function() { ])
Order.findAll({order: ['id']}).done(callback); ]).then(function() {
}); return Promise.all([
}, User.findAll(),
associate: ['users', 'items', 'orders', function(callback, results) { Item.findAll({order: ['id']}),
var chainer = new Sequelize.Utils.QueryChainer(); Order.findAll({order: ['id']})
]);
var user1 = results.users[0]; }).spread(function(users, items, orders) {
var user2 = results.users[1]; return Promise.all([
var user3 = results.users[2]; users[0].setItemA(items[0]),
users[0].setItemB(items[1]),
var item1 = results.items[0]; users[0].setOrder(orders[2]),
var item2 = results.items[1]; users[1].setItemA(items[2]),
var item3 = results.items[2]; users[1].setItemB(items[3]),
var item4 = results.items[3]; users[1].setOrder(orders[1]),
users[2].setItemA(items[0]),
var order1 = results.orders[0]; users[2].setItemB(items[3]),
var order2 = results.orders[1]; users[2].setOrder(orders[0])
var order3 = results.orders[2]; ]);
}).spread(function() {
chainer.add(user1.setItemA(item1)); return User.findAll({
chainer.add(user1.setItemB(item2));
chainer.add(user1.setOrder(order3));
chainer.add(user2.setItemA(item3));
chainer.add(user2.setItemB(item4));
chainer.add(user2.setOrder(order2));
chainer.add(user3.setItemA(item1));
chainer.add(user3.setItemB(item4));
chainer.add(user3.setOrder(order1));
chainer.run().done(callback);
}]
}, function() {
User.findAll({
'include': [ 'include': [
{'model': Item, 'as': 'itemA', where: {test: 'abc'}}, {'model': Item, 'as': 'itemA', where: {test: 'abc'}},
{'model': Item, 'as': 'itemB'}, {'model': Item, 'as': 'itemB'},
...@@ -576,23 +520,18 @@ describe(Support.getTestDialectTeaser('Includes with schemas'), function() { ...@@ -576,23 +520,18 @@ describe(Support.getTestDialectTeaser('Includes with schemas'), function() {
'order': [ 'order': [
[Order, 'position'] [Order, 'position']
] ]
}).done(function(err, as) { }).then(function(as) {
expect(err).not.to.be.ok;
expect(as.length).to.eql(2); expect(as.length).to.eql(2);
expect(as[0].itemA.test).to.eql('abc'); expect(as[0].itemA.test).to.eql('abc');
expect(as[1].itemA.test).to.eql('abc'); expect(as[1].itemA.test).to.eql('abc');
expect(as[0].Order.position).to.eql(1); expect(as[0].Order.position).to.eql(1);
expect(as[1].Order.position).to.eql(2); expect(as[1].Order.position).to.eql(2);
done();
}); });
}); });
}); });
}); });
it('should include attributes from through models', function(done) { it('should include attributes from through models', function() {
var Product = this.sequelize.define('Product', { var Product = this.sequelize.define('Product', {
title: DataTypes.STRING title: DataTypes.STRING
}, {schema: 'account'}) }, {schema: 'account'})
...@@ -606,44 +545,34 @@ describe(Support.getTestDialectTeaser('Includes with schemas'), function() { ...@@ -606,44 +545,34 @@ describe(Support.getTestDialectTeaser('Includes with schemas'), function() {
Product.hasMany(Tag, {through: ProductTag}); Product.hasMany(Tag, {through: ProductTag});
Tag.hasMany(Product, {through: ProductTag}); Tag.hasMany(Product, {through: ProductTag});
this.sequelize.sync({force: true}).done(function() { return this.sequelize.sync({force: true}).then(function() {
async.auto({ return Promise.all([
products: function(callback) {
Product.bulkCreate([ Product.bulkCreate([
{title: 'Chair'}, {title: 'Chair'},
{title: 'Desk'}, {title: 'Desk'},
{title: 'Dress'} {title: 'Dress'}
]).done(function() { ]),
Product.findAll().done(callback);
});
},
tags: function(callback) {
Tag.bulkCreate([ Tag.bulkCreate([
{name: 'A'}, {name: 'A'},
{name: 'B'}, {name: 'B'},
{name: 'C'} {name: 'C'}
]).done(function() { ])
Tag.findAll().done(callback); ]).spread(function() {
}); return Promise.all([
}, Product.findAll(),
productTags: ['products', 'tags', function(callback, results) { Tag.findAll()
var chainer = new Sequelize.Utils.QueryChainer(); ]);
}).spread(function(products, tags) {
chainer.add(results.products[0].addTag(results.tags[0], {priority: 1})); return Promise.all([
chainer.add(results.products[0].addTag(results.tags[1], {priority: 2})); products[0].addTag(tags[0], {priority: 1}),
products[0].addTag(tags[1], {priority: 2}),
chainer.add(results.products[1].addTag(results.tags[1], {priority: 1})); products[1].addTag(tags[1], {priority: 1}),
products[2].addTag(tags[0], {priority: 3}),
chainer.add(results.products[2].addTag(results.tags[0], {priority: 3})); products[2].addTag(tags[1], {priority: 1}),
chainer.add(results.products[2].addTag(results.tags[1], {priority: 1})); products[2].addTag(tags[2], {priority: 2})
chainer.add(results.products[2].addTag(results.tags[2], {priority: 2})); ]);
}).spread(function() {
chainer.run().done(callback); return Product.findAll({
}]
}, function(err) {
expect(err).not.to.be.ok;
Product.findAll({
include: [ include: [
{model: Tag} {model: Tag}
], ],
...@@ -651,63 +580,49 @@ describe(Support.getTestDialectTeaser('Includes with schemas'), function() { ...@@ -651,63 +580,49 @@ describe(Support.getTestDialectTeaser('Includes with schemas'), function() {
['id', 'ASC'], ['id', 'ASC'],
[Tag, 'id', 'ASC'] [Tag, 'id', 'ASC']
] ]
}).done(function(err, products) { }).then(function(products) {
expect(err).not.to.be.ok;
expect(products[0].Tags[0].ProductTag.priority).to.equal(1); expect(products[0].Tags[0].ProductTag.priority).to.equal(1);
expect(products[0].Tags[1].ProductTag.priority).to.equal(2); expect(products[0].Tags[1].ProductTag.priority).to.equal(2);
expect(products[1].Tags[0].ProductTag.priority).to.equal(1); expect(products[1].Tags[0].ProductTag.priority).to.equal(1);
expect(products[2].Tags[0].ProductTag.priority).to.equal(3); expect(products[2].Tags[0].ProductTag.priority).to.equal(3);
expect(products[2].Tags[1].ProductTag.priority).to.equal(1); expect(products[2].Tags[1].ProductTag.priority).to.equal(1);
expect(products[2].Tags[2].ProductTag.priority).to.equal(2); expect(products[2].Tags[2].ProductTag.priority).to.equal(2);
done();
}); });
}); });
}); });
}); });
it('should support a required belongsTo include', function(done) { it('should support a required belongsTo include', function() {
var User = this.sequelize.define('User', {}, {schema: 'account'}) var User = this.sequelize.define('User', {}, {schema: 'account'})
, Group = this.sequelize.define('Group', {}, {schema: 'account'}); , Group = this.sequelize.define('Group', {}, {schema: 'account'});
User.belongsTo(Group); User.belongsTo(Group);
this.sequelize.sync({force: true}).done(function() { return this.sequelize.sync({force: true}).then(function() {
async.auto({ return Promise.all([
groups: function(callback) { Group.bulkCreate([{}, {}]),
Group.bulkCreate([{}, {}]).done(function() { User.bulkCreate([{}, {}, {}])
Group.findAll().done(callback); ]).then(function() {
}); return Promise.all([
}, Group.findAll(),
users: function(callback) { User.findAll()
User.bulkCreate([{}, {}, {}]).done(function() { ]);
User.findAll().done(callback); }).spread(function(groups, users) {
}); return users[2].setGroup(groups[1]);
}, }).then(function() {
userGroups: ['users', 'groups', function(callback, results) { return User.findAll({
results.users[2].setGroup(results.groups[1]).done(callback);
}]
}, function(err) {
expect(err).not.to.be.ok;
User.findAll({
include: [ include: [
{model: Group, required: true} {model: Group, required: true}
] ]
}).done(function(err, users) { }).then(function(users) {
expect(err).not.to.be.ok;
expect(users.length).to.equal(1); expect(users.length).to.equal(1);
expect(users[0].Group).to.be.ok; expect(users[0].Group).to.be.ok;
done();
}); });
}); });
}); });
}); });
it('should be possible to extend the on clause with a where option on a belongsTo include', function(done) { it('should be possible to extend the on clause with a where option on a belongsTo include', function() {
var User = this.sequelize.define('User', {}, {schema: 'account'}) var User = this.sequelize.define('User', {}, {schema: 'account'})
, Group = this.sequelize.define('Group', { , Group = this.sequelize.define('Group', {
name: DataTypes.STRING name: DataTypes.STRING
...@@ -715,46 +630,38 @@ describe(Support.getTestDialectTeaser('Includes with schemas'), function() { ...@@ -715,46 +630,38 @@ describe(Support.getTestDialectTeaser('Includes with schemas'), function() {
User.belongsTo(Group); User.belongsTo(Group);
this.sequelize.sync({force: true}).done(function() { return this.sequelize.sync({force: true}).then(function() {
async.auto({ return Promise.all([
groups: function(callback) {
Group.bulkCreate([ Group.bulkCreate([
{name: 'A'}, {name: 'A'},
{name: 'B'} {name: 'B'}
]).done(function() { ]),
Group.findAll().done(callback); User.bulkCreate([{}, {}])
}); ]).then(function() {
}, return Promise.all([
users: function(callback) { Group.findAll(),
User.bulkCreate([{}, {}]).done(function() { User.findAll()
User.findAll().done(callback); ]);
}); }).spread(function(groups, users) {
}, return Promise.all([
userGroups: ['users', 'groups', function(callback, results) { users[0].setGroup(groups[1]),
var chainer = new Sequelize.Utils.QueryChainer(); users[1].setGroup(groups[0])
chainer.add(results.users[0].setGroup(results.groups[1])); ]);
chainer.add(results.users[1].setGroup(results.groups[0])); }).then(function() {
chainer.run().done(callback); return User.findAll({
}]
}, function(err) {
expect(err).not.to.be.ok;
User.findAll({
include: [ include: [
{model: Group, where: {name: 'A'}} {model: Group, where: {name: 'A'}}
] ]
}).done(function(err, users) { }).then(function(users) {
expect(err).not.to.be.ok;
expect(users.length).to.equal(1); expect(users.length).to.equal(1);
expect(users[0].Group).to.be.ok; expect(users[0].Group).to.be.ok;
expect(users[0].Group.name).to.equal('A'); expect(users[0].Group.name).to.equal('A');
done();
}); });
}); });
}); });
}); });
it('should be possible to extend the on clause with a where option on a belongsTo include', function(done) { it('should be possible to extend the on clause with a where option on a belongsTo include', function() {
var User = this.sequelize.define('User', {}, {schema: 'account'}) var User = this.sequelize.define('User', {}, {schema: 'account'})
, Group = this.sequelize.define('Group', { , Group = this.sequelize.define('Group', {
name: DataTypes.STRING name: DataTypes.STRING
...@@ -762,46 +669,38 @@ describe(Support.getTestDialectTeaser('Includes with schemas'), function() { ...@@ -762,46 +669,38 @@ describe(Support.getTestDialectTeaser('Includes with schemas'), function() {
User.belongsTo(Group); User.belongsTo(Group);
this.sequelize.sync({force: true}).done(function() { return this.sequelize.sync({force: true}).then(function() {
async.auto({ return Promise.all([
groups: function(callback) {
Group.bulkCreate([ Group.bulkCreate([
{name: 'A'}, {name: 'A'},
{name: 'B'} {name: 'B'}
]).done(function() { ]),
Group.findAll().done(callback); User.bulkCreate([{}, {}])
}); ]).then(function() {
}, return Promise.all([
users: function(callback) { Group.findAll(),
User.bulkCreate([{}, {}]).done(function() { User.findAll()
User.findAll().done(callback); ]);
}); }).spread(function(groups, users) {
}, return Promise.all([
userGroups: ['users', 'groups', function(callback, results) { users[0].setGroup(groups[1]),
var chainer = new Sequelize.Utils.QueryChainer(); users[1].setGroup(groups[0])
chainer.add(results.users[0].setGroup(results.groups[1])); ]);
chainer.add(results.users[1].setGroup(results.groups[0])); }).then(function() {
chainer.run().done(callback); return User.findAll({
}]
}, function(err) {
expect(err).not.to.be.ok;
User.findAll({
include: [ include: [
{model: Group, required: true} {model: Group, required: true}
] ]
}).done(function(err, users) { }).then(function(users) {
expect(err).not.to.be.ok;
users.forEach(function(user) { users.forEach(function(user) {
expect(user.Group).to.be.ok; expect(user.Group).to.be.ok;
}); });
done();
}); });
}); });
}); });
}); });
it('should be possible to define a belongsTo include as required with child hasMany with limit', function(done) { it('should be possible to define a belongsTo include as required with child hasMany with limit', function() {
var User = this.sequelize.define('User', {}, {schema: 'account'}) , Group = this.sequelize.define('Group', { var User = this.sequelize.define('User', {}, {schema: 'account'}) , Group = this.sequelize.define('Group', {
name: DataTypes.STRING name: DataTypes.STRING
}, {schema: 'account'}) }, {schema: 'account'})
...@@ -812,65 +711,49 @@ describe(Support.getTestDialectTeaser('Includes with schemas'), function() { ...@@ -812,65 +711,49 @@ describe(Support.getTestDialectTeaser('Includes with schemas'), function() {
User.belongsTo(Group); User.belongsTo(Group);
Group.hasMany(Category); Group.hasMany(Category);
this.sequelize.sync({force: true}).done(function() { return this.sequelize.sync({force: true}).then(function() {
async.auto({ return Promise.all([
groups: function(callback) {
Group.bulkCreate([ Group.bulkCreate([
{name: 'A'}, {name: 'A'},
{name: 'B'} {name: 'B'}
]).done(function() { ]),
Group.findAll().done(callback); User.bulkCreate([{}, {}]),
}); Category.bulkCreate([{}, {}])
}, ]).then(function() {
users: function(callback) { return Promise.all([
User.bulkCreate([{}, {}]).done(function() { Group.findAll(),
User.findAll().done(callback); User.findAll(),
}); Category.findAll()
}, ]);
categories: function(callback) { }).spread(function(groups, users, categories) {
Category.bulkCreate([{}, {}]).done(function() { var promises = [
Category.findAll().done(callback); users[0].setGroup(groups[1]),
}); users[1].setGroup(groups[0])
}, ];
userGroups: ['users', 'groups', function(callback, results) { groups.forEach(function(group) {
var chainer = new Sequelize.Utils.QueryChainer(); promises.push(group.setCategories(categories));
chainer.add(results.users[0].setGroup(results.groups[1]));
chainer.add(results.users[1].setGroup(results.groups[0]));
chainer.run().done(callback);
}],
groupCategories: ['groups', 'categories', function(callback, results) {
var chainer = new Sequelize.Utils.QueryChainer();
results.groups.forEach(function(group) {
chainer.add(group.setCategories(results.categories));
}); });
return Promise.all(promises);
chainer.run().done(callback); }).then(function() {
}] return User.findAll({
}, function(err) {
expect(err).not.to.be.ok;
User.findAll({
include: [ include: [
{model: Group, required: true, include: [ {model: Group, required: true, include: [
{model: Category} {model: Category}
]} ]}
], ],
limit: 1 limit: 1
}).done(function(err, users) { }).then(function(users) {
expect(err).not.to.be.ok;
expect(users.length).to.equal(1); expect(users.length).to.equal(1);
users.forEach(function(user) { users.forEach(function(user) {
expect(user.Group).to.be.ok; expect(user.Group).to.be.ok;
expect(user.Group.Categories).to.be.ok; expect(user.Group.Categories).to.be.ok;
}); });
done();
}); });
}); });
}); });
}); });
it('should be possible to define a belongsTo include as required with child hasMany with limit and aliases', function(done) { it('should be possible to define a belongsTo include as required with child hasMany with limit and aliases', function() {
var User = this.sequelize.define('User', {}, {schema: 'account'}) var User = this.sequelize.define('User', {}, {schema: 'account'})
, Group = this.sequelize.define('Group', { , Group = this.sequelize.define('Group', {
name: DataTypes.STRING name: DataTypes.STRING
...@@ -882,65 +765,49 @@ describe(Support.getTestDialectTeaser('Includes with schemas'), function() { ...@@ -882,65 +765,49 @@ describe(Support.getTestDialectTeaser('Includes with schemas'), function() {
User.belongsTo(Group, {as: 'Team'}); User.belongsTo(Group, {as: 'Team'});
Group.hasMany(Category, {as: 'Tags'}); Group.hasMany(Category, {as: 'Tags'});
this.sequelize.sync({force: true}).done(function() { return this.sequelize.sync({force: true}).then(function() {
async.auto({ return Promise.all([
groups: function(callback) {
Group.bulkCreate([ Group.bulkCreate([
{name: 'A'}, {name: 'A'},
{name: 'B'} {name: 'B'}
]).done(function() { ]),
Group.findAll().done(callback); User.bulkCreate([{}, {}]),
}); Category.bulkCreate([{}, {}])
}, ]).then(function() {
users: function(callback) { return Promise.all([
User.bulkCreate([{}, {}]).done(function() { Group.findAll(),
User.findAll().done(callback); User.findAll(),
}); Category.findAll()
}, ]);
categories: function(callback) { }).spread(function(groups, users, categories) {
Category.bulkCreate([{}, {}]).done(function() { var promises = [
Category.findAll().done(callback); users[0].setTeam(groups[1]),
}); users[1].setTeam(groups[0])
}, ];
userGroups: ['users', 'groups', function(callback, results) { groups.forEach(function(group) {
var chainer = new Sequelize.Utils.QueryChainer(); promises.push(group.setTags(categories));
chainer.add(results.users[0].setTeam(results.groups[1]));
chainer.add(results.users[1].setTeam(results.groups[0]));
chainer.run().done(callback);
}],
groupCategories: ['groups', 'categories', function(callback, results) {
var chainer = new Sequelize.Utils.QueryChainer();
results.groups.forEach(function(group) {
chainer.add(group.setTags(results.categories));
}); });
return Promise.all(promises);
chainer.run().done(callback); }).then(function() {
}] return User.findAll({
}, function(err) {
expect(err).not.to.be.ok;
User.findAll({
include: [ include: [
{model: Group, required: true, as: 'Team', include: [ {model: Group, required: true, as: 'Team', include: [
{model: Category, as: 'Tags'} {model: Category, as: 'Tags'}
]} ]}
], ],
limit: 1 limit: 1
}).done(function(err, users) { }).then(function(users) {
expect(err).not.to.be.ok;
expect(users.length).to.equal(1); expect(users.length).to.equal(1);
users.forEach(function(user) { users.forEach(function(user) {
expect(user.Team).to.be.ok; expect(user.Team).to.be.ok;
expect(user.Team.Tags).to.be.ok; expect(user.Team.Tags).to.be.ok;
}); });
done();
}); });
}); });
}); });
}); });
it('should be possible to define a belongsTo include as required with child hasMany which is not required with limit', function(done) { it('should be possible to define a belongsTo include as required with child hasMany which is not required with limit', function() {
var User = this.sequelize.define('User', {}, {schema: 'account'}) var User = this.sequelize.define('User', {}, {schema: 'account'})
, Group = this.sequelize.define('Group', { , Group = this.sequelize.define('Group', {
name: DataTypes.STRING name: DataTypes.STRING
...@@ -952,65 +819,49 @@ describe(Support.getTestDialectTeaser('Includes with schemas'), function() { ...@@ -952,65 +819,49 @@ describe(Support.getTestDialectTeaser('Includes with schemas'), function() {
User.belongsTo(Group); User.belongsTo(Group);
Group.hasMany(Category); Group.hasMany(Category);
this.sequelize.sync({force: true}).done(function() { return this.sequelize.sync({force: true}).then(function() {
async.auto({ return Promise.all([
groups: function(callback) {
Group.bulkCreate([ Group.bulkCreate([
{name: 'A'}, {name: 'A'},
{name: 'B'} {name: 'B'}
]).done(function() { ]),
Group.findAll().done(callback); User.bulkCreate([{}, {}]),
}); Category.bulkCreate([{}, {}])
}, ]).then(function() {
users: function(callback) { return Promise.all([
User.bulkCreate([{}, {}]).done(function() { Group.findAll(),
User.findAll().done(callback); User.findAll(),
}); Category.findAll()
}, ]);
categories: function(callback) { }).spread(function (groups, users, categories) {
Category.bulkCreate([{}, {}]).done(function() { var promises = [
Category.findAll().done(callback); users[0].setGroup(groups[1]),
}); users[1].setGroup(groups[0])
}, ];
userGroups: ['users', 'groups', function(callback, results) { groups.forEach(function(group) {
var chainer = new Sequelize.Utils.QueryChainer(); promises.push(group.setCategories(categories));
chainer.add(results.users[0].setGroup(results.groups[1]));
chainer.add(results.users[1].setGroup(results.groups[0]));
chainer.run().done(callback);
}],
groupCategories: ['groups', 'categories', function(callback, results) {
var chainer = new Sequelize.Utils.QueryChainer();
results.groups.forEach(function(group) {
chainer.add(group.setCategories(results.categories));
}); });
return Promise.all(promises);
chainer.run().done(callback); }).then(function() {
}] return User.findAll({
}, function(err) {
expect(err).not.to.be.ok;
User.findAll({
include: [ include: [
{model: Group, required: true, include: [ {model: Group, required: true, include: [
{model: Category, required: false} {model: Category, required: false}
]} ]}
], ],
limit: 1 limit: 1
}).done(function(err, users) { }).then(function(users) {
expect(err).not.to.be.ok;
expect(users.length).to.equal(1); expect(users.length).to.equal(1);
users.forEach(function(user) { users.forEach(function(user) {
expect(user.Group).to.be.ok; expect(user.Group).to.be.ok;
expect(user.Group.Categories).to.be.ok; expect(user.Group.Categories).to.be.ok;
}); });
done();
}); });
}); });
}); });
}); });
it('should be possible to extend the on clause with a where option on a hasOne include', function(done) { it('should be possible to extend the on clause with a where option on a hasOne include', function() {
var User = this.sequelize.define('User', {}, {schema: 'account'}) var User = this.sequelize.define('User', {}, {schema: 'account'})
, Project = this.sequelize.define('Project', { , Project = this.sequelize.define('Project', {
title: DataTypes.STRING title: DataTypes.STRING
...@@ -1018,46 +869,38 @@ describe(Support.getTestDialectTeaser('Includes with schemas'), function() { ...@@ -1018,46 +869,38 @@ describe(Support.getTestDialectTeaser('Includes with schemas'), function() {
User.hasOne(Project, {as: 'LeaderOf'}); User.hasOne(Project, {as: 'LeaderOf'});
this.sequelize.sync({force: true}).done(function() { return this.sequelize.sync({force: true}).then(function() {
async.auto({ return Promise.all([
projects: function(callback) {
Project.bulkCreate([ Project.bulkCreate([
{title: 'Alpha'}, {title: 'Alpha'},
{title: 'Beta'} {title: 'Beta'}
]).done(function() { ]),
Project.findAll().done(callback); User.bulkCreate([{}, {}])
}); ]).then(function() {
}, return Promise.all([
users: function(callback) { Project.findAll(),
User.bulkCreate([{}, {}]).done(function() { User.findAll()
User.findAll().done(callback); ]);
}); }).spread(function(projects, users) {
}, return Promise.all([
userProjects: ['users', 'projects', function(callback, results) { users[1].setLeaderOf(projects[1]),
var chainer = new Sequelize.Utils.QueryChainer(); users[0].setLeaderOf(projects[0])
chainer.add(results.users[1].setLeaderOf(results.projects[1])); ]);
chainer.add(results.users[0].setLeaderOf(results.projects[0])); }).then(function() {
chainer.run().done(callback); return User.findAll({
}]
}, function(err) {
expect(err).not.to.be.ok;
User.findAll({
include: [ include: [
{model: Project, as: 'LeaderOf', where: {title: 'Beta'}} {model: Project, as: 'LeaderOf', where: {title: 'Beta'}}
] ]
}).done(function(err, users) { }).then(function(users) {
expect(err).not.to.be.ok;
expect(users.length).to.equal(1); expect(users.length).to.equal(1);
expect(users[0].LeaderOf).to.be.ok; expect(users[0].LeaderOf).to.be.ok;
expect(users[0].LeaderOf.title).to.equal('Beta'); expect(users[0].LeaderOf.title).to.equal('Beta');
done();
}); });
}); });
}); });
}); });
it('should be possible to extend the on clause with a where option on a hasMany include with a through model', function(done) { it('should be possible to extend the on clause with a where option on a hasMany include with a through model', function() {
var Product = this.sequelize.define('Product', { var Product = this.sequelize.define('Product', {
title: DataTypes.STRING title: DataTypes.STRING
}, {schema: 'account'}) }, {schema: 'account'})
...@@ -1071,54 +914,40 @@ describe(Support.getTestDialectTeaser('Includes with schemas'), function() { ...@@ -1071,54 +914,40 @@ describe(Support.getTestDialectTeaser('Includes with schemas'), function() {
Product.hasMany(Tag, {through: ProductTag}); Product.hasMany(Tag, {through: ProductTag});
Tag.hasMany(Product, {through: ProductTag}); Tag.hasMany(Product, {through: ProductTag});
this.sequelize.sync({force: true}).done(function() { return this.sequelize.sync({force: true}).then(function() {
async.auto({ return Promise.all([
products: function(callback) {
Product.bulkCreate([ Product.bulkCreate([
{title: 'Chair'}, {title: 'Chair'},
{title: 'Desk'}, {title: 'Desk'},
{title: 'Dress'} {title: 'Dress'}
]).done(function() { ]),
Product.findAll().done(callback);
});
},
tags: function(callback) {
Tag.bulkCreate([ Tag.bulkCreate([
{name: 'A'}, {name: 'A'},
{name: 'B'}, {name: 'B'},
{name: 'C'} {name: 'C'}
]).done(function() { ])
Tag.findAll().done(callback); ]).then(function() {
}); return Promise.all([
}, Product.findAll(),
productTags: ['products', 'tags', function(callback, results) { Tag.findAll()
var chainer = new Sequelize.Utils.QueryChainer(); ]);
}).spread(function(products, tags) {
chainer.add(results.products[0].addTag(results.tags[0], {priority: 1})); return Promise.all([
chainer.add(results.products[0].addTag(results.tags[1], {priority: 2})); products[0].addTag(tags[0], {priority: 1}),
products[0].addTag(tags[1], {priority: 2}),
chainer.add(results.products[1].addTag(results.tags[1], {priority: 1})); products[1].addTag(tags[1], {priority: 1}),
products[2].addTag(tags[0], {priority: 3}),
chainer.add(results.products[2].addTag(results.tags[0], {priority: 3})); products[2].addTag(tags[1], {priority: 1}),
chainer.add(results.products[2].addTag(results.tags[1], {priority: 1})); products[2].addTag(tags[2], {priority: 2})
chainer.add(results.products[2].addTag(results.tags[2], {priority: 2})); ]);
}).then(function() {
chainer.run().done(callback); return Product.findAll({
}]
}, function(err) {
expect(err).not.to.be.ok;
Product.findAll({
include: [ include: [
{model: Tag, where: {name: 'C'}} {model: Tag, where: {name: 'C'}}
] ]
}).done(function(err, products) { }).then(function(products) {
expect(err).not.to.be.ok;
expect(products.length).to.equal(1); expect(products.length).to.equal(1);
expect(products[0].Tags.length).to.equal(1); expect(products[0].Tags.length).to.equal(1);
done();
}); });
}); });
}); });
......
...@@ -341,11 +341,11 @@ describe(Support.getTestDialectTeaser('Instance'), function() { ...@@ -341,11 +341,11 @@ describe(Support.getTestDialectTeaser('Instance'), function() {
it('should still work right with other concurrent increments', function() { it('should still work right with other concurrent increments', function() {
var self = this; var self = this;
return this.User.find(1).then(function(user1) { return this.User.find(1).then(function(user1) {
return user1.increment(['aNumber'], { by: 2 }).then(function() { return this.sequelize.Promise.all([
return user1.increment(['aNumber'], { by: 2 }); user1.increment(['aNumber'], { by: 2 }),
}).then(function() { user1.increment(['aNumber'], { by: 2 }),
return user1.increment(['aNumber'], { by: 2 }); user1.increment(['aNumber'], { by: 2 })
}).then(function() { ]).then(function() {
return self.User.find(1).then(function(user2) { return self.User.find(1).then(function(user2) {
expect(user2.aNumber).to.equal(6); expect(user2.aNumber).to.equal(6);
}); });
...@@ -468,11 +468,11 @@ describe(Support.getTestDialectTeaser('Instance'), function() { ...@@ -468,11 +468,11 @@ describe(Support.getTestDialectTeaser('Instance'), function() {
it('should still work right with other concurrent increments', function() { it('should still work right with other concurrent increments', function() {
var self = this; var self = this;
return this.User.find(1).then(function(user1) { return this.User.find(1).then(function(user1) {
return user1.decrement(['aNumber'], { by: 2 }).then(function() { return this.sequelize.Promise.all([
return user1.decrement(['aNumber'], { by: 2 }); user1.decrement(['aNumber'], { by: 2 }),
}).then(function() { user1.decrement(['aNumber'], { by: 2 }),
return user1.decrement(['aNumber'], { by: 2 }); user1.decrement(['aNumber'], { by: 2 })
}).then(function() { ]).then(function() {
return self.User.find(1).then(function(user2) { return self.User.find(1).then(function(user2) {
expect(user2.aNumber).to.equal(-6); expect(user2.aNumber).to.equal(-6);
}); });
......
...@@ -924,12 +924,12 @@ describe(Support.getTestDialectTeaser('Model'), function() { ...@@ -924,12 +924,12 @@ describe(Support.getTestDialectTeaser('Model'), function() {
}); });
}); });
it('can omit autoincremental columns', function(done) { it('can omit autoincremental columns', function() {
var self = this var self = this
, data = { title: 'Iliad' } , data = { title: 'Iliad' }
, dataTypes = [Sequelize.INTEGER, Sequelize.BIGINT] , dataTypes = [Sequelize.INTEGER, Sequelize.BIGINT]
, chain = new Sequelize.Utils.QueryChainer() , sync = []
, chain2 = new Sequelize.Utils.QueryChainer() , promises = []
, books = []; , books = [];
dataTypes.forEach(function(dataType, index) { dataTypes.forEach(function(dataType, index) {
...@@ -940,21 +940,18 @@ describe(Support.getTestDialectTeaser('Model'), function() { ...@@ -940,21 +940,18 @@ describe(Support.getTestDialectTeaser('Model'), function() {
}); });
books.forEach(function(b) { books.forEach(function(b) {
chain.add(b.sync({ force: true })); sync.push(b.sync({ force: true }));
}); });
chain.run().then(function() { return Promise.all(sync).then(function() {
books.forEach(function(b) { books.forEach(function(b, index) {
chain2.add(b.create(data)); promises.push(b.create(data).then(function(book) {
});
chain2.run().then(function(results) {
results.forEach(function(book, index) {
expect(book.title).to.equal(data.title); expect(book.title).to.equal(data.title);
expect(book.author).to.equal(data.author); expect(book.author).to.equal(data.author);
expect(books[index].rawAttributes.id.type instanceof dataTypes[index]).to.be.ok; expect(books[index].rawAttributes.id.type instanceof dataTypes[index]).to.be.ok;
}));
}); });
done(); return Promise.all(promises);
});
}); });
}); });
......
...@@ -11,7 +11,6 @@ var chai = require('chai') ...@@ -11,7 +11,6 @@ var chai = require('chai')
, datetime = require('chai-datetime') , datetime = require('chai-datetime')
, promised = require('chai-as-promised') , promised = require('chai-as-promised')
, _ = require('lodash') , _ = require('lodash')
, async = require('async')
, current = Support.sequelize; , current = Support.sequelize;
chai.use(promised); chai.use(promised);
...@@ -760,64 +759,42 @@ describe(Support.getTestDialectTeaser('Model'), function() { ...@@ -760,64 +759,42 @@ describe(Support.getTestDialectTeaser('Model'), function() {
this.Tag = this.sequelize.define('Tag', { name: Sequelize.STRING }); this.Tag = this.sequelize.define('Tag', { name: Sequelize.STRING });
}); });
it('returns the associated models when using through as string and alias', function(done) { it('returns the associated models when using through as string and alias', function() {
var self = this; var self = this;
this.Product.hasMany(this.Tag, {as: 'tags', through: 'product_tag'}); this.Product.hasMany(this.Tag, {as: 'tags', through: 'product_tag'});
this.Tag.hasMany(this.Product, {as: 'products', through: 'product_tag'}); this.Tag.hasMany(this.Product, {as: 'products', through: 'product_tag'});
this.sequelize.sync().done(function() { return this.sequelize.sync().then(function() {
async.auto({ return Promise.all([
createProducts: function(callback) {
self.Product.bulkCreate([ self.Product.bulkCreate([
{title: 'Chair'}, {title: 'Chair'},
{title: 'Desk'}, {title: 'Desk'},
{title: 'Handbag'}, {title: 'Handbag'},
{title: 'Dress'}, {title: 'Dress'},
{title: 'Jan'} {title: 'Jan'}
]).done(callback); ]),
},
// bulkCreate doesn't include id for some reason, not going to fix tis now
products: ['createProducts', function(callback) {
self.Product.findAll().done(callback);
}],
createTags: function(callback) {
self.Tag.bulkCreate([ self.Tag.bulkCreate([
{name: 'Furniture'}, {name: 'Furniture'},
{name: 'Clothing'}, {name: 'Clothing'},
{name: 'People'} {name: 'People'}
]).done(callback); ])
}, ]).then(function() {
tags: ['createTags', function(callback) { return Promise.all([
self.Tag.findAll().done(callback); self.Product.findAll(),
}] self.Tag.findAll()
}, function(err, results) { ]);
expect(err).not.to.exist; }).spread(function(products, tags) {
self.products = products;
var products = results.products self.tags = tags;
, tags = results.tags; return Promise.all([
products[0].setTags([tags[0], tags[1]]),
async.parallel([ products[1].addTag(tags[0]),
function(callback) { products[2].addTag(tags[1]),
products[0].setTags([tags[0], tags[1]]).done(callback); products[3].setTags([tags[1]]),
}, products[4].setTags([tags[2]])
function(callback) { ]).then(function() {
products[1].addTag(tags[0]).done(callback); return Promise.all([
},
function(callback) {
products[2].addTag(tags[1]).done(callback);
},
function(callback) {
products[3].setTags([tags[1]]).done(callback);
},
function(callback) {
products[4].setTags([tags[2]]).done(callback);
}
], function(err) {
expect(err).not.to.exist;
async.parallel([
function(callback) {
self.Tag.find({ self.Tag.find({
where: { where: {
id: tags[0].id id: tags[0].id
...@@ -825,19 +802,13 @@ describe(Support.getTestDialectTeaser('Model'), function() { ...@@ -825,19 +802,13 @@ describe(Support.getTestDialectTeaser('Model'), function() {
include: [ include: [
{model: self.Product, as: 'products'} {model: self.Product, as: 'products'}
] ]
}).done(function(err, tag) { }).then(function(tag) {
expect(tag).to.exist; expect(tag).to.exist;
expect(tag.products.length).to.equal(2); expect(tag.products.length).to.equal(2);
callback(); }),
}); tags[1].getProducts().then(function(products) {
},
function(callback) {
tags[1].getProducts().done(function(err, products) {
expect(products.length).to.equal(3); expect(products.length).to.equal(3);
callback(); }),
});
},
function(callback) {
self.Product.find({ self.Product.find({
where: { where: {
id: products[0].id id: products[0].id
...@@ -845,19 +816,14 @@ describe(Support.getTestDialectTeaser('Model'), function() { ...@@ -845,19 +816,14 @@ describe(Support.getTestDialectTeaser('Model'), function() {
include: [ include: [
{model: self.Tag, as: 'tags'} {model: self.Tag, as: 'tags'}
] ]
}).done(function(err, product) { }).then(function(product) {
expect(product).to.exist; expect(product).to.exist;
expect(product.tags.length).to.equal(2); expect(product.tags.length).to.equal(2);
callback(); }),
}); products[1].getTags().then(function(tags) {
},
function(callback) {
products[1].getTags().done(function(err, tags) {
expect(tags.length).to.equal(1); expect(tags.length).to.equal(1);
callback(); })
}); ]);
}
], done);
}); });
}); });
}); });
......
...@@ -9,24 +9,21 @@ var chai = require('chai') ...@@ -9,24 +9,21 @@ var chai = require('chai')
chai.config.includeStack = true; chai.config.includeStack = true;
describe(Support.getTestDialectTeaser('QueryChainer'), function() { describe(Support.getTestDialectTeaser('QueryChainer'), function() {
beforeEach(function(done) { beforeEach(function() {
this.queryChainer = new QueryChainer(); this.queryChainer = new QueryChainer();
done();
}); });
describe('add', function() { describe('add', function() {
it('adds a new serial item if method is passed', function(done) { it('adds a new serial item if method is passed', function() {
expect(this.queryChainer.serials.length).to.equal(0); expect(this.queryChainer.serials.length).to.equal(0);
this.queryChainer.add({}, 'foo'); this.queryChainer.add({}, 'foo');
expect(this.queryChainer.serials.length).to.equal(1); expect(this.queryChainer.serials.length).to.equal(1);
done();
}); });
it('adds a new emitter if no method is passed', function(done) { it('adds a new emitter if no method is passed', function() {
expect(this.queryChainer.emitters.length).to.equal(0); expect(this.queryChainer.emitters.length).to.equal(0);
this.queryChainer.add(new CustomEventEmitter()); this.queryChainer.add(new CustomEventEmitter());
expect(this.queryChainer.emitters.length).to.equal(1); expect(this.queryChainer.emitters.length).to.equal(1);
done();
}); });
}); });
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!