[Pkg-javascript-commits] [backbone] 125/281: Fixes #788

Jonas Smedegaard js at moszumanska.debian.org
Sat May 3 17:02:03 UTC 2014


This is an automated email from the git hooks/post-receive script.

js pushed a commit to tag 0.9.0
in repository backbone.

commit dd83f2057c504df243bcc5a39cb4c5a887bdce6a
Author: Jeremy Ashkenas <jashkenas at gmail.com>
Date:   Mon Dec 19 11:20:25 2011 -0500

    Fixes #788
---
 backbone.js        |  1 +
 test/collection.js | 32 ++++++++++++++++++++------------
 2 files changed, 21 insertions(+), 12 deletions(-)

diff --git a/backbone.js b/backbone.js
index 1e8f506..eafa08a 100644
--- a/backbone.js
+++ b/backbone.js
@@ -414,6 +414,7 @@
     add : function(models, options) {
       if (_.isArray(models)) {
         for (var i = 0, l = models.length; i < l; i++) {
+          if (options && (options.at == +options.at) && i) options.at += 1;
           this._add(models[i], options);
         }
       } else {
diff --git a/test/collection.js b/test/collection.js
index 005b044..61e2b87 100644
--- a/test/collection.js
+++ b/test/collection.js
@@ -122,20 +122,28 @@ $(document).ready(function() {
     equals(atCol.last(), h);
   });
 
+  test("Collection: add multiple models", function() {
+    var col = new Backbone.Collection([{at: 0}, {at: 1}, {at: 9}]);
+    col.add([{at: 2}, {at: 3}, {at: 4}, {at: 5}, {at: 6}, {at: 7}, {at: 8}], {at: 2});
+    for (var i = 0; i <= 5; i++) {
+      equals(col.at(i).get('at'), i);
+    }
+  });
+
   test("Collection: add model to collection and verify index updates", function() {
     var f = new Backbone.Model({id: 20, label : 'f'});
     var g = new Backbone.Model({id: 21, label : 'g'});
     var h = new Backbone.Model({id: 22, label : 'h'});
     var col = new Backbone.Collection();
-    
+
     var counts = [];
-     
+
     col.bind('add', function(model, collection, options) {
-      counts.push(options.index);  
+      counts.push(options.index);
     });
-    col.add(f); 
-    col.add(g); 
-    col.add(h); 
+    col.add(f);
+    col.add(g);
+    col.add(h);
     ok(_.isEqual(counts, [0,1,2]));
   });
 
@@ -209,15 +217,15 @@ $(document).ready(function() {
     var g = new Backbone.Model({id: 21, label : 'g'});
     var h = new Backbone.Model({id: 22, label : 'h'});
     var col = new Backbone.Collection([f,g,h]);
-    
+
     var counts = [];
-     
+
     col.bind('remove', function(model, collection, options) {
-      counts.push(options.index);  
+      counts.push(options.index);
     });
-    col.remove(h); 
-    col.remove(g); 
-    col.remove(f); 
+    col.remove(h);
+    col.remove(g);
+    col.remove(f);
     ok(_.isEqual(counts, [2,1,0]));
   });
 

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/backbone.git



More information about the Pkg-javascript-commits mailing list