Commit Graph

22 Commits

Author SHA1 Message Date
Fabien Franzen 86ea107550 Validations configuration as object
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`.
2014-08-26 17:51:01 +02:00
Fabien Franzen bed97a75cb Expose validation metadata
The new Validatable.validations mixin method returns the validations as
an object
indexed by property name.
2014-08-26 16:56:09 +02:00
Fabien Franzen 50656b8206 Handle custom error codes
Fixes #151
2014-07-11 23:03:07 +02:00
Fabien Franzen a58dbe3a54 More validations and tests
Added validatesAbsenceOf. Handle async with if/unless prevention of
validators correctly. See: #170 #158
2014-07-11 22:56:02 +02:00
Fabien Franzen 5f1431aa05 Don't check uniqueness of blank values 2014-07-11 22:07:57 +02:00
Miroslav Bajtoš 65fa7a1c00 validations: include more details in `err.message`
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.
2014-05-27 21:59:21 -07:00
Miroslav Bajtoš 2a74bdc4de validations: support multi-key unique constraint
Modify the "unique" validator to accept additional property names to
narrow the space of rows searched for duplicates.

Example:

Consider `SiteUser` belongsTo `Site` via `siteId` foreign key.
Inside every site, the user email must be unique. It is allowed to
register the same email with multiple sites.

    SiteUser.validateUniquenessOf('email', { scopedTo: ['siteId'] });
2014-05-15 09:15:44 +02:00
Raymond Feng b42f7d2498 Remove the disconnect to avoid race condition 2014-03-27 13:56:24 -07:00
Raymond Feng 2b8c1ebaee Reformat the code 2014-01-24 09:09:53 -08:00
Miroslav Bajtos b5e0035d73 Improve properties of ValidationError
- change `statusCode` from 400 to 422
- nest `context` and `codes` inside `details`
- add `details.messages`
- reword the main error message

Remove the call to Error's constructor from ValidationError constructor,
because it's a no-op - Error's constructor creates a new
instance when called via `.call()`.
2013-12-02 21:35:47 +01:00
Anatoliy Chakkaev f98f62388d Temp. disable test for validation 2013-05-13 22:04:29 -07:00
Anatoliy Chakkaev 06641da2c6 Add context info to validation error 2013-05-13 22:04:29 -07:00
Anatoliy Chakkaev 43f395d653 Manually require init 2013-04-06 14:57:12 +04:00
Anatoliy Chakkaev 3a355851b6 ValidationError instead Error 2013-04-04 19:31:07 +04:00
Anatoliy Chakkaev be17763eca Return valid in case of sync validations 2013-04-01 20:13:55 +04:00
Anatoliy Chakkaev c5019ef354 Test update 2013-04-01 20:10:46 +04:00
Anatoliy Chakkaev b0a1ed3bed Fix validation issue 2013-04-01 20:08:22 +04:00
Anatoliy Chakkaev c1e3e78976 Turn off ignoring tests 2013-03-29 12:54:04 +04:00
Anatoliy Chakkaev 839791de2f Upd tests
- skipping
- hook up redis-hq
- some stuff should be moved to advanced-querying tests
2013-03-29 11:43:04 +04:00
Anatoliy Chakkaev d5d07d8806 Make tests importable 2013-03-26 04:41:00 +04:00
Anatoliy Chakkaev 8d53ed5e82 Docs for models 2013-03-25 15:04:07 +04:00
Anatoliy Chakkaev 716318bedd Rewrite validations in mocha 2013-03-25 02:21:18 +04:00