Skip to content

Commit

Permalink
Handle keys with empty values as present, not missing
Browse files Browse the repository at this point in the history
  • Loading branch information
Tully committed Jun 10, 2014
1 parent 0a609a5 commit 0a4fa0e
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 23 deletions.
5 changes: 3 additions & 2 deletions releases/latest/amanda.js
Expand Up @@ -1034,9 +1034,9 @@ var requiredAttribute = function required(property, propertyValue, attributeValu
if (attributeValue) {

var undefinedCondition = isUndefined(propertyValue);
var emptyCondition = (isString(propertyValue) || isArray(propertyValue) || isObject(propertyValue)) && isEmpty(propertyValue);
var nullCondition = isNull(propertyValue);

if (undefinedCondition || emptyCondition) {
if (undefinedCondition || nullCondition) {
this.addError();
}

Expand All @@ -1049,6 +1049,7 @@ var requiredAttribute = function required(property, propertyValue, attributeValu
// Export
Validation.prototype.addAttribute('required', requiredAttribute);


/**
* Type
*/
Expand Down
6 changes: 3 additions & 3 deletions src/engines/json/attributes/required.js
Expand Up @@ -6,9 +6,9 @@ var requiredAttribute = function required(property, propertyValue, attributeValu
if (attributeValue) {

var undefinedCondition = isUndefined(propertyValue);
var emptyCondition = (isString(propertyValue) || isArray(propertyValue) || isObject(propertyValue)) && isEmpty(propertyValue);
var nullCondition = isNull(propertyValue);

if (undefinedCondition || emptyCondition) {
if (undefinedCondition || nullCondition) {
this.addError();
}

Expand All @@ -19,4 +19,4 @@ var requiredAttribute = function required(property, propertyValue, attributeValu
};

// Export
Validation.prototype.addAttribute('required', requiredAttribute);
Validation.prototype.addAttribute('required', requiredAttribute);
22 changes: 4 additions & 18 deletions tests/json/attributes/required/required.js
Expand Up @@ -49,12 +49,8 @@ suite('JSON/Attribute/required#string', function() {
expect(error).to.be.ok();
});

jsonSchemaValidator.validate('', schema, function(error) {
count += 1;
expect(error).to.be.ok();
});

expect(count).to.be.eql(3);
expect(count).to.be.eql(2);

});

Expand Down Expand Up @@ -106,12 +102,7 @@ suite('JSON/Attribute/required#array', function() {
expect(error).to.be.ok();
});

jsonSchemaValidator.validate([], schema, function(error) {
count += 1;
expect(error).to.be.ok();
});

expect(count).to.be.eql(3);
expect(count).to.be.eql(2);

});

Expand Down Expand Up @@ -165,13 +156,8 @@ suite('JSON/Attribute/required#object', function() {
expect(error).to.be.ok();
});

jsonSchemaValidator.validate({}, schema, function(error) {
count += 1;
expect(error).to.be.ok();
});

expect(count).to.be.eql(3);
expect(count).to.be.eql(2);

});

});
});

0 comments on commit 0a4fa0e

Please sign in to comment.