Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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

… validateion. Fixes #36
  • Loading branch information...
commit 3efff48cef2262f37aed80304b28940cb253f522 1 parent b1d8db4
@thedersen authored
Showing with 12 additions and 2 deletions.
  1. +2 −2 backbone.validation.js
  2. +10 −0 tests/mixin.js
View
4 backbone.validation.js
@@ -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
10 tests/mixin.js
@@ -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'}));
+ }
}
});
Please sign in to comment.
Something went wrong with that request. Please try again.