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

restore error being an instance of Seq Validation error

1 parent 0330637f
...@@ -106,10 +106,10 @@ var DaoValidator = module.exports = function(modelInstance, optOptions) { ...@@ -106,10 +106,10 @@ var DaoValidator = module.exports = function(modelInstance, optOptions) {
/** /**
* All errors will be stored here from the validations. * All errors will be stored here from the validations.
* *
* @type {Object} Will contain keys that correspond to attributes which will * @type {Sequelize.error} Will contain keys that correspond to attributes which will
* be Arrays of Errors. * be Arrays of Errors.
*/ */
this.errors = {} this.errors = new sequelizeError.ValidationError('Validation error')
/** @type {boolean} Indicates if validations are in progress */ /** @type {boolean} Indicates if validations are in progress */
this.inProgress = false; this.inProgress = false;
...@@ -128,7 +128,7 @@ DaoValidator.prototype.validate = function() { ...@@ -128,7 +128,7 @@ DaoValidator.prototype.validate = function() {
throw new Error('Validations already in progress.'); throw new Error('Validations already in progress.');
} }
this.inProgress = true; this.inProgress = true;
this.errors = {} this.errors = new sequelizeError.ValidationError('Validation error')
var self = this var self = this
return new Utils.CustomEventEmitter(function(emitter) { return new Utils.CustomEventEmitter(function(emitter) {
......
...@@ -199,12 +199,12 @@ describe(Support.getTestDialectTeaser("DaoValidator"), function() { ...@@ -199,12 +199,12 @@ 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('Object'); expect(_errors).to.be.an.instanceOf(Error)
expect(_errors.name).to.deep.eql([message]) expect(_errors.name).to.deep.eql([message])
done() done()
}) })
}) })
} }
, applyPassTest = function applyPassTest(validatorDetails, j, validator) { , applyPassTest = function applyPassTest(validatorDetails, j, validator) {
...@@ -298,13 +298,13 @@ describe(Support.getTestDialectTeaser("DaoValidator"), function() { ...@@ -298,13 +298,13 @@ 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('Object') expect(err).to.be.an.instanceOf(Error)
expect(err.name).to.deep.equal(['Validation notEmpty failed']); expect(err.name).to.deep.equal(['Validation notEmpty failed']);
done() done()
}) })
}) })
}) })
}) })
...@@ -320,13 +320,13 @@ describe(Support.getTestDialectTeaser("DaoValidator"), function() { ...@@ -320,13 +320,13 @@ 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.update({name: ''}, {id: 1}).error(function(err) { Model.update({name: ''}, {id: 1}).error(function(err) {
expect(err).to.be.an('Object') expect(err).to.be.an.instanceOf(Error)
expect(err.name).to.deep.equal(['Validation notEmpty failed']) expect(err.name).to.deep.equal(['Validation notEmpty failed'])
done() done()
}) })
}) })
}) })
}) })
...@@ -398,12 +398,12 @@ describe(Support.getTestDialectTeaser("DaoValidator"), function() { ...@@ -398,12 +398,12 @@ 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('Object') expect(err).to.be.an.instanceOf(Error)
expect(err.id).to.deep.equal(['Validation isInt failed']) expect(err.id).to.deep.equal(['Validation isInt failed'])
done() done()
}) })
}) })
}) })
...@@ -419,12 +419,12 @@ describe(Support.getTestDialectTeaser("DaoValidator"), function() { ...@@ -419,12 +419,12 @@ 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('Object') expect(err).to.be.an.instanceOf(Error)
expect(err.username).to.deep.equal(['Username must be an integer!']) expect(err.username).to.deep.equal(['Username must be an integer!'])
done() done()
}) })
}) })
}) })
...@@ -446,28 +446,28 @@ describe(Support.getTestDialectTeaser("DaoValidator"), function() { ...@@ -446,28 +446,28 @@ 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('Object') expect(err).to.be.an.instanceOf(Error)
expect(err.id).to.deep.equal(['ID must be an integer!']) expect(err.id).to.deep.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('Object') expect(err).to.be.an.instanceOf(Error)
expect(err.id).to.deep.equal(['ID must be an integer!']) expect(err.id).to.deep.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('Object') expect(err).to.be.an.instanceOf(Error)
expect(err.id).to.deep.equal(['ID must be an integer!']) expect(err.id).to.deep.equal(['ID must be an integer!'])
done() done()
}) })
...@@ -515,7 +515,7 @@ describe(Support.getTestDialectTeaser("DaoValidator"), function() { ...@@ -515,7 +515,7 @@ describe(Support.getTestDialectTeaser("DaoValidator"), function() {
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('Object'); 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,7 +542,7 @@ describe(Support.getTestDialectTeaser("DaoValidator"), function() { ...@@ -542,7 +542,7 @@ 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('Object'); 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'")
...@@ -570,13 +570,13 @@ describe(Support.getTestDialectTeaser("DaoValidator"), function() { ...@@ -570,13 +570,13 @@ 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('Object'); expect(error).to.be.an.instanceOf(Error)
expect(error.age).to.deep.equal(["must be positive"]) expect(error.age).to.deep.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,13 @@ describe(Support.getTestDialectTeaser("DaoValidator"), function() { ...@@ -608,13 +608,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('Object') 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 +646,13 @@ describe(Support.getTestDialectTeaser("DaoValidator"), function() { ...@@ -646,13 +646,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('Object') 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) {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!