Permalink
Browse files

Fix ‘Amanda 0.4.3 breaks validation of 'falsey' values’

  • Loading branch information...
1 parent 78cc1b1 commit 6368366958471be7657ae34f25767409a0d5ebd4 @Baggz committed Mar 1, 2013
Showing with 40 additions and 4 deletions.
  1. +2 −2 src/engines/json/getProperty.js
  2. +38 −2 tests/json/attributes/type/boolean.js
@@ -1,12 +1,12 @@
/**
* GetProperty
*
- * @param {string} property
+ * @param {string} property
* @param {object} source
*/
Validation.prototype.getProperty = function(property, source) {
if (source) {
- return (source[property] !== undefined) ? source[property] : undefined;
+ return (isDefined(source[property])) ? source[property] : undefined;
} else {
return undefined;
}
@@ -19,11 +19,20 @@ suite('JSON/Attribute/type#boolean', function() {
};
/**
+ * Schema
+ */
+ var schemaWithRequired = {
+ required: true,
+ type: 'boolean'
+ };
+
+ /**
* Validator
*/
var Validator = amanda('json');
test('should not return an error', function() {
+
[
true,
false
@@ -33,9 +42,21 @@ suite('JSON/Attribute/type#boolean', function() {
expect(error).to.not.be.ok();
});
});
+
+ [
+ true,
+ false
+ ].forEach(function(instance) {
+ Validator.validate(instance, schemaWithRequired, function(error) {
+ count += 1;
+ expect(error).to.not.be.ok();
+ });
+ });
+
});
test('should return an error', function() {
+
[
'Hello',
123,
@@ -48,10 +69,25 @@ suite('JSON/Attribute/type#boolean', function() {
expect(error).to.be.ok();
});
});
+
+ [
+ undefined,
+ 'Hello',
+ 123,
+ {},
+ [],
+ function() {}
+ ].forEach(function(instance) {
+ Validator.validate(instance, schemaWithRequired, function(error) {
+ count += 1;
+ expect(error).to.be.ok();
+ });
+ });
+
});
- test('should run 7 times', function() {
- expect(count).to.be.eql(7);
+ test('should run 15 times', function() {
+ expect(count).to.be.eql(15);
});
});

0 comments on commit 6368366

Please sign in to comment.