Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Add a fix for failing tests #6

Merged
merged 1 commit into from

2 participants

@domharrington

The last pull request broke some tests in Catfish due to schemata attempting to iterate over and validate falsy and empty array values.

This has now been fixed and tested directly against Catfish using npm link.

@serby serby merged commit a51b0fb into serby:master

1 check passed

Details default The Travis build passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 26, 2013
  1. @domharrington
This page is out of date. Refresh to see the latest.
Showing with 25 additions and 1 deletion.
  1. +5 −1 lib/schemata.js
  2. +20 −0 test/schemata.test.js
View
6 lib/schemata.js
@@ -310,7 +310,11 @@ module.exports = function(schema) {
}
, function(seriesCallback) {
// This property has an array subschema that needs validating
- if ((typeof property.type !== 'undefined') && (typeof property.type.arraySchema !== 'undefined')) {
+ if ((typeof property.type !== 'undefined')
+ && (typeof property.type.arraySchema !== 'undefined')
+ && entityObject[key]
+ && entityObject[key].length > 0) {
+
var index = 0
async.forEach(entityObject[key], function (i, next) {
View
20 test/schemata.test.js
@@ -2,6 +2,7 @@ var schemata = require('..')
, validity = require('validity')
, propertyValidator = require('validity/property-validator')
, should = require('should')
+ , async = require('async')
function createContactSchema() {
var schema = schemata({
@@ -558,7 +559,26 @@ describe('schemata', function() {
done()
})
+ })
+
+ it('does not try and validate array sub-schemas that are falsy or []', function (done) {
+ var schema = createBlogSchema()
+ , model = schema.makeBlank()
+ , testValues = [undefined, null, '', 0, []]
+ , subSchema = schema.schema.comments.type.arraySchema.schema
+ subSchema.email.validators = {
+ all: [validity.required]
+ }
+
+ async.forEach(testValues, function (value, next) {
+ model.comments = value
+
+ schema.validate(model, function (error, errors) {
+ errors.should.eql({})
+ next()
+ })
+ }, done)
})
it('allows error response to be a string instead of Error object', function(done) {
Something went wrong with that request. Please try again.