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

Commit ab5f7567 by Igor Nawrocki

reworked to use promises

1 parent 16620c02
Showing with 55 additions and 46 deletions
...@@ -254,56 +254,64 @@ describe(Support.getTestDialectTeaser("Include"), function () { ...@@ -254,56 +254,64 @@ describe(Support.getTestDialectTeaser("Include"), 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 () { this.sequelize.sync({force: true}).then(function () {
async.auto({
sets: function(callback) { return Set.bulkCreate([
Set.bulkCreate([
{title: 'office'} {title: 'office'}
]).done(function () { ])
Set.findAll().done(callback) .then( function() {
}) return Product.bulkCreate([
},
products: function (callback) {
Product.bulkCreate([
{title: 'Chair'}, {title: 'Chair'},
{title: 'Desk'}, {title: 'Desk'},
{title: 'Dress'} {title: 'Dress'}
]).done(function () { ])
Product.findAll().done(callback)
}) })
}, .then( function() {
tags: function(callback) { return Tag.bulkCreate([
Tag.bulkCreate([
{name: 'A'}, {name: 'A'},
{name: 'B'}, {name: 'B'},
{name: 'C'} {name: 'C'}
]).done(function () { ]).done(function () {
Tag.findAll().done(callback) return Tag.findAll()
}) })
}, })
productSets: ['sets','products', function(callback, results) { .then(function() {
var chainer = new Sequelize.Utils.QueryChainer() return Set.findAll()
chainer.add(results.sets[0].addProduct(results.products[0])) })
chainer.add(results.sets[0].addProduct(results.products[1])) .then(function(sets) {
chainer.run().done(callback) return [sets, Product.findAll()]
}], })
productTags: ['products', 'tags', function (callback, results) { .spread( function(sets, products) {
var chainer = new Sequelize.Utils.QueryChainer() return sets[0].addProduct(products[0])
chainer.add(results.products[0].addTag(results.tags[0], {priority: 1})) .then( function() {
chainer.add(results.products[0].addTag(results.tags[1], {priority: 2})) return sets[0].addProduct(products[1])
}).then( function() {
chainer.add(results.products[1].addTag(results.tags[1], {priority: 1})) return [sets, products]
})
chainer.add(results.products[2].addTag(results.tags[0], {priority: 3})) })
chainer.add(results.products[2].addTag(results.tags[1], {priority: 1})) .spread( function(sets, products) {
chainer.add(results.products[2].addTag(results.tags[2], {priority: 2})) return [sets, products, Tag.findAll()]
})
chainer.run().done(callback) .spread( function(sets, products, tags) {
}] return products[0].addTag(tags[0], {priority:1})
}, function (err) { .then( function() {
expect(err).not.to.be.ok return products[0].addTag(tags[1], {priority:2})
})
Set.findAll({ .then( function() {
return products[0].addTag(tags[2], {priority:1})
})
.then( function() {
return products[1].addTag(tags[1], {priority:2})
})
.then( function() {
return products[2].addTag(tags[1], {priority:3})
})
.then( function() {
return products[2].addTag(tags[2], {priority:0})
})
})
.then( function() {
return Set.findAll({
include: [ include: [
{ {
model: Product, model: Product,
...@@ -313,18 +321,19 @@ describe(Support.getTestDialectTeaser("Include"), function () { ...@@ -313,18 +321,19 @@ describe(Support.getTestDialectTeaser("Include"), function () {
where: { where: {
name: 'A' name: 'A'
} }
} }]
]
}], }],
limit: 1 limit: 1
}).done(function (err, products) { })
expect(err).not.to.be.ok })
.then( function() {
done() done()
}) })
.catch(function (err) {
expect(err).not.to.be.ok
done()
}) })
}) })
}) })
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 User = this.sequelize.define('User', {}) var User = this.sequelize.define('User', {})
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!