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

Commit b907c1ad by Daniel Durante

Added specs to explicitly test for auto incremented/primary key validations. Closes #220.

1 parent da325d96
Showing with 64 additions and 0 deletions
......@@ -254,6 +254,7 @@ describe(Support.getTestDialectTeaser("DaoValidator"), function() {
}
describe('#create', function() {
describe('generic', function() {
beforeEach(function(done) {
var self = this
......@@ -300,6 +301,69 @@ describe(Support.getTestDialectTeaser("DaoValidator"), function() {
})
})
describe('explicitly validating id/primary/auto incremented columns', function() {
it('should emit an error when we try to enter in a string for the id key without validation arguments', function(done) {
var User = this.sequelize.define('UserId', {
id: {
type: Sequelize.INTEGER,
autoIncrement: true,
primaryKey: true,
validate: {
isInt: true
}
}
})
User.sync({ force: true }).success(function() {
User.create({id: 'helloworld'}).error(function(err) {
expect(err).to.deep.equal({id: ['Invalid integer: id']})
done()
})
})
})
it('should emit an error when we try to enter in a string for the id key with validation arguments', function(done) {
var User = this.sequelize.define('UserId', {
id: {
type: Sequelize.INTEGER,
autoIncrement: true,
primaryKey: true,
validate: {
isInt: { args: true, msg: 'ID must be an integer!' }
}
}
})
User.sync({ force: true }).success(function() {
User.create({id: 'helloworld'}).error(function(err) {
expect(err).to.deep.equal({id: ['ID must be an integer!']})
done()
})
})
})
it('should emit an error when we try to enter in a string for an auto increment key (not named id)', function(done) {
var User = this.sequelize.define('UserId', {
username: {
type: Sequelize.INTEGER,
autoIncrement: true,
primaryKey: true,
validate: {
isInt: { args: true, msg: 'Username must be an integer!' }
}
}
})
User.sync({ force: true }).success(function() {
User.create({username: 'helloworldhelloworld'}).error(function(err) {
expect(err).to.deep.equal({username: ['Username must be an integer!']})
done()
})
})
})
})
})
it('correctly validates using custom validation methods', function(done) {
var User = this.sequelize.define('User' + config.rand(), {
name: {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!