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

Commit faf948ea by Ruben Bridgewater

Fix transactions not rolling back properly

Fix test to actually check for the rollback happening
1 parent d1662c13
......@@ -1142,18 +1142,18 @@ module.exports = (function() {
var result = autoCallback(transaction);
if (!result || !result.then) return reject(new Error('You need to return a promise chain/thenable to the sequelize.transaction() callback'));
result.then(function (result) {
return result.then(function (result) {
return transaction.commit().then(function () {
resolve(result);
});
}).then(null, function (err) {
});
}).catch(function(err) {
transaction.rollback().then(function () {
reject(err);
}, function () {
reject(err);
});
});
}).catch(reject);
};
if (ns) {
......
......@@ -45,9 +45,13 @@ describe(Support.getTestDialectTeaser('Transaction'), function() {
});
});
it('supports automatically rolling back with a thrown error', function() {
return expect(this.sequelize.transaction(function() {
var t;
return (expect(this.sequelize.transaction(function(transaction) {
t = transaction;
throw new Error('Yolo');
})).to.eventually.be.rejected;
})).to.eventually.be.rejected).then(function() {
expect(t.finished).to.be.equal('rollback');
});
});
it('supports automatically rolling back with a rejection', function() {
return expect(this.sequelize.transaction(function() {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!