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

Commit 5a8a6800 by Sascha Depold

transaction test for bulkDelete

1 parent 20563ff0
...@@ -685,7 +685,6 @@ module.exports = (function() { ...@@ -685,7 +685,6 @@ module.exports = (function() {
} }
daos[i] = newValues || daos[i] daos[i] = newValues || daos[i]
console.log('....................')
daos[i].save({ transaction: options.transaction }).error(function(err) { daos[i].save({ transaction: options.transaction }).error(function(err) {
emitter.emit('error', err) emitter.emit('error', err)
}).success(function() { }).success(function() {
......
...@@ -617,7 +617,7 @@ module.exports = (function() { ...@@ -617,7 +617,7 @@ module.exports = (function() {
return new Utils.CustomEventEmitter(function(emitter) { return new Utils.CustomEventEmitter(function(emitter) {
var chainer = new Utils.QueryChainer() var chainer = new Utils.QueryChainer()
chainer.add(self, 'queryAndEmit', [sql, 'bulkDelete', options]) chainer.add(self, 'queryAndEmit', [[sql, null, options], 'bulkDelete', options])
chainer.runSerially() chainer.runSerially()
.success(function(results){ .success(function(results){
......
...@@ -1398,20 +1398,21 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () { ...@@ -1398,20 +1398,21 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () {
}) })
describe('destroy', function() { describe('destroy', function() {
it('deletes a record from the database if dao is not paranoid', function(done) { it('supports transactions', function(done) {
var UserDestroy = this.sequelize.define('UserDestroy', { Support.prepareTransactionTest(dialect, this.sequelize, function(sequelize) {
name: Sequelize.STRING, var User = sequelize.define('User', { username: Sequelize.STRING })
bio: Sequelize.TEXT
})
UserDestroy.sync({ force: true }).success(function() { User.sync({ force: true }).success(function() {
UserDestroy.create({name: 'hallo', bio: 'welt'}).success(function(u) { User.create({ username: 'foo' }).success(function() {
UserDestroy.all().success(function(users) { sequelize.transaction(function(t) {
expect(users.length).to.equal(1) User.destroy({}, { transaction: t }).success(function() {
u.destroy().success(function() { User.count().success(function(count1) {
UserDestroy.all().success(function(users) { User.count({ transaction: t }).success(function(count2) {
expect(users.length).to.equal(0) expect(count1).to.equal(1)
done() expect(count2).to.equal(0)
t.rollback().success(done)
})
})
}) })
}) })
}) })
...@@ -1419,26 +1420,6 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () { ...@@ -1419,26 +1420,6 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () {
}) })
}) })
it('allows sql logging of delete statements', function(done) {
var UserDelete = this.sequelize.define('UserDelete', {
name: Sequelize.STRING,
bio: Sequelize.TEXT
})
UserDelete.sync({ force: true }).success(function() {
UserDelete.create({name: 'hallo', bio: 'welt'}).success(function(u) {
UserDelete.all().success(function(users) {
expect(users.length).to.equal(1)
u.destroy().on('sql', function(sql) {
expect(sql).to.exist
expect(sql.toUpperCase().indexOf("DELETE")).to.be.above(-1)
done()
})
})
})
})
})
it('deletes values that match filter', function(done) { it('deletes values that match filter', function(done) {
var self = this var self = this
, data = [{ username: 'Peter', secretValue: '42' }, , data = [{ username: 'Peter', secretValue: '42' },
......
...@@ -1275,4 +1275,47 @@ describe(Support.getTestDialectTeaser("DAO"), function () { ...@@ -1275,4 +1275,47 @@ describe(Support.getTestDialectTeaser("DAO"), function () {
}) })
}) })
}) })
describe('destroy', function() {
it('deletes a record from the database if dao is not paranoid', function(done) {
var UserDestroy = this.sequelize.define('UserDestroy', {
name: Sequelize.STRING,
bio: Sequelize.TEXT
})
UserDestroy.sync({ force: true }).success(function() {
UserDestroy.create({name: 'hallo', bio: 'welt'}).success(function(u) {
UserDestroy.all().success(function(users) {
expect(users.length).to.equal(1)
u.destroy().success(function() {
UserDestroy.all().success(function(users) {
expect(users.length).to.equal(0)
done()
})
})
})
})
})
})
it('allows sql logging of delete statements', function(done) {
var UserDelete = this.sequelize.define('UserDelete', {
name: Sequelize.STRING,
bio: Sequelize.TEXT
})
UserDelete.sync({ force: true }).success(function() {
UserDelete.create({name: 'hallo', bio: 'welt'}).success(function(u) {
UserDelete.all().success(function(users) {
expect(users.length).to.equal(1)
u.destroy().on('sql', function(sql) {
expect(sql).to.exist
expect(sql.toUpperCase().indexOf("DELETE")).to.be.above(-1)
done()
})
})
})
})
})
})
}) })
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!