Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Add support for conform function used in resourceful #9

Merged
merged 1 commit into from

2 participants

@colinf

See issue 49 in resourceful.

@indexzero
Owner

lgtm

@indexzero indexzero merged commit ba7a8b4 into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Feb 7, 2012
  1. @colinf
This page is out of date. Refresh to see the latest.
Showing with 15 additions and 1 deletion.
  1. +2 −0  lib/revalidator.js
  2. +13 −1 test/validator-test.js
View
2  lib/revalidator.js
@@ -244,6 +244,8 @@
checkType(value, schema.type, function(err, type) {
if (err) return error('type', property, typeof value, schema, errors);
+ constrain('conform', value, function (a, e) { return e(a) });
+
switch (type || (isArray(value) ? 'array' : typeof value)) {
case 'string':
constrain('minLength', value.length, function (a, e) { return a >= e });
View
14 test/validator-test.js
@@ -186,7 +186,10 @@ vows.describe('revalidator', {
},
author: { type: 'string', pattern: /^[\w ]+$/i, required: true},
published: { type: 'boolean', 'default': false },
- category: { type: 'string' }
+ category: { type: 'string' },
+ palindrome: {type: 'string', conform: function(val) {
+ return val == val.split("").reverse().join(""); }
+ }
},
patternProperties: {
'^_': {
@@ -203,6 +206,7 @@ vows.describe('revalidator', {
author: 'cloudhead',
published: true,
category: 'misc',
+ palindrome: 'dennis sinned',
_flag: true
},
"can be validated with `revalidator.validate`": {
@@ -273,6 +277,14 @@ vows.describe('revalidator', {
},
"return an object with `valid` set to false": assertInvalid
},
+ "and if it is not a palindrome (conform function)": {
+ topic: function (object, schema) {
+ object = clone(object);
+ object.palindrome = 'bad palindrome';
+ return revalidator.validate(object, schema);
+ },
+ "return an object with `valid` set to false": assertInvalid
+ },
"and if it didn't validate a pattern": {
topic: function (object, schema) {
object = clone(object);
Something went wrong with that request. Please try again.