mirror of
https://github.com/jashkenas/backbone.git
synced 2026-01-23 22:08:04 -05:00
Issue #209 ... unsetting a missing attribute should not fire a change event.
This commit is contained in:
@@ -206,8 +206,9 @@
|
||||
},
|
||||
|
||||
// Remove an attribute from the model, firing `"change"` unless you choose
|
||||
// to silence it.
|
||||
// to silence it. `unset` is a noop if the attribute doesn't exist.
|
||||
unset : function(attr, options) {
|
||||
if (!(attr in this.attributes)) return this;
|
||||
options || (options = {});
|
||||
var value = this.attributes[attr];
|
||||
|
||||
|
||||
@@ -152,6 +152,17 @@ $(document).ready(function() {
|
||||
equals(a.id, undefined, "Unsetting the id should remove the id property.");
|
||||
});
|
||||
|
||||
test("Model: multiple unsets", function() {
|
||||
var i = 0;
|
||||
var counter = function(){ i++; };
|
||||
var model = new Backbone.Model({a: 1});
|
||||
model.bind("change:a", counter);
|
||||
model.set({a: 2});
|
||||
model.unset('a');
|
||||
model.unset('a');
|
||||
equals(i, 2, 'Unset does not fire an event for missing attributes.');
|
||||
});
|
||||
|
||||
test("Model: using a non-default id attribute.", function() {
|
||||
var MongoModel = Backbone.Model.extend({idAttribute : '_id'});
|
||||
var model = new MongoModel({id: 'eye-dee', _id: 25, title: 'Model'});
|
||||
|
||||
Reference in New Issue
Block a user