diff --git a/src/backbone-validation.js b/src/backbone-validation.js index 8156b048..e4aa8de2 100644 --- a/src/backbone-validation.js +++ b/src/backbone-validation.js @@ -330,7 +330,7 @@ Backbone.Validation = (function(_){ // Removes view from associated views of the model or the methods // added to a model if no view or single view provided var unbindModel = function(model, view) { - if (view && model.associatedViews.length > 1){ + if (view && model.associatedViews && model.associatedViews.length > 1){ model.associatedViews = _.without(model.associatedViews, view); } else { delete model.validate; diff --git a/tests/general.js b/tests/general.js index a6ffe484..48435373 100644 --- a/tests/general.js +++ b/tests/general.js @@ -52,6 +52,13 @@ buster.testCase("Backbone.Validation", { } }, + "when unbinding view which was not bound": { + "nothing happens": function(){ + Backbone.Validation.unbind(new Backbone.View({model:new Backbone.Model()})); + assert(true); + } + }, + "when bound to model with two validated attributes": { setUp: function() { Backbone.Validation.bind(this.view);