validateNumericality didn't test if attributes value is a number
only if it's type is number.
Further nullCheck had a wrong testing order. It first checked if
value is null, later if blank. Also null check only used two equals,
not three. We don't use blank() anymore, testing if variable is
undefined should be fine too.
Added tests covering validateNumericality.
When a required number property is set to NaN, for example as a result
of coersion (`Number([1,2,3])`), the "presence" validation now correctly
reports an error.
When building a list of errors for `ValidationError.message`, include
the values of invalid properties too.
In order to keep the message reasonably short, the values are truncated
at approx 32 characters.
If the validator configured with `{async:true}` option and `if/unless`
condition, validator should be skipped when the condition is un-fulfilled,
so the validator should be pass.
But currently, when skipping the validator, it calls `done(true)` which
accepts a `fail` flag as a param, this will fail the entire validation.
Signed-off-by: Clark Wang <clark.wangs@gmail.com>
Previously validations were appended to an array when configured. The
format was cumbersome, and led to issues. This refactors the
configuration into an object, as a property of the Model.
Note that if no validations have been configured, this property is
currently `undefined`.
Call `Error.captureStackTrace()` only when it is available.
Use `this.stack = (new Error).stack` when `captureStackTrace` is not
available but the `stack` property is (Firefox).
Modify ValidationError constructor to include the model name and
a human-readable representation of the validation errors (messages)
in the error message.
Before this change, the message was pointing the reader
to `err.details`. Most frameworks (e.g. express, mocha) log only
`err.message` but not other error properties, thus the logs were
rather unhelpful.
Example of the new error message:
The `User` instance is not valid. Details: `name` can't be blank.
Modify ValidationError constructor to include the model name and
a human-readable representation of the validation errors (messages)
in the error message.
Before this change, the message was pointing the reader
to `err.details`. Most frameworks (e.g. express, mocha) log only
`err.message` but not other error properties, thus the logs were
rather unhelpful.
Example of the new error message:
The `User` instance is not valid. Details: `name` can't be blank.