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

Commit 2b889ed7 by ekmartin

Make sure truncate: true is still allowed in Model.destroy() and add a test for it

1 parent 5c84dc0d
Showing with 20 additions and 3 deletions
......@@ -1415,8 +1415,8 @@ module.exports = (function() {
var self = this
, instances;
if (!options || !options.where) {
throw new Error('Missing where attribute in the options parameter passed to destroy.');
if (!options || !(options.where || options.truncate)) {
throw new Error('Missing where or truncate attribute in the options parameter passed to destroy.');
}
options = Utils._.extend({
......
......@@ -1094,6 +1094,22 @@ describe(Support.getTestDialectTeaser('Model'), function() {
});
describe('destroy', function() {
it('truncate should clear the table', function() {
var User = this.sequelize.define('User', { username: DataTypes.STRING }),
data = [
{ username: 'user1' },
{ username: 'user2' }
];
return this.sequelize.sync({ force: true }).then(function() {
return User.bulkCreate(data);
}).then(function() {
return User.destroy({ truncate: true });
}).then(function() {
return expect(User.findAll()).to.eventually.have.length(0);
});
});
it('throws an error if no where clause is given', function() {
var User = this.sequelize.define('User', { username: DataTypes.STRING });
......@@ -1102,7 +1118,8 @@ describe(Support.getTestDialectTeaser('Model'), function() {
}).then(function() {
throw new Error('Destroy should throw an error if no where clause is given.');
}, function(err) {
expect(err.message).to.equal('Missing where attribute in the options parameter passed to destroy.');
expect(err).to.be.an.instanceof(Error);
expect(err.message).to.equal('Missing where or truncate attribute in the options parameter passed to destroy.');
});
});
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!