Commit Graph

34 Commits

Author SHA1 Message Date
Miroslav Bajtoš 27c6279d6c fix remaining eslint issues 2016-04-05 15:25:34 +02:00
Miroslav Bajtoš 39e04a1756 eslint --fix 2016-04-05 15:25:34 +02:00
Ryan Graham c467b43c38 Insert copyright headers 2016-04-04 18:14:03 -07:00
Fabien Franzen 6ce47f71b4 Correctly handle validatesUniquenessOf(idName) 2015-07-13 12:56:49 +02:00
Miroslav Bajtoš 9bc79d2366 dao: support validateUpsert:false
- validateUpsert:true reports validation errors back to the callback
 - validateUpsert:false does not call `isValid()` at all
 - any other value report validation errors via `console.warn`
2015-05-05 08:24:08 +02:00
Miroslav Bajtoš 40eecd98c9 validations: treat `NaN` as a blank value
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.
2015-04-22 19:57:48 +02:00
Miroslav Bajtoš 3df62444d6 Validate model on updateOrCreate (upsert).
Fix the implementation of updateOrCreate (a.k.a. upsert) to validate
the model before calling the connector.

In order to preserve backwards compatibility, validation errors are
only logged via console.warn by default.

The correct behaviour, where validation errors fail the updateOrCreate
operation, can be enabled via new model setting "validateUpsert".
2015-04-16 09:09:54 +02:00
James Billingham 28f3f5d9f8 Fixed nullCheck in validations to correct behavior when dealing with undefined attributes 2015-01-27 22:18:47 +00:00
Miroslav Bajtoš e4fc38788f Fix Model.prototype.inspect
Return the raw object data when running on Node v0.11.14+
That way all `inspect` options are always preserved.

When running on older version:
 - Honour the depth argument passed to the custom `inspect` function.
 - Disable color output, becase there is now way how to detect whether
   colors were enabled or disabled by the top-level caller.
2015-01-12 17:12:18 +01:00
Miroslav Bajtoš 9b759c95ac Include property value in the error message
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.
2015-01-12 17:12:18 +01:00
Clark Wang 973dd33d63 fix skipping async validator will always fail if condition is un-fulfilled
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>
2014-11-19 21:50:08 +08:00
Fabien Franzen a66e612c87 Fix multi-property validation definitions
Fixes #291, as introduced by me ...
https://github.com/strongloop/loopback-datasource-juggler/commit/6fae8c7
27759256157bf7ccd82e04ee372a59088
2014-09-05 18:00:11 +02:00
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