From 98e01bbc4ad2a0cee44198699de73c898ab4e069 Mon Sep 17 00:00:00 2001 From: Sam Breed Date: Wed, 23 May 2012 23:53:13 -0600 Subject: [PATCH] adding test for falsy comparators (#1342) --- backbone.js | 2 +- test/collection.js | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/backbone.js b/backbone.js index 08c668af..06a49dd0 100644 --- a/backbone.js +++ b/backbone.js @@ -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}); diff --git a/test/collection.js b/test/collection.js index ceb8e60a..530a1785 100644 --- a/test/collection.js +++ b/test/collection.js @@ -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); + }); + });