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

Commit 089504fe by Gabe Gorelick Committed by Sushant

feat(instance-validator): add model name to allowNull messages (#8500)

1 parent e40f6f45
......@@ -322,7 +322,7 @@ class InstanceValidator {
if (rawAttribute.allowNull === false && (value === null || value === undefined)) {
const validators = this.modelInstance.validators[field];
const errMsg = _.get(validators, 'notNull.msg', `${field} cannot be null`);
const errMsg = _.get(validators, 'notNull.msg', `${this.modelInstance.constructor.name}.${field} cannot be null`);
error = new sequelizeError.ValidationErrorItem(errMsg, 'notNull Violation', field, value);
this.errors.push(error);
}
......
......@@ -375,9 +375,9 @@ describe(Support.getTestDialectTeaser('InstanceValidator'), () => {
it('correctly throws an error using create method with default generated messages', function() {
return this.Project.create({}).catch(err => {
expect(err).to.have.property('name', 'SequelizeValidationError');
expect(err.message).equal('notNull Violation: name cannot be null');
expect(err.message).equal('notNull Violation: Project.name cannot be null');
expect(err.errors).to.be.an('array').and.have.length(1);
expect(err.errors[0]).to.have.property('message', 'name cannot be null');
expect(err.errors[0]).to.have.property('message', 'Project.name cannot be null');
});
});
});
......
......@@ -65,6 +65,20 @@ describe(Support.getTestDialectTeaser('InstanceValidator'), () => {
return expect(result).to.be.rejectedWith(SequelizeValidationError);
});
it('has a useful default error message for not null validation failures', () => {
const User = Support.sequelize.define('user', {
name: {
type: Support.Sequelize.STRING,
allowNull: false
}
});
const instanceValidator = new InstanceValidator(User.build());
const result = instanceValidator.validate();
return expect(result).to.be.rejectedWith(SequelizeValidationError, /user\.name cannot be null/);
});
});
describe('_validateAndRunHooks', () => {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!