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

Commit bccd3a0e by Sascha Depold

transaction tests

1 parent 28eeef7e
......@@ -7,6 +7,7 @@ var chai = require('chai')
, Sequelize = require(__dirname + '/../index')
, config = require(__dirname + "/config/config")
, moment = require('moment')
, Transaction = require(__dirname + '/../lib/transaction')
chai.Assertion.includeStack = true
......@@ -472,17 +473,47 @@ describe(Support.getTestDialectTeaser("Sequelize"), function () {
})
it('passes a transaction object to the callback', function(done) {
var Transaction = require(__dirname + '/../lib/transaction')
this.sequelize.transaction(function(t) {
expect(t).to.be.instanceOf(Transaction)
done()
})
})
it("creates a new connection", function(done) {
it('returns a transaction object', function() {
expect(this.sequelize.transaction(function(){})).to.be.instanceOf(Transaction)
})
it('allows me to define a callback on the result', function(done) {
this
.sequelize
.transaction(function(t) { console.log(t); t.commit() })
.done(done)
})
it('allows me to define a callback on the transaction object', function(done) {
this.sequelize.transaction(function(t) {
done()
t.done(done)
t.commit()
})
})
it("creates a new connection", function(done) {
var sql = "SELECT count(*) connection_count FROM INFORMATION_SCHEMA.PROCESSLIST WHERE DB = 'sequelize_test';"
, self = this
this.sequelize.query(sql, null, { plain: true, raw: true }).success(function(r1) {
expect(r1.connection_count).to.equal(2)
self.sequelize.transaction(function(t) {
self.sequelize.query(sql, null, { plain: true, raw: true, transaction: t}).success(function(r2) {
expect(r1.connection_count).to.equal(3)
})
}).done(function() {
self.sequelize.query(sql, null, { plain: true, raw: true, transaction: t}).success(function(r2) {
expect(r1.connection_count).to.equal(2)
done()
})
})
})
})
})
......
......@@ -15,4 +15,24 @@ describe(Support.getTestDialectTeaser("Transaction"), function () {
expect(transaction.id).to.exist
})
})
describe('commit', function() {
it('is a commit message available', function() {
expect(Transaction).to.respondTo('commit')
})
})
describe('rollback', function() {
it('is a rollback message available', function() {
expect(Transaction).to.respondTo('rollback')
})
})
describe('done', function() {
it('gets called when the transaction gets commited', function(done) {
var transaction = new Transaction()
transaction.done(done)
transaction.commit()
})
})
})
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!