[Pkg-javascript-commits] [backbone] 75/211: ditto

Jonas Smedegaard js at moszumanska.debian.org
Sat May 3 17:00:04 UTC 2014


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

js pushed a commit to tag 0.5.0
in repository backbone.

commit c6d2c69d8253de25c079215e069cbfda8c160f52
Author: Jeremy Ashkenas <jashkenas at gmail.com>
Date:   Mon Feb 7 14:49:56 2011 -0500

    ditto
---
 backbone.js        |  2 +-
 test/collection.js | 20 ++++++++++++++++----
 2 files changed, 17 insertions(+), 5 deletions(-)

diff --git a/backbone.js b/backbone.js
index 44d94d3..2341c17 100644
--- a/backbone.js
+++ b/backbone.js
@@ -606,7 +606,7 @@
       if (ev == 'destroy') {
         this._remove(model, options);
       }
-      if (ev === 'change:id') {
+      if (ev === 'change:' + model.idAttribute) {
         delete this._byId[model.previous(model.idAttribute)];
         this._byId[model.id] = model;
       }
diff --git a/test/collection.js b/test/collection.js
index ba93619..e620e13 100644
--- a/test/collection.js
+++ b/test/collection.js
@@ -32,6 +32,18 @@ $(document).ready(function() {
     equals(col.getByCid(col.first().cid), col.first());
   });
 
+  test("Collection: get with non-default ids", function() {
+    var col = new Backbone.Collection();
+    var MongoModel = Backbone.Model.extend({
+      idAttribute: '_id'
+    });
+    var model = new MongoModel({_id: 100});
+    col.add(model);
+    equals(col.get(100), model);
+    model.set({_id: 101});
+    equals(col.get(101), model);
+  });
+
   test("Collection: update index when id changes", function() {
     var col = new Backbone.Collection();
     col.add([
@@ -210,12 +222,12 @@ $(document).ready(function() {
 
   test("Collection: create enforces validation", function() {
     var ValidatingModel = Backbone.Model.extend({
-        validate: function(attrs) {
-                return "fail"
-        }
+      validate: function(attrs) {
+        return "fail";
+      }
     });
     var ValidatingCollection = Backbone.Collection.extend({
-        model: ValidatingModel
+      model: ValidatingModel
     });
     var col = new ValidatingCollection();
     equals(col.create({"foo":"bar"}),false);

-- 
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