mirror of
https://github.com/jashkenas/backbone.git
synced 2026-04-30 03:00:06 -04:00
Merge pull request #700 from iros/673
#673 - Adding index as a property on the options object that gets passed
This commit is contained in:
@@ -122,6 +122,23 @@ $(document).ready(function() {
|
||||
equals(atCol.last(), h);
|
||||
});
|
||||
|
||||
test("Collection: add model to collection and verify index updates", function() {
|
||||
var f = new Backbone.Model({id: 20, label : 'f'});
|
||||
var g = new Backbone.Model({id: 21, label : 'g'});
|
||||
var h = new Backbone.Model({id: 22, label : 'h'});
|
||||
var col = new Backbone.Collection();
|
||||
|
||||
var counts = [];
|
||||
|
||||
col.bind('add', function(model, collection, options) {
|
||||
counts.push(options.index);
|
||||
});
|
||||
col.add(f);
|
||||
col.add(g);
|
||||
col.add(h);
|
||||
ok(_.isEqual(counts, [0,1,2]));
|
||||
});
|
||||
|
||||
test("Collection: add model to collection twice", function() {
|
||||
try {
|
||||
// no id, same cid
|
||||
@@ -173,6 +190,23 @@ $(document).ready(function() {
|
||||
equals(otherRemoved, null);
|
||||
});
|
||||
|
||||
test("Collection: remove should return correct index events", function() {
|
||||
var f = new Backbone.Model({id: 20, label : 'f'});
|
||||
var g = new Backbone.Model({id: 21, label : 'g'});
|
||||
var h = new Backbone.Model({id: 22, label : 'h'});
|
||||
var col = new Backbone.Collection([f,g,h]);
|
||||
|
||||
var counts = [];
|
||||
|
||||
col.bind('remove', function(model, collection, options) {
|
||||
counts.push(options.index);
|
||||
});
|
||||
col.remove(h);
|
||||
col.remove(g);
|
||||
col.remove(f);
|
||||
ok(_.isEqual(counts, [2,1,0]));
|
||||
});
|
||||
|
||||
test("Collection: events are unbound on remove", function() {
|
||||
var counter = 0;
|
||||
var dj = new Backbone.Model();
|
||||
|
||||
Reference in New Issue
Block a user