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

Commit fc644f4b by Pavel Committed by Sushant

fix(error): optimistic lock message (#10068)

1 parent 4b39e530
......@@ -92,7 +92,7 @@ class OptimisticLockError extends BaseError {
constructor(options) {
options = options || {};
options.message = options.message || `Attempting to update a stale model instance: ${options.modelName}`;
super(options);
super(options.message);
this.name = 'SequelizeOptimisticLockError';
/**
* The name of the model on which the update was attempted
......
......@@ -242,7 +242,36 @@ describe(Support.getTestDialectTeaser('Sequelize Errors'), () => {
});
});
describe('Constraint error', () => {
describe('OptimisticLockError', () => {
it('got correct error type and message', function() {
const Account = this.sequelize.define('Account', {
number: {
type: Sequelize.INTEGER
}
}, {
version: true
});
return Account.sync({force: true}).then(() => {
const result = Account.create({number: 1}).then(accountA => {
return Account.findByPk(accountA.id).then(accountB => {
accountA.number += 1;
return accountA.save().then(() => { return accountB; });
});
}).then(accountB => {
accountB.number += 1;
return accountB.save();
});
return Promise.all([
expect(result).to.eventually.be.rejectedWith(Support.Sequelize.OptimisticLockError),
expect(result).to.eventually.be.rejectedWith('Attempting to update a stale model instance: Account')
]);
});
});
});
describe('ConstraintError', () => {
[
{
type: 'UniqueConstraintError',
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!