Add a test and tweak whitespace for #1448.

This commit is contained in:
Brad Dunbar
2012-06-25 08:33:27 -04:00
parent 6a8232a36e
commit c18b7763f8
2 changed files with 13 additions and 2 deletions

View File

@@ -624,7 +624,6 @@
this.length += length;
index = options.at != null ? options.at : this.models.length;
splice.apply(this.models, [index, 0].concat(models));
// Merge in duplicate models.
if (options.merge) {
@@ -634,7 +633,9 @@
}
}
}
if (this.comparator && options.at == null) this.sort({silent: true});
// Sort the collection if appropriate.
if (this.comparator && options.at == null) this.sort({silent: true});
if (options.silent) return this;
for (i = 0, length = this.models.length; i < length; i++) {

View File

@@ -656,4 +656,14 @@ $(document).ready(function() {
collection.on('add', function(){ ok(true); });
collection.create(model, {wait: true});
});
test("#1448 - add sorts collection after merge.", function() {
var collection = new Backbone.Collection([
{id: 1, x: 1},
{id: 2, x: 2}
]);
collection.comparator = function(model){ return model.get('x'); };
collection.add({id: 1, x: 3}, {merge: true});
deepEqual(collection.pluck('id'), [2, 1]);
});
});