Skip to content

Commit f814b85

Browse files
committed
Make new tests more thorough
1 parent 3f7fbde commit f814b85

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

test/collection.js

+10-5
Original file line numberDiff line numberDiff line change
@@ -1379,8 +1379,8 @@
13791379
});
13801380

13811381
test('Polymorphic models work with "advanced" constructors', function () {
1382-
var A = Backbone.Model.extend();
1383-
var B = Backbone.Model.extend();
1382+
var A = Backbone.Model.extend({idAttribute: '_id'});
1383+
var B = Backbone.Model.extend({idAttribute: '_id'});
13841384
var C = Backbone.Collection.extend({
13851385
model: Backbone.Model.extend({
13861386
constructor: function (attrs) {
@@ -1393,22 +1393,27 @@
13931393
var collection = new C([{_id: 1, type: 'a'}, {_id: 2, type: 'b'}]);
13941394
equal(collection.length, 2);
13951395
ok(collection.at(0) instanceof A);
1396+
equal(collection.at(0).id, 1);
13961397
ok(collection.at(1) instanceof B);
1398+
equal(collection.at(1).id, 2);
13971399

1400+
A.prototype.generateId = B.prototype.generateId = function (attrs) {
1401+
return attrs.type + '-' + attrs.id;
1402+
}
13981403
C = Backbone.Collection.extend({
13991404
model: Backbone.Model.extend({
14001405
constructor: function (attrs) {
14011406
return attrs.type === 'a' ? new A(attrs) : new B(attrs);
14021407
},
14031408

1404-
generateId: function (attrs) {
1405-
return attrs.type + '-' + attrs.id;
1406-
}
1409+
generateId: A.prototype.generateId
14071410
})
14081411
});
14091412
collection = new C([{id: 1, type: 'a'}, {id: 1, type: 'b'}]);
14101413
equal(collection.length, 2);
14111414
ok(collection.at(0) instanceof A);
1415+
equal(collection.at(0).id, 'a-1');
14121416
ok(collection.at(1) instanceof B);
1417+
equal(collection.at(1).id, 'b-1');
14131418
});
14141419
})();

0 commit comments

Comments
 (0)