forked from canjs/canjs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodel_test.js
985 lines (797 loc) · 20.7 KB
/
model_test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
(function() {
module("can/model", {
setup: function() {
}
})
var isDojo = (typeof dojo !== "undefined");
var getPath = function(path) {
if(typeof steal !== 'undefined') {
return steal.config().root.join(path) + '';
}
return path;
}
test("shadowed id", function(){
var MyModel = can.Model({
id: 'foo'
},{
foo: function() {
return this.attr('foo');
}
});
var newModel = new MyModel({});
ok(newModel.isNew(),'new model is isNew');
var oldModel = new MyModel({foo:'bar'});
ok(!oldModel.isNew(),'old model is not new');
equals(oldModel.foo(),'bar','method can coexist with attribute');
});
test("findAll deferred", function(){
can.Model("Person",{
findAll : function(params, success, error){
var self= this;
return can.ajax({
url : "/people",
data : params,
fixture: "//can/model/test/people.json",
dataType : "json"
}).pipe(function(data){
return self.models(data);
});
}
},{});
stop();
var people = Person.findAll({});
people.then(function(people){
equals(people.length, 1, "we got a person back");
equals(people[0].name, "Justin", "Got a name back");
equals(people[0].constructor.shortName, "Person", "got a class back");
start();
})
});
asyncTest("findAll deferred reject", function() {
// This test is automatically paused
function rejectDeferred(df) {
setTimeout(function() { df.reject(); }, 100);
}
function resolveDeferred(df) {
setTimeout(function() { df.resolve(); }, 100);
}
can.Model("Person", {
findAll : function(params, success, error) {
var df = can.Deferred();
if(params.resolve) {
resolveDeferred(df);
} else {
rejectDeferred(df);
}
return df;
}
},{});
var people_reject = Person.findAll({ resolve : false});
var people_resolve = Person.findAll({ resolve : true});
setTimeout(function() {
people_reject.done(function() {
ok(false, "This deferred should be rejected");
});
people_reject.fail(function() {
ok(true, "The deferred is rejected");
});
people_resolve.done(function() {
ok(true, "This deferred is resolved");
});
people_resolve.fail(function() {
ok(false, "The deferred should be resolved");
});
// continue the test
start();
}, 200);
});
if(window.jQuery) {
asyncTest("findAll abort", function() {
expect(4);
var df;
can.Model("Person", {
findAll : function(params, success, error) {
df = can.Deferred();
df.then(function() {
ok(!params.abort,'not aborted');
},function() {
ok(params.abort,'aborted');
});
return df.promise({
abort: function() {
df.reject();
}
});
}
},{});
var resolvePromise = Person.findAll({ abort : false}).done(function() {
ok(true,'resolved');
});
var resolveDf = df;
var abortPromise = Person.findAll({ abort : true}).fail(function() {
ok(true,'failed');
});
setTimeout(function() {
resolveDf.resolve();
abortPromise.abort();
// continue the test
start();
}, 200);
});
}
test("findOne deferred", function(){
if(window.jQuery){
can.Model("Person",{
findOne : function(params, success, error){
var self = this;
return can.ajax({
url : "/people/5",
data : params,
fixture: "//can/model/test/person.json",
dataType : "json"
}).pipe(function(data){
return self.model(data);
});
}
},{});
} else {
can.Model("Person",{
findOne : getPath("can/model/test/person.json")
},{});
}
stop();
var person = Person.findOne({});
person.then(function(person){
equals(person.name, "Justin", "Got a name back");
equals(person.constructor.shortName, "Person", "got a class back");
start();
})
});
test("save deferred", function(){
can.Model("Person",{
create : function(attrs, success, error){
return can.ajax({
url : "/people",
data : attrs,
type : 'post',
dataType : "json",
fixture: function(){
return {id: 5}
},
success : success
})
}
},{});
var person = new Person({name: "Justin"}),
personD = person.save();
stop();
personD.then(function(person){
start()
equals(person.id, 5, "we got an id")
});
});
test("update deferred", function(){
can.Model("Person",{
update : function(id, attrs, success, error){
return can.ajax({
url : "/people/"+id,
data : attrs,
type : 'post',
dataType : "json",
fixture: function(){
return {thing: "er"}
},
success : success
})
}
},{});
var person = new Person({name: "Justin", id:5}),
personD = person.save();
stop();
personD.then(function(person){
start()
equals(person.thing, "er", "we got updated")
});
});
test("destroy deferred", function(){
can.Model("Person",{
destroy : function(id, success, error){
return can.ajax({
url : "/people/"+id,
type : 'post',
dataType : "json",
fixture: function(){
return {thing: "er"}
},
success : success
})
}
},{});
var person = new Person({name: "Justin", id:5}),
personD = person.destroy();
stop();
personD.then(function(person){
start()
equals(person.thing, "er", "we got destroyed")
});
});
test("models", function(){
can.Model("Person",{
prettyName : function(){
return "Mr. "+this.name;
}
})
var people = Person.models([
{id: 1, name: "Justin"}
])
equals(people[0].prettyName(),"Mr. Justin","wraps wrapping works")
});
test(".models with custom id", function() {
can.Model("CustomId", {
findAll : getPath("can/model/test") + "/customids.json",
id : '_id'
}, {
getName : function() {
return this.name;
}
});
stop();
CustomId.findAll().done(function(results) {
equals(results.length, 2, 'Got two items back');
equals(results[0].name, 'Justin', 'First name right');
equals(results[1].name, 'Brian', 'Second name right');
start();
});
});
/*
test("async setters", function(){
can.Model("Test.AsyncModel",{
setName : function(newVal, success, error){
setTimeout(function(){
success(newVal)
}, 100)
}
});
var model = new Test.AsyncModel({
name : "justin"
});
equals(model.name, "justin","property set right away")
//makes model think it is no longer new
model.id = 1;
var count = 0;
model.bind('name', function(ev, newName){
equals(newName, "Brian",'new name');
equals(++count, 1, "called once");
ok(new Date() - now > 0, "time passed")
start();
})
var now = new Date();
model.attr('name',"Brian");
stop();
})*/
test("binding", 2,function(){
can.Model('Person')
var inst = new Person({foo: "bar"});
inst.bind("foo", function(ev, val){
ok(true,"updated")
equals(val, "baz", "values match")
});
inst.attr("foo","baz");
});
test("auto methods",function(){
//turn off fixtures
can.fixture.on = false;
var School = can.Model.extend("Jquery.Model.Models.School",{
findAll : getPath("can/model/test")+"/{type}.json",
findOne : getPath("can/model/test")+"/{id}.json",
create : "GET " + getPath("can/model/test")+"/create.json",
update : "GET "+ getPath("can/model/test")+"/update{id}.json"
},{})
stop();
School.findAll({type:"schools"}, function(schools){
ok(schools,"findAll Got some data back");
equals(schools[0].constructor.shortName,"School","there are schools")
School.findOne({id : "4"}, function(school){
ok(school,"findOne Got some data back");
equals(school.constructor.shortName,"School","a single school");
new School({name: "Highland"}).save(function(school){
equals(school.name,"Highland","create gets the right name")
school.attr({name: "LHS"}).save( function(){
start();
equals(school.name,"LHS","create gets the right name")
can.fixture.on = true;
})
})
})
})
})
test("isNew", function(){
var p = new Person();
ok(p.isNew(), "nothing provided is new");
var p2 = new Person({id: null})
ok(p2.isNew(), "null id is new");
var p3 = new Person({id: 0})
ok(!p3.isNew(), "0 is not new");
});
test("findAll string", function(){
can.fixture.on = false;
can.Model("Test.Thing",{
findAll : getPath("can/model/test/findAll.json")+''
},{});
stop();
Test.Thing.findAll({},function(things){
equals(things.length, 1, "got an array");
equals(things[0].id, 1, "an array of things");
start();
can.fixture.on = true;
})
})
/*
test("Empty uses fixtures", function(){
ok(false, "Figure out")
return;
can.Model("Test.Things");
$.fixture.make("thing", 10, function(i){
return {
id: i
}
});
stop();
Test.Thing.findAll({}, function(things){
start();
equals(things.length, 10,"got 10 things")
})
});*/
test("Model events" , function(){
var order = 0;
can.Model("Test.Event",{
create : function(attrs){
var def = isDojo ? new dojo.Deferred() : new can.Deferred();
def.resolve({id: 1})
return def;
},
update : function(id, attrs, success){
var def = isDojo ? new dojo.Deferred() : new can.Deferred();
def.resolve(attrs)
return def;
},
destroy : function(id, success){
var def = isDojo ? new dojo.Deferred() : new can.Deferred();
def.resolve({})
return def;
}
},{});
stop();
Test.Event.bind('created',function(ev, passedItem){
ok(this === Test.Event, "got model")
ok(passedItem === item, "got instance")
equals(++order, 1, "order");
passedItem.save();
}).bind('updated', function(ev, passedItem){
equals(++order, 2, "order");
ok(this === Test.Event, "got model")
ok(passedItem === item, "got instance")
passedItem.destroy();
}).bind('destroyed', function(ev, passedItem){
equals(++order, 3, "order");
ok(this === Test.Event, "got model")
ok(passedItem === item, "got instance")
start();
})
var item = new Test.Event();
item.save();
});
test("removeAttr test", function(){
can.Model("Person");
var person = new Person({foo: "bar"})
equals(person.foo, "bar", "property set");
person.removeAttr('foo')
equals(person.foo, undefined, "property removed");
var attrs = person.attr()
equals(attrs.foo, undefined, "attrs removed");
});
test("save error args", function(){
var Foo = can.Model('Testin.Models.Foo',{
create : "/testinmodelsfoos.json"
},{
})
var st = '{type: "unauthorized"}';
can.fixture("/testinmodelsfoos.json", function(request, response){
response(401,st)
});
stop();
var inst = new Foo({}).save(function(){
ok(false, "success should not be called")
start()
}, function(jQXHR){
ok(true, "error called")
ok(jQXHR.getResponseHeader,"jQXHR object")
start()
})
});
test("object definitions", function(){
can.Model('ObjectDef',{
findAll : {
url : "/test/place",
dataType: "json"
},
findOne : {
url : "/objectdef/{id}",
timeout : 1000
},
create : {
},
update : {
},
destroy : {
}
},{})
can.fixture("GET /objectdef/{id}", function(original){
equals(original.timeout,1000,"timeout set");
return {yes: true}
});
can.fixture("GET /test/place", function(original){
return [original.data];
});
stop();
ObjectDef.findOne({id: 5}, function(){
start();
})
stop();
// Do find all, pass some attrs
ObjectDef.findAll({ start: 0, count: 10, myflag: 1}, function(data){
start();
equals(data[0].myflag, 1, 'my flag set')
});
stop();
// Do find all with slightly different attrs than before,
// and notice when leaving one out the other is still there
ObjectDef.findAll({ start: 0, count: 10 }, function(data){
start();
console.log("DATA IS", data)
equals(data[0].myflag, undefined, 'my flag is undefined')
});
})
test('aborting create update and destroy', function(){
stop();
var delay = can.fixture.delay;
can.fixture.delay = 1000;
can.fixture("POST /abort", function(){
ok(false, "we should not be calling the fixture");
return {};
})
can.Model('Abortion',{
create : "POST /abort",
update : "POST /abort",
destroy: "POST /abort"
},{});
var deferred = new Abortion({name: "foo"}).save(function(){
ok(false, "success create");
start();
}, function(){
ok(true, "create error called");
deferred = new Abortion({name: "foo",id: 5})
.save(function(){
ok(false,"save called")
start();
},function(){
ok(true, "error called in update")
deferred = new Abortion({name: "foo",id: 5}).destroy(function(){},
function(){
ok(true,"destroy error called")
can.fixture.delay = delay;
start();
})
setTimeout(function(){
deferred.abort();
},10)
})
setTimeout(function(){
deferred.abort();
},10)
});
setTimeout(function(){
deferred.abort();
},10)
});
test("store binding", function(){
can.Model("Storage");
var s = new Storage({
id: 1,
thing : {foo: "bar"}
});
ok(!Storage.store[1],"not stored");
var func = function(){};
s.bind("foo",func) ;
ok(Storage.store[1], "stored");
s.unbind("foo", func);
ok(!Storage.store[1],"not stored");
var s2 = new Storage({});
s2.bind("foo",func) ;
s2.attr('id',5)
ok(Storage.store[5], "stored");
s2.unbind("foo", func);
ok(!Storage.store[5],"not stored");
})
test("store ajax binding", function(){
var Guy = can.Model({
findAll : "/guys",
findOne : "/guy/{id}"
},{});
can.fixture("GET /guys", function(){
return [{id: 1}]
})
can.fixture("GET /guy/{id}", function(){
return {id: 1}
});
stop();
can.when( Guy.findOne({id: 1}),
Guy.findAll()).then(function(guyRes, guysRes2){
equals(guyRes.id,1, "got a guy id 1 back");
equals(guysRes2[0].id, 1, "got guys w/ id 1 back")
ok(guyRes === guysRes2[0], "guys are the same");
// check the store is empty
setTimeout(function(){
start();
for(var id in Guy.store){
ok(false, "there should be nothing in the store")
}
},1)
});
})
test("store instance updates", function(){
var Guy, updateCount;
Guy = can.Model({
findAll : 'GET /guys'
},{});
updateCount = 0;
can.fixture("GET /guys", function(){
var guys = [{id: 1, updateCount: updateCount, nested: {count: updateCount}}];
updateCount++;
return guys;
});
stop();
Guy.findAll({}, function(guys){
start();
guys[0].bind('updated', function(){});
ok(Guy.store[1], 'instance stored');
equals(Guy.store[1].updateCount, 0, 'updateCount is 0')
equals(Guy.store[1].nested.count, 0, 'nested.count is 0')
})
Guy.findAll({}, function(guys){
equals(Guy.store[1].updateCount, 1, 'updateCount is 1')
equals(Guy.store[1].nested.count, 1, 'nested.count is 1')
})
})
/** /
test("store instance update removed fields", function(){
var Guy, updateCount, remove;
Guy = can.Model({
findAll : 'GET /guys'
},{});
remove = false;
can.fixture("GET /guys", function(){
var guys = [{id: 1, name: 'mikey', age: 35, likes: ['soccer', 'fantasy baseball', 'js', 'zelda'], dislikes: ['backbone', 'errors']}];
if(remove) {
delete guys[0].name;
guys[0].likes = [];
delete guys[0].dislikes;
}
remove = true;
return guys;
});
stop();
Guy.findAll({}, function(guys){
start();
guys[0].bind('updated', function(){});
ok(Guy.store[1], 'instance stored');
equals(Guy.store[1].name, 'mikey', 'name is mikey')
equals(Guy.store[1].likes.length, 4, 'mikey has 4 likes')
equals(Guy.store[1].dislikes.length, 2, 'mikey has 2 dislikes')
})
Guy.findAll({}, function(guys){
equals(Guy.store[1].name, undefined, 'name is undefined')
equals(Guy.store[1].likes.length, 0, 'no likes')
equals(Guy.store[1].dislikes, undefined, 'dislikes removed')
})
})
/**/
test("templated destroy", function(){
var MyModel = can.Model({
destroy : "/destroyplace/{id}"
},{});
can.fixture("/destroyplace/{id}", function(original){
ok(true,"fixture called");
equals(original.url, "/destroyplace/5", "urls match")
return {};
})
stop();
new MyModel({id: 5}).destroy(function(){
start();
})
can.fixture("/product/{id}", function( original ) {
equals(original.data.id, 9001, "Changed ID is correctly set.");
start();
return {};
});
Base = can.Model({
id:'_id'
}, {
});
Product = Base({
destroy:'DELETE /product/{id}'
},{
});
var prod = new Product({
_id: 9001
}).destroy();
stop();
});
test("overwrite makeFindAll", function(){
var store = {};
var LocalModel = can.Model({
makeFindOne : function(findOne){
return function(params, success, error){
var def = new can.Deferred(),
data = store[params.id];
def.then(success, error)
// make the ajax request right away
var findOneDeferred = findOne(params);
if(data){
var instance= this.model(data);
findOneDeferred.then(function(data){
instance.updated(data)
}, function(){
can.trigger(instance,"error", data)
});
def.resolve(instance)
} else {
findOneDeferred.then(can.proxy(function(data){
var instance= this.model(data);
store[instance[this.id]] = data;
def.resolve(instance)
}, this), function(data){
def.reject(data)
})
}
return def;
}
}
},{
updated : function(attrs){
can.Model.prototype.updated.apply(this, arguments);
store[this[this.constructor.id]] = this.serialize();
}
});
can.fixture("/food/{id}", function(settings){
return count == 0 ? {
id: settings.data.id,
name : "hot dog"
} : {
id: settings.data.id,
name : "ice water"
}
})
var Food = LocalModel({
findOne : "/food/{id}"
},{});
stop();
var count = 0;
Food.findOne({id: 1}, function(food){
count = 1;
ok(true, "empty findOne called back")
food.bind("name", function(){
ok(true, "name changed");
equal(count, 2, "after last find one")
equals(this.name, "ice water");
start();
})
Food.findOne({id: 1}, function(food2){
count = 2;
ok(food2 === food, "same instances")
equals(food2.name, "hot dog")
});
});
});
test("inheriting unique model names", function(){
var Foo = can.Model({});
var Bar = can.Model({});
ok(Foo.fullName != Bar.fullName, "fullNames not the same")
})
test("model list attr", function() {
can.Model("Person",{},{});
var list1 = new Person.List(),
list2 = new Person.List([ new Person({ id : 1 }), new Person({ id : 2 }) ]);
equal( list1.length, 0, "Initial empty list has length of 0")
list1.attr( list2 );
equal( list1.length, 2, "Merging using attr yields length of 2")
console.log( list1 )
});
test("destroying a model impact the right list", function() {
can.Model("Person",{
destroy : function(id, success){
var def = isDojo ? new dojo.Deferred() : new can.Deferred();
def.resolve({})
return def;
}
},{});
can.Model("Organisation",{
destroy : function(id, success){
var def = isDojo ? new dojo.Deferred() : new can.Deferred();
def.resolve({})
return def;
}
},{});
var list1 = new Person.List([ new Person({ id : 1 }), new Person({ id : 2 }) ]),
list2 = new Organisation.List([ new Organisation({ id : 1 }), new Organisation({ id : 2 }) ]);
// set each person to have an organization
list1[0].attr('organisation', list2[0]);
list1[1].attr('organisation', list2[1]);
equal( list1.length, 2, "Initial Person.List has length of 2")
equal( list2.length, 2, "Initial Organisation.List has length of 2")
list2[0].destroy();
equal( list1.length, 2, "After destroying list2[0] Person.List has length of 2")
equal( list2.length, 1, "After destroying list2[0] Organisation.List has length of 1")
console.log( list1 )
console.log( list2 )
});
test("uses attr with isNew", function(){
expect(1)
var old = can.Observe.__reading;
can.Observe.__reading = function(object, attribute){
if(attribute == "id") {
ok(true, "used attr")
}
}
var m = new can.Model({id: 4});
m.isNew();
can.Observe.__reading = old;
});
test("extends defaults by calling base method", function(){
var M1 = can.Model({
defaults: {foo: "bar"}
},{});
var M2 = M1({});
equal(M2.defaults.foo,"bar")
});
test(".models updates existing list if passed", 4, function() {
var Model = can.Model({});
var list = Model.models([{
id : 1,
name : 'first'
}, {
id : 2,
name : 'second'
}]);
list.bind('add', function(ev, newData) {
equal(newData.length, 3, 'Got all new items at once');
});
var newList = Model.models([{
id : 3,
name : 'third'
}, {
id : 4,
name : 'fourth'
}, {
id : 5,
name : 'fifth'
}], list);
equal(list, newList, 'Lists are the same');
equal(newList.attr('length'), 3, 'List has new items');
equal(list[0].name, 'third', 'New item is the first one');
});
test("calling destroy with unsaved model triggers destroyed event (#181)", function() {
var MyModel = can.Model({}, {}),
newModel = new MyModel(),
list = new MyModel.List(),
deferred;
list.push(newModel);
equal(list.attr('length'), 1, "List length as expected");
deferred = newModel.destroy();
ok(deferred, ".destroy returned a Deferred");
equal(list.attr('length'), 0, "Unsaved model removed from list");
deferred.done(function(data) {
ok(data == newModel, "Resolved with destroyed model as described in docs");
});
});
})();