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

indent changes based on new code updates

1 parent 9c99552e
...@@ -27,16 +27,16 @@ DaoValidator.prototype.validate = function() { ...@@ -27,16 +27,16 @@ DaoValidator.prototype.validate = function() {
emitter.emit('success') emitter.emit('success')
}) })
.error(function(err) { .error(function(err) {
var error = new Error('Validation error') var error = new Error('Validation error')
error[DaoValidator.RAW_KEY_NAME] = [] error[DaoValidator.RAW_KEY_NAME] = []
Utils._.each(err, function (value) { Utils._.each(err, function (value) {
error[DaoValidator.RAW_KEY_NAME].push(value[DaoValidator.RAW_KEY_NAME]) error[DaoValidator.RAW_KEY_NAME].push(value[DaoValidator.RAW_KEY_NAME])
delete value[DaoValidator.RAW_KEY_NAME] delete value[DaoValidator.RAW_KEY_NAME]
Utils._.extend(error, value) Utils._.extend(error, value)
}) })
emitter.emit('success', error) emitter.emit('success', error)
}) })
}).run() }).run()
} }
...@@ -69,7 +69,6 @@ DaoValidator.prototype.hookValidate = function() { ...@@ -69,7 +69,6 @@ DaoValidator.prototype.hookValidate = function() {
} }
// private // private
var validateModel = function() { var validateModel = function() {
Utils._.each(this.model.__options.validate, function(_validator, validatorType) { Utils._.each(this.model.__options.validate, function(_validator, validatorType) {
var validator = prepareValidationOfAttribute.call(this, undefined, _validator, validatorType, { omitValue: true }) var validator = prepareValidationOfAttribute.call(this, undefined, _validator, validatorType, { omitValue: true })
...@@ -78,11 +77,11 @@ var validateModel = function() { ...@@ -78,11 +77,11 @@ var validateModel = function() {
var next = function(err) { var next = function(err) {
if (err) { if (err) {
var error = {}; var error = {};
error[DaoValidator.RAW_KEY_NAME] = err; error[DaoValidator.RAW_KEY_NAME] = err
var msg = ((err instanceof Error) ? err.message : err) var msg = ((err instanceof Error) ? err.message : err)
error[validatorType] = [msg] error[validatorType] = [msg]
emitter.emit('error', error) emitter.emit('error', error)
} else { } else {
emitter.emit('success') emitter.emit('success')
...@@ -164,7 +163,7 @@ var prepareValidationOfAttribute = function(value, details, validatorType, optio ...@@ -164,7 +163,7 @@ var prepareValidationOfAttribute = function(value, details, validatorType, optio
try { try {
details.apply(this.model, callArgs) details.apply(this.model, callArgs)
} catch(ex) { } catch(ex) {
return next(ex) return next(ex)
} }
if (!isAsync) { if (!isAsync) {
......
...@@ -8,7 +8,7 @@ var chai = require('chai') ...@@ -8,7 +8,7 @@ var chai = require('chai')
chai.Assertion.includeStack = true chai.Assertion.includeStack = true
describe(Support.getTestDialectTeaser("DaoValidator"), function() { describe(Support.getTestDialectTeaser("DaoValidator"), function() {
describe.only('validations', function() { describe('validations', function() {
var checks = { var checks = {
is: { is: {
spec: { args: ["[a-z]",'i'] }, spec: { args: ["[a-z]",'i'] },
...@@ -476,7 +476,7 @@ describe(Support.getTestDialectTeaser("DaoValidator"), function() { ...@@ -476,7 +476,7 @@ describe(Support.getTestDialectTeaser("DaoValidator"), function() {
}) })
}) })
it('correctly validates using custom validation methods', function(done) { it.only('correctly validates using custom validation methods', function(done) {
var User = this.sequelize.define('User' + config.rand(), { var User = this.sequelize.define('User' + config.rand(), {
name: { name: {
type: Sequelize.STRING, type: Sequelize.STRING,
...@@ -495,6 +495,7 @@ describe(Support.getTestDialectTeaser("DaoValidator"), function() { ...@@ -495,6 +495,7 @@ describe(Support.getTestDialectTeaser("DaoValidator"), function() {
var failingUser = User.build({ name : "3" }) var failingUser = User.build({ name : "3" })
failingUser.validate().success(function(errors) { failingUser.validate().success(function(errors) {
console.log('ERR:\n', errors, '\n\n', errors.name, '\n\n');
expect(errors).to.deep.equal({ name: ["name should equal '2'"] }) expect(errors).to.deep.equal({ name: ["name should equal '2'"] })
var successfulUser = User.build({ name : "2" }) var successfulUser = User.build({ name : "2" })
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!