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

Commit 6890a60d by Sushant Committed by Mick Hansen

(test) paranoid without timestamps (#6804)

1 parent a68f8a03
......@@ -91,7 +91,7 @@ class Model {
if (!_.some(this.rawAttributes, 'primaryKey')) {
if ('id' in this.rawAttributes) {
// Something is fishy here!
throw new Error(`A column called 'id' was added to the attributes of \'${this.tableName}\' but not marked with 'primaryKey: true'`);
throw new Error(`A column called 'id' was added to the attributes of '${this.tableName}' but not marked with 'primaryKey: true'`);
}
head = {
......
'use strict';
/* jshint -W030 */
var Support = require(__dirname + '/../support');
var DataTypes = require(__dirname + '/../../../lib/data-types');
var chai = require('chai');
var expect = chai.expect;
var sinon = require('sinon');
var Support = require(__dirname + '/../support');
describe(Support.getTestDialectTeaser('Model'), function () {
describe('paranoid', function () {
before(function () {
this.clock = sinon.useFakeTimers();
});
after(function () {
this.clock.restore();
});
it('should be able to soft delete with timestamps', function () {
const Account = this.sequelize.define('Account', {
ownerId: {
type: DataTypes.INTEGER,
allowNull: false,
field: 'owner_id'
},
name: {
type: DataTypes.STRING
}
}, {
paranoid: true,
timestamps: true
});
return Account.sync({force: true})
.then(() => Account.create({ ownerId: 12 }))
.then(() => Account.count())
.then((count) => {
expect(count).to.be.equal(1);
return Account.destroy({ where: { ownerId: 12 }});
})
.then(() => Account.count())
.then((count) => {
expect(count).to.be.equal(0);
return Account.count({ paranoid: false });
})
.then((count) => {
expect(count).to.be.equal(1);
return Account.restore({ where: { ownerId: 12 }});
})
.then(() => Account.count())
.then((count) => {
expect(count).to.be.equal(1);
});
});
it('should be able to soft delete without timestamps', function () {
const Account = this.sequelize.define('Account', {
ownerId: {
type: DataTypes.INTEGER,
allowNull: false,
field: 'owner_id'
},
name: {
type: DataTypes.STRING
},
deletedAt: {
type: DataTypes.DATE,
allowNull: true
}
}, {
paranoid: true,
timestamps: true,
deletedAt: 'deletedAt',
createdAt: false,
updatedAt: false
});
return Account.sync({force: true})
.then(() => Account.create({ ownerId: 12 }))
.then(() => Account.count())
.then((count) => {
expect(count).to.be.equal(1);
return Account.destroy({ where: { ownerId: 12 }});
})
.then(() => Account.count())
.then((count) => {
expect(count).to.be.equal(0);
return Account.count({ paranoid: false });
})
.then((count) => {
expect(count).to.be.equal(1);
return Account.restore({ where: { ownerId: 12 }});
})
.then(() => Account.count())
.then((count) => {
expect(count).to.be.equal(1);
});
});
});
});
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!