diff --git a/backbone.js b/backbone.js index 62e66769..2a0deb94 100644 --- a/backbone.js +++ b/backbone.js @@ -215,9 +215,7 @@ // Remove the attribute. delete this.attributes[attr]; delete this._escapedAttributes[attr]; - if (attr == 'id') { - delete this.id; - } + if (attr == 'id') delete this.id; this._changed = true; if (!options.silent) { this.trigger('change:' + attr, this, void 0, options); diff --git a/test/model.js b/test/model.js index 2070bb25..ab62cd5e 100644 --- a/test/model.js +++ b/test/model.js @@ -133,7 +133,7 @@ $(document).ready(function() { }); test("Model: set and unset", function() { - attrs = { 'foo': 1, 'bar': 2, 'baz': 3}; + attrs = {id: 'id', foo: 1, bar: 2, baz: 3}; a = new Backbone.Model(attrs); var changeCount = 0; a.bind("change:foo", function() { changeCount += 1; }); @@ -147,6 +147,9 @@ $(document).ready(function() { a.unset('foo'); ok(a.get('foo')== null, "Foo should have changed"); ok(changeCount == 2, "Change count should have incremented for unset."); + + a.unset('id'); + equals(a.id, undefined, "Unsetting the id should remove the id property."); }); test("Model: set an empty string", function() { @@ -322,7 +325,7 @@ $(document).ready(function() { equals(lastError, "Can't change admin status."); equals(boundError, undefined); }); - + test("Model: Inherit class properties", function() { var Parent = Backbone.Model.extend({ instancePropSame: function() {}, @@ -333,7 +336,7 @@ $(document).ready(function() { var Child = Parent.extend({ instancePropDiff: function() {} }); - + var adult = new Parent; var kid = new Child;