Permalink
Browse files

Fixed error when using mixin and setting attributes on models without…

… validateion. Fixes #36
  • Loading branch information...
1 parent b1d8db4 commit 3efff48cef2262f37aed80304b28940cb253f522 @thedersen committed Jul 16, 2012
Showing with 12 additions and 2 deletions.
  1. +2 −2 backbone.validation.js
  2. +10 −0 tests/mixin.js
View
@@ -15,14 +15,14 @@ Backbone.Validation = (function(Backbone, _, undefined) {
};
var getValidatedAttrs = function(model){
- return _.reduce(_.keys(model.validation), function(memo, key){
+ return _.reduce(_.keys(model.validation || {}), function(memo, key){
memo[key] = undefined;
return memo;
}, {});
};
var getValidators = function(model, attr) {
- var attrValidation = model.validation[attr] || {};
+ var attrValidation = model.validation ? model.validation[attr] || {} : {};
if (_.isFunction(attrValidation)) {
return attrValidation;
View
@@ -65,5 +65,15 @@ buster.testCase("Mixin validation", {
"succeeds setting invalid value when forcing update globally": function() {
assert(this.model.set({name:''}));
}
+ },
+
+ "when setting attribute on model without validation": {
+ setUp: function(){
+ this.model = new Backbone.Model();
+ },
+
+ "it should not complain": function() {
+ assert(this.model.set({someAttr: 'someValue'}));
+ }
}
});

0 comments on commit 3efff48

Please sign in to comment.