adding test for falsy comparators (#1342)

This commit is contained in:
Sam Breed
2012-05-23 23:53:13 -06:00
parent 6d21c05b18
commit 98e01bbc4a
2 changed files with 14 additions and 1 deletions

View File

@@ -548,7 +548,7 @@
var Collection = Backbone.Collection = function(models, options) {
options || (options = {});
if (options.model) this.model = options.model;
if (typeof options.comparator !== 'undefined') this.comparator = options.comparator;
if (options.comparator !== undefined) this.comparator = options.comparator;
this._reset();
this.initialize.apply(this, arguments);
if (models) this.reset(models, {silent: true, parse: options.parse});

View File

@@ -599,4 +599,17 @@ $(document).ready(function() {
ok(!collection.get('undefined'));
});
test("Collection: falsy comparator", function(){
var Col = Backbone.Collection.extend({
comparator: function(model){ return model.id; }
});
var col = new Col([{id: 2}, {id: 1}], {
comparator: false
});
var otherCol = new Col([{id: 2}, {id: 1}]);
raises(function(){ col.sort() });
equal(col.first().id, 2);
equal(otherCol.first().id, 1);
});
});