From 8d8d0acb6d31d4d6e78d4049122dd5c0325ac9d6 Mon Sep 17 00:00:00 2001 From: akshaddhoke Date: Mon, 4 May 2015 17:29:10 -0500 Subject: [PATCH 1/3] Check for no associatedViews in unbindModel() Fix error when unbind is invoked on a view which has no associated views. Modified unbindModel() to check for a non empty list of model.associatedViews, before removing the view --- src/backbone-validation.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/backbone-validation.js b/src/backbone-validation.js index c024db40..0c0e668b 100644 --- a/src/backbone-validation.js +++ b/src/backbone-validation.js @@ -325,7 +325,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 && !_.isEmpty(model.associatedViews)){ model.associatedViews = _.without(model.associatedViews, view); } else { delete model.validate; From fae1c2b00598c3c3a6849409bcdf84f51608a4d4 Mon Sep 17 00:00:00 2001 From: Akshad Dhoke Date: Thu, 7 May 2015 23:30:12 -0500 Subject: [PATCH 2/3] changed from _.isEmpty(model.associatedViews) to model.associatedViews && model.associatedViews.length > 1 --- src/backbone-validation.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/backbone-validation.js b/src/backbone-validation.js index 0c0e668b..1bc83df3 100644 --- a/src/backbone-validation.js +++ b/src/backbone-validation.js @@ -325,7 +325,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 && !_.isEmpty(model.associatedViews)){ + if (view && model.associatedViews && model.associatedViews.length > 1){ model.associatedViews = _.without(model.associatedViews, view); } else { delete model.validate; From 0a3fb4981b0dafc7b154c672316c2454fbb34123 Mon Sep 17 00:00:00 2001 From: Akshad Dhoke Date: Fri, 8 May 2015 01:42:34 -0500 Subject: [PATCH 3/3] Added test case for unbinding view that was not bound --- tests/general.js | 7 +++++++ 1 file changed, 7 insertions(+) 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);