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

link dao-validations.test file INDENTATIONS

1 parent 678b9267
Showing with 129 additions and 130 deletions
...@@ -199,13 +199,13 @@ describe(Support.getTestDialectTeaser("DaoValidator"), function() { ...@@ -199,13 +199,13 @@ describe(Support.getTestDialectTeaser("DaoValidator"), function() {
var failingUser = UserFail.build({ name : failingValue }) var failingUser = UserFail.build({ name : failingValue })
failingUser.validate().done( function(err, _errors) { failingUser.validate().done( function(err, _errors) {
expect(_errors).to.not.be.null expect(_errors).to.not.be.null
expect(_errors).to.be.an.instanceOf(Error) expect(_errors).to.be.an.instanceOf(Error)
expect(_errors.name[0].message).to.equal(message) expect(_errors.name[0].message).to.equal(message)
done() done()
}) })
}) })
} }
, applyPassTest = function applyPassTest(validatorDetails, j, validator) { , applyPassTest = function applyPassTest(validatorDetails, j, validator) {
var succeedingValue = validatorDetails.pass[j] var succeedingValue = validatorDetails.pass[j]
...@@ -231,7 +231,7 @@ describe(Support.getTestDialectTeaser("DaoValidator"), function() { ...@@ -231,7 +231,7 @@ describe(Support.getTestDialectTeaser("DaoValidator"), function() {
expect(arguments).to.have.length(0) expect(arguments).to.have.length(0)
done() done()
}).error(function(err) { }).error(function(err) {
expect(err).to.deep.equal({}) expect(err).to.deep.equal({})
done() done()
}) })
}) })
...@@ -298,14 +298,14 @@ describe(Support.getTestDialectTeaser("DaoValidator"), function() { ...@@ -298,14 +298,14 @@ describe(Support.getTestDialectTeaser("DaoValidator"), function() {
} }
}) })
Model.sync({ force: true }).success(function() { Model.sync({ force: true }).success(function() {
Model.create({name: 'World'}).success(function(model) { Model.create({name: 'World'}).success(function(model) {
model.updateAttributes({name: ''}).error(function(err) { model.updateAttributes({name: ''}).error(function(err) {
expect(err).to.be.an.instanceOf(Error) expect(err).to.be.an.instanceOf(Error)
expect(err.name[0].message).to.equal('Validation notEmpty failed'); expect(err.name[0].message).to.equal('Validation notEmpty failed');
done() done()
}) })
}) })
}) })
}) })
...@@ -318,16 +318,16 @@ describe(Support.getTestDialectTeaser("DaoValidator"), function() { ...@@ -318,16 +318,16 @@ describe(Support.getTestDialectTeaser("DaoValidator"), function() {
notEmpty: true // don't allow empty strings notEmpty: true // don't allow empty strings
} }
} }
}) })
Model.sync({ force: true }).success(function() { Model.sync({ force: true }).success(function() {
Model.create({name: 'World'}).success(function() { Model.create({name: 'World'}).success(function() {
Model.update({name: ''}, {id: 1}).error(function(err) { Model.update({name: ''}, {id: 1}).error(function(err) {
expect(err).to.be.an.instanceOf(Error) expect(err).to.be.an.instanceOf(Error)
expect(err.name[0].message).to.equal('Validation notEmpty failed') expect(err.name[0].message).to.equal('Validation notEmpty failed')
done() done()
}) })
}) })
}) })
}) })
}) })
...@@ -398,13 +398,13 @@ describe(Support.getTestDialectTeaser("DaoValidator"), function() { ...@@ -398,13 +398,13 @@ describe(Support.getTestDialectTeaser("DaoValidator"), function() {
} }
}) })
User.sync({ force: true }).success(function() { User.sync({ force: true }).success(function() {
User.create({id: 'helloworld'}).error(function(err) { User.create({id: 'helloworld'}).error(function(err) {
expect(err).to.be.an.instanceOf(Error) expect(err).to.be.an.instanceOf(Error)
expect(err.id[0].message).to.equal('Validation isInt failed') expect(err.id[0].message).to.equal('Validation isInt failed')
done() done()
}) })
}) })
}) })
it('should emit an error when we try to enter in a string for an auto increment key (not named id)', function(done) { it('should emit an error when we try to enter in a string for an auto increment key (not named id)', function(done) {
...@@ -419,13 +419,13 @@ describe(Support.getTestDialectTeaser("DaoValidator"), function() { ...@@ -419,13 +419,13 @@ describe(Support.getTestDialectTeaser("DaoValidator"), function() {
} }
}) })
User.sync({ force: true }).success(function() { User.sync({ force: true }).success(function() {
User.create({username: 'helloworldhelloworld'}).error(function(err) { User.create({username: 'helloworldhelloworld'}).error(function(err) {
expect(err).to.be.an.instanceOf(Error) expect(err).to.be.an.instanceOf(Error)
expect(err.username[0].message).to.equal('Username must be an integer!') expect(err.username[0].message).to.equal('Username must be an integer!')
done() done()
}) })
}) })
}) })
describe("primaryKey with the name as id with arguments for it's validation", function() { describe("primaryKey with the name as id with arguments for it's validation", function() {
...@@ -446,80 +446,80 @@ describe(Support.getTestDialectTeaser("DaoValidator"), function() { ...@@ -446,80 +446,80 @@ describe(Support.getTestDialectTeaser("DaoValidator"), function() {
}) })
}) })
it('should emit an error when we try to enter in a string for the id key with validation arguments', function(done) { it('should emit an error when we try to enter in a string for the id key with validation arguments', function(done) {
this.User.create({id: 'helloworld'}).error(function(err) { this.User.create({id: 'helloworld'}).error(function(err) {
expect(err).to.be.an.instanceOf(Error) expect(err).to.be.an.instanceOf(Error)
expect(err.id[0].message).to.equal('ID must be an integer!') expect(err.id[0].message).to.equal('ID must be an integer!')
done() done()
}) })
}) })
it('should emit an error when we try to enter in a string for an auto increment key through .build().validate()', function(done) { it('should emit an error when we try to enter in a string for an auto increment key through .build().validate()', function(done) {
var user = this.User.build({id: 'helloworld'}) var user = this.User.build({id: 'helloworld'})
user.validate().success(function(err) { user.validate().success(function(err) {
expect(err).to.be.an.instanceOf(Error) expect(err).to.be.an.instanceOf(Error)
expect(err.id[0].message).to.equal('ID must be an integer!') expect(err.id[0].message).to.equal('ID must be an integer!')
done() done()
}) })
}) })
it('should emit an error when we try to .save()', function(done) { it('should emit an error when we try to .save()', function(done) {
var user = this.User.build({id: 'helloworld'}) var user = this.User.build({id: 'helloworld'})
user.save().error(function(err) { user.save().error(function(err) {
expect(err).to.be.an.instanceOf(Error) expect(err).to.be.an.instanceOf(Error)
expect(err.id[0].message).to.equal('ID must be an integer!') expect(err.id[0].message).to.equal('ID must be an integer!')
done() done()
}) })
}) })
}) })
}) })
describe('Pass all paths when validating', function() { describe('Pass all paths when validating', function() {
beforeEach(function(done) { beforeEach(function(done) {
var self = this var self = this
var Project = this.sequelize.define('Project', { var Project = this.sequelize.define('Project', {
name: { name: {
type: Sequelize.STRING, type: Sequelize.STRING,
allowNull: false, allowNull: false,
validate: { validate: {
isIn: [['unknown', 'hello', 'test']] isIn: [['unknown', 'hello', 'test']]
} }
}, },
creatorName: { creatorName: {
type: Sequelize.STRING, type: Sequelize.STRING,
allowNull: false, allowNull: false,
}, },
cost: { cost: {
type: Sequelize.INTEGER, type: Sequelize.INTEGER,
allowNull: false, allowNull: false,
}, },
}) })
var Task = this.sequelize.define('Task', { var Task = this.sequelize.define('Task', {
something: Sequelize.INTEGER something: Sequelize.INTEGER
}) })
Project.hasOne(Task) Project.hasOne(Task)
Task.hasOne(Project) Task.hasOne(Project)
Project.sync({ force: true }).success(function() { Project.sync({ force: true }).success(function() {
Task.sync({ force: true }).success(function() { Task.sync({ force: true }).success(function() {
self.Project = Project self.Project = Project
self.Task = Task self.Task = Task
done() done()
}) })
}) })
}) })
it('produce 3 errors', function(done) { it('produce 3 errors', function(done) {
this.Project.create({}).error(function(err) { this.Project.create({}).error(function(err) {
expect(err).to.be.an.instanceOf(Error) expect(err).to.be.an.instanceOf(Error)
expect(Object.keys(err)).to.have.length(3) expect(Object.keys(err)).to.have.length(3)
done() done()
}) })
}) })
}) })
}) })
...@@ -542,16 +542,16 @@ describe(Support.getTestDialectTeaser("DaoValidator"), function() { ...@@ -542,16 +542,16 @@ describe(Support.getTestDialectTeaser("DaoValidator"), function() {
var failingUser = User.build({ name : "3" }) var failingUser = User.build({ name : "3" })
failingUser.validate().success(function(error) { failingUser.validate().success(function(error) {
expect(error).to.be.an.instanceOf(Error) expect(error).to.be.an.instanceOf(Error)
expect(error.name[0].message).to.equal("name should equal '2'") expect(error.name[0].message).to.equal("name should equal '2'")
var successfulUser = User.build({ name : "2" }) var successfulUser = User.build({ name : "2" })
successfulUser.validate().success(function() { successfulUser.validate().success(function() {
expect(arguments).to.have.length(0) expect(arguments).to.have.length(0)
done() done()
}).error(function(err) { }).error(function(err) {
expect(err[0].message).to.equal() expect(err[0].message).to.equal()
done() done()
}) })
}) })
...@@ -570,14 +570,14 @@ describe(Support.getTestDialectTeaser("DaoValidator"), function() { ...@@ -570,14 +570,14 @@ describe(Support.getTestDialectTeaser("DaoValidator"), function() {
User User
.build({ age: -1 }) .build({ age: -1 })
.validate() .validate()
.success(function(error) { .success(function(error) {
expect(error).not.to.be.null expect(error).not.to.be.null
expect(error).to.be.an.instanceOf(Error) expect(error).to.be.an.instanceOf(Error)
expect(error.age[0].message).to.equal("must be positive") expect(error.age[0].message).to.equal("must be positive")
User.build({ age: null }).validate().success(function() { User.build({ age: null }).validate().success(function() {
User.build({ age: 1 }).validate().success(function() { User.build({ age: 1 }).validate().success(function() {
done() done()
}) })
}) })
...@@ -608,13 +608,12 @@ describe(Support.getTestDialectTeaser("DaoValidator"), function() { ...@@ -608,13 +608,12 @@ describe(Support.getTestDialectTeaser("DaoValidator"), function() {
Foo Foo
.build({ field1: null, field2: null }) .build({ field1: null, field2: null })
.validate() .validate()
.success(function(error) { .success(function(error) {
expect(error).not.to.be.null expect(error).not.to.be.null
expect(error).to.be.an.instanceOf(Error) expect(error).to.be.an.instanceOf(Error)
expect(error.xnor[0].message).to.equal('xnor failed'); expect(error.xnor[0].message).to.equal('xnor failed');
Foo
Foo
.build({ field1: 33, field2: null }) .build({ field1: 33, field2: null })
.validate() .validate()
.success(function(errors) { .success(function(errors) {
...@@ -646,13 +645,13 @@ describe(Support.getTestDialectTeaser("DaoValidator"), function() { ...@@ -646,13 +645,13 @@ describe(Support.getTestDialectTeaser("DaoValidator"), function() {
Foo Foo
.build({ field1: null, field2: null }) .build({ field1: null, field2: null })
.validate() .validate()
.success(function(error) { .success(function(error) {
expect(error).not.to.be.null expect(error).not.to.be.null
expect(error).to.be.an.instanceOf(Error) expect(error).to.be.an.instanceOf(Error)
expect(error.xnor[0].message).to.equal('xnor failed') expect(error.xnor[0].message).to.equal('xnor failed')
Foo Foo
.build({ field1: 33, field2: null }) .build({ field1: 33, field2: null })
.validate() .validate()
.success(function(errors) { .success(function(errors) {
...@@ -700,7 +699,7 @@ describe(Support.getTestDialectTeaser("DaoValidator"), function() { ...@@ -700,7 +699,7 @@ describe(Support.getTestDialectTeaser("DaoValidator"), function() {
failingBar.validate().success(function(errors) { failingBar.validate().success(function(errors) {
expect(errors).not.to.be.null expect(errors).not.to.be.null
expect(errors.field).to.have.length(1) expect(errors.field).to.have.length(1)
expect(errors.field[0].message).to.equal("Validation isIn failed") expect(errors.field[0].message).to.equal("Validation isIn failed")
}) })
}) })
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!