Merge pull request #1896 from braddunbar/push-sort

Fix #1894, Collection#push should not sort.
This commit is contained in:
Jeremy Ashkenas
2012-12-11 07:26:56 -08:00
2 changed files with 11 additions and 1 deletions

View File

@@ -730,7 +730,7 @@
// Add a model to the end of the collection.
push: function(model, options) {
model = this._prepareModel(model, options);
this.add(model, options);
this.add(model, _.extend({at: this.length}, options));
return model;
},

View File

@@ -828,4 +828,14 @@ $(document).ready(function() {
strictEqual(c.length, 0);
});
test("#1894 - Push should not trigger a sort", 0, function() {
var Collection = Backbone.Collection.extend({
comparator: 'id',
sort: function() {
ok(false);
}
});
new Collection().push({id: 1});
});
});