From 50ce2192769257e3dbc0b7d124fdb0fdee9c0d63 Mon Sep 17 00:00:00 2001 From: Vail Gold Date: Wed, 16 Jan 2013 09:17:50 -0500 Subject: [PATCH 1/2] Added ability to refer to object in custom conform function and associated tests. --- lib/revalidator.js | 4 ++-- test/validator-test.js | 12 ++++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/lib/revalidator.js b/lib/revalidator.js index 1faa25f..fba47c3 100644 --- a/lib/revalidator.js +++ b/lib/revalidator.js @@ -224,7 +224,7 @@ type; function constrain(name, value, assert) { - if (schema[name] !== undefined && !assert(value, schema[name])) { + if (schema[name] !== undefined && !assert(value, schema[name], object)) { error(name, property, value, schema, errors); } } @@ -295,7 +295,7 @@ 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) }); + constrain('conform', value, function (a, e, o) { return e(a, o) }); switch (type || (isArray(value) ? 'array' : typeof value)) { case 'string': diff --git a/test/validator-test.js b/test/validator-test.js index 0d2590d..435a709 100644 --- a/test/validator-test.js +++ b/test/validator-test.js @@ -231,6 +231,9 @@ vows.describe('revalidator', { category: { type: 'string' }, palindrome: {type: 'string', conform: function(val) { return val == val.split("").reverse().join(""); } + }, + sameAsTitle: {conform: function(val, obj) { + return val == obj.title; } } }, patternProperties: { @@ -250,6 +253,7 @@ vows.describe('revalidator', { published: true, category: 'misc', palindrome: 'dennis sinned', + sameAsTitle: 'Gimme some Gurus', _flag: true }, "can be validated with `revalidator.validate`": { @@ -330,6 +334,14 @@ vows.describe('revalidator', { }, "return an object with `valid` set to false": assertInvalid }, + "and if it didn't validate a custom conform referring to another value in the object": { + topic: function (object, schema) { + object = clone(object); + object.sameAsTitle = 'Not the same as the title'; + 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); From 410ebb419d60f4e8c3d5989a1871731b51e2b347 Mon Sep 17 00:00:00 2001 From: Vail Gold Date: Thu, 17 Jan 2013 12:11:53 -0500 Subject: [PATCH 2/2] Added Node version 0.8 to Travis. --- .gitignore | 3 ++- .travis.yml | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 5171c54..b0e3907 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ node_modules -npm-debug.log \ No newline at end of file +npm-debug.log +.DS_Store diff --git a/.travis.yml b/.travis.yml index c958222..368f52f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,6 +3,7 @@ node_js: - 0.4 - 0.6 - 0.7 + - 0.8 notifications: email: