jdl 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +18 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +54 -0
- data/Rakefile +1 -0
- data/bin/jdl +60 -0
- data/jdl.gemspec +23 -0
- data/lib/jdl/version.rb +3 -0
- data/lib/jdl.rb +53 -0
- data/test/collection.js +1154 -0
- data/test/environment.js +35 -0
- data/test/events.js +452 -0
- data/test/index.html +29 -0
- data/test/model.coffee +43 -0
- data/test/model.js +1110 -0
- data/test/noconflict.js +12 -0
- data/test/router.js +689 -0
- data/test/sync.js +210 -0
- data/test/vendor/backbone.js +1582 -0
- data/test/vendor/jquery.js +9472 -0
- data/test/vendor/json2.js +481 -0
- data/test/vendor/qunit.css +244 -0
- data/test/vendor/qunit.js +2212 -0
- data/test/vendor/runner.js +127 -0
- data/test/vendor/underscore.js +1222 -0
- data/test/view.js +330 -0
- metadata +128 -0
data/test/environment.js
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
(function() {
|
2
|
+
|
3
|
+
var sync = Backbone.sync;
|
4
|
+
var ajax = Backbone.ajax;
|
5
|
+
var emulateHTTP = Backbone.emulateHTTP;
|
6
|
+
var emulateJSON = Backbone.emulateJSON;
|
7
|
+
|
8
|
+
QUnit.testStart(function() {
|
9
|
+
var env = this.config.current.testEnvironment;
|
10
|
+
|
11
|
+
// Capture ajax settings for comparison.
|
12
|
+
Backbone.ajax = function(settings) {
|
13
|
+
env.ajaxSettings = settings;
|
14
|
+
};
|
15
|
+
|
16
|
+
// Capture the arguments to Backbone.sync for comparison.
|
17
|
+
Backbone.sync = function(method, model, options) {
|
18
|
+
env.syncArgs = {
|
19
|
+
method: method,
|
20
|
+
model: model,
|
21
|
+
options: options
|
22
|
+
};
|
23
|
+
sync.apply(this, arguments);
|
24
|
+
};
|
25
|
+
|
26
|
+
});
|
27
|
+
|
28
|
+
QUnit.testDone(function() {
|
29
|
+
Backbone.sync = sync;
|
30
|
+
Backbone.ajax = ajax;
|
31
|
+
Backbone.emulateHTTP = emulateHTTP;
|
32
|
+
Backbone.emulateJSON = emulateJSON;
|
33
|
+
});
|
34
|
+
|
35
|
+
})();
|
data/test/events.js
ADDED
@@ -0,0 +1,452 @@
|
|
1
|
+
$(document).ready(function() {
|
2
|
+
|
3
|
+
module("Backbone.Events");
|
4
|
+
|
5
|
+
test("on and trigger", 2, function() {
|
6
|
+
var obj = { counter: 0 };
|
7
|
+
_.extend(obj,Backbone.Events);
|
8
|
+
obj.on('event', function() { obj.counter += 1; });
|
9
|
+
obj.trigger('event');
|
10
|
+
equal(obj.counter,1,'counter should be incremented.');
|
11
|
+
obj.trigger('event');
|
12
|
+
obj.trigger('event');
|
13
|
+
obj.trigger('event');
|
14
|
+
obj.trigger('event');
|
15
|
+
equal(obj.counter, 5, 'counter should be incremented five times.');
|
16
|
+
});
|
17
|
+
|
18
|
+
test("binding and triggering multiple events", 4, function() {
|
19
|
+
var obj = { counter: 0 };
|
20
|
+
_.extend(obj, Backbone.Events);
|
21
|
+
|
22
|
+
obj.on('a b c', function() { obj.counter += 1; });
|
23
|
+
|
24
|
+
obj.trigger('a');
|
25
|
+
equal(obj.counter, 1);
|
26
|
+
|
27
|
+
obj.trigger('a b');
|
28
|
+
equal(obj.counter, 3);
|
29
|
+
|
30
|
+
obj.trigger('c');
|
31
|
+
equal(obj.counter, 4);
|
32
|
+
|
33
|
+
obj.off('a c');
|
34
|
+
obj.trigger('a b c');
|
35
|
+
equal(obj.counter, 5);
|
36
|
+
});
|
37
|
+
|
38
|
+
test("binding and triggering with event maps", function() {
|
39
|
+
var obj = { counter: 0 };
|
40
|
+
_.extend(obj, Backbone.Events);
|
41
|
+
|
42
|
+
var increment = function() {
|
43
|
+
this.counter += 1;
|
44
|
+
};
|
45
|
+
|
46
|
+
obj.on({
|
47
|
+
a: increment,
|
48
|
+
b: increment,
|
49
|
+
c: increment
|
50
|
+
}, obj);
|
51
|
+
|
52
|
+
obj.trigger('a');
|
53
|
+
equal(obj.counter, 1);
|
54
|
+
|
55
|
+
obj.trigger('a b');
|
56
|
+
equal(obj.counter, 3);
|
57
|
+
|
58
|
+
obj.trigger('c');
|
59
|
+
equal(obj.counter, 4);
|
60
|
+
|
61
|
+
obj.off({
|
62
|
+
a: increment,
|
63
|
+
c: increment
|
64
|
+
}, obj);
|
65
|
+
obj.trigger('a b c');
|
66
|
+
equal(obj.counter, 5);
|
67
|
+
});
|
68
|
+
|
69
|
+
test("listenTo and stopListening", 1, function() {
|
70
|
+
var a = _.extend({}, Backbone.Events);
|
71
|
+
var b = _.extend({}, Backbone.Events);
|
72
|
+
a.listenTo(b, 'all', function(){ ok(true); });
|
73
|
+
b.trigger('anything');
|
74
|
+
a.listenTo(b, 'all', function(){ ok(false); });
|
75
|
+
a.stopListening();
|
76
|
+
b.trigger('anything');
|
77
|
+
});
|
78
|
+
|
79
|
+
test("listenTo and stopListening with event maps", 4, function() {
|
80
|
+
var a = _.extend({}, Backbone.Events);
|
81
|
+
var b = _.extend({}, Backbone.Events);
|
82
|
+
var cb = function(){ ok(true); };
|
83
|
+
a.listenTo(b, {event: cb});
|
84
|
+
b.trigger('event');
|
85
|
+
a.listenTo(b, {event2: cb});
|
86
|
+
b.on('event2', cb);
|
87
|
+
a.stopListening(b, {event2: cb});
|
88
|
+
b.trigger('event event2');
|
89
|
+
a.stopListening();
|
90
|
+
b.trigger('event event2');
|
91
|
+
});
|
92
|
+
|
93
|
+
test("stopListening with omitted args", 2, function () {
|
94
|
+
var a = _.extend({}, Backbone.Events);
|
95
|
+
var b = _.extend({}, Backbone.Events);
|
96
|
+
var cb = function () { ok(true); };
|
97
|
+
a.listenTo(b, 'event', cb);
|
98
|
+
b.on('event', cb);
|
99
|
+
a.listenTo(b, 'event2', cb);
|
100
|
+
a.stopListening(null, {event: cb});
|
101
|
+
b.trigger('event event2');
|
102
|
+
b.off();
|
103
|
+
a.listenTo(b, 'event event2', cb);
|
104
|
+
a.stopListening(null, 'event');
|
105
|
+
a.stopListening();
|
106
|
+
b.trigger('event2');
|
107
|
+
});
|
108
|
+
|
109
|
+
test("listenToOnce and stopListening", 1, function() {
|
110
|
+
var a = _.extend({}, Backbone.Events);
|
111
|
+
var b = _.extend({}, Backbone.Events);
|
112
|
+
a.listenToOnce(b, 'all', function() { ok(true); });
|
113
|
+
b.trigger('anything');
|
114
|
+
b.trigger('anything');
|
115
|
+
a.listenToOnce(b, 'all', function() { ok(false); });
|
116
|
+
a.stopListening();
|
117
|
+
b.trigger('anything');
|
118
|
+
});
|
119
|
+
|
120
|
+
test("listenTo, listenToOnce and stopListening", 1, function() {
|
121
|
+
var a = _.extend({}, Backbone.Events);
|
122
|
+
var b = _.extend({}, Backbone.Events);
|
123
|
+
a.listenToOnce(b, 'all', function() { ok(true); });
|
124
|
+
b.trigger('anything');
|
125
|
+
b.trigger('anything');
|
126
|
+
a.listenTo(b, 'all', function() { ok(false); });
|
127
|
+
a.stopListening();
|
128
|
+
b.trigger('anything');
|
129
|
+
});
|
130
|
+
|
131
|
+
test("listenTo and stopListening with event maps", 1, function() {
|
132
|
+
var a = _.extend({}, Backbone.Events);
|
133
|
+
var b = _.extend({}, Backbone.Events);
|
134
|
+
a.listenTo(b, {change: function(){ ok(true); }});
|
135
|
+
b.trigger('change');
|
136
|
+
a.listenTo(b, {change: function(){ ok(false); }});
|
137
|
+
a.stopListening();
|
138
|
+
b.trigger('change');
|
139
|
+
});
|
140
|
+
|
141
|
+
test("listenTo yourself", 1, function(){
|
142
|
+
var e = _.extend({}, Backbone.Events);
|
143
|
+
e.listenTo(e, "foo", function(){ ok(true); });
|
144
|
+
e.trigger("foo");
|
145
|
+
});
|
146
|
+
|
147
|
+
test("listenTo yourself cleans yourself up with stopListening", 1, function(){
|
148
|
+
var e = _.extend({}, Backbone.Events);
|
149
|
+
e.listenTo(e, "foo", function(){ ok(true); });
|
150
|
+
e.trigger("foo");
|
151
|
+
e.stopListening();
|
152
|
+
e.trigger("foo");
|
153
|
+
});
|
154
|
+
|
155
|
+
test("listenTo with empty callback doesn't throw an error", 1, function(){
|
156
|
+
var e = _.extend({}, Backbone.Events);
|
157
|
+
e.listenTo(e, "foo", null);
|
158
|
+
e.trigger("foo");
|
159
|
+
ok(true);
|
160
|
+
});
|
161
|
+
|
162
|
+
test("trigger all for each event", 3, function() {
|
163
|
+
var a, b, obj = { counter: 0 };
|
164
|
+
_.extend(obj, Backbone.Events);
|
165
|
+
obj.on('all', function(event) {
|
166
|
+
obj.counter++;
|
167
|
+
if (event == 'a') a = true;
|
168
|
+
if (event == 'b') b = true;
|
169
|
+
})
|
170
|
+
.trigger('a b');
|
171
|
+
ok(a);
|
172
|
+
ok(b);
|
173
|
+
equal(obj.counter, 2);
|
174
|
+
});
|
175
|
+
|
176
|
+
test("on, then unbind all functions", 1, function() {
|
177
|
+
var obj = { counter: 0 };
|
178
|
+
_.extend(obj,Backbone.Events);
|
179
|
+
var callback = function() { obj.counter += 1; };
|
180
|
+
obj.on('event', callback);
|
181
|
+
obj.trigger('event');
|
182
|
+
obj.off('event');
|
183
|
+
obj.trigger('event');
|
184
|
+
equal(obj.counter, 1, 'counter should have only been incremented once.');
|
185
|
+
});
|
186
|
+
|
187
|
+
test("bind two callbacks, unbind only one", 2, function() {
|
188
|
+
var obj = { counterA: 0, counterB: 0 };
|
189
|
+
_.extend(obj,Backbone.Events);
|
190
|
+
var callback = function() { obj.counterA += 1; };
|
191
|
+
obj.on('event', callback);
|
192
|
+
obj.on('event', function() { obj.counterB += 1; });
|
193
|
+
obj.trigger('event');
|
194
|
+
obj.off('event', callback);
|
195
|
+
obj.trigger('event');
|
196
|
+
equal(obj.counterA, 1, 'counterA should have only been incremented once.');
|
197
|
+
equal(obj.counterB, 2, 'counterB should have been incremented twice.');
|
198
|
+
});
|
199
|
+
|
200
|
+
test("unbind a callback in the midst of it firing", 1, function() {
|
201
|
+
var obj = {counter: 0};
|
202
|
+
_.extend(obj, Backbone.Events);
|
203
|
+
var callback = function() {
|
204
|
+
obj.counter += 1;
|
205
|
+
obj.off('event', callback);
|
206
|
+
};
|
207
|
+
obj.on('event', callback);
|
208
|
+
obj.trigger('event');
|
209
|
+
obj.trigger('event');
|
210
|
+
obj.trigger('event');
|
211
|
+
equal(obj.counter, 1, 'the callback should have been unbound.');
|
212
|
+
});
|
213
|
+
|
214
|
+
test("two binds that unbind themeselves", 2, function() {
|
215
|
+
var obj = { counterA: 0, counterB: 0 };
|
216
|
+
_.extend(obj,Backbone.Events);
|
217
|
+
var incrA = function(){ obj.counterA += 1; obj.off('event', incrA); };
|
218
|
+
var incrB = function(){ obj.counterB += 1; obj.off('event', incrB); };
|
219
|
+
obj.on('event', incrA);
|
220
|
+
obj.on('event', incrB);
|
221
|
+
obj.trigger('event');
|
222
|
+
obj.trigger('event');
|
223
|
+
obj.trigger('event');
|
224
|
+
equal(obj.counterA, 1, 'counterA should have only been incremented once.');
|
225
|
+
equal(obj.counterB, 1, 'counterB should have only been incremented once.');
|
226
|
+
});
|
227
|
+
|
228
|
+
test("bind a callback with a supplied context", 1, function () {
|
229
|
+
var TestClass = function () {
|
230
|
+
return this;
|
231
|
+
};
|
232
|
+
TestClass.prototype.assertTrue = function () {
|
233
|
+
ok(true, '`this` was bound to the callback');
|
234
|
+
};
|
235
|
+
|
236
|
+
var obj = _.extend({},Backbone.Events);
|
237
|
+
obj.on('event', function () { this.assertTrue(); }, (new TestClass));
|
238
|
+
obj.trigger('event');
|
239
|
+
});
|
240
|
+
|
241
|
+
test("nested trigger with unbind", 1, function () {
|
242
|
+
var obj = { counter: 0 };
|
243
|
+
_.extend(obj, Backbone.Events);
|
244
|
+
var incr1 = function(){ obj.counter += 1; obj.off('event', incr1); obj.trigger('event'); };
|
245
|
+
var incr2 = function(){ obj.counter += 1; };
|
246
|
+
obj.on('event', incr1);
|
247
|
+
obj.on('event', incr2);
|
248
|
+
obj.trigger('event');
|
249
|
+
equal(obj.counter, 3, 'counter should have been incremented three times');
|
250
|
+
});
|
251
|
+
|
252
|
+
test("callback list is not altered during trigger", 2, function () {
|
253
|
+
var counter = 0, obj = _.extend({}, Backbone.Events);
|
254
|
+
var incr = function(){ counter++; };
|
255
|
+
obj.on('event', function(){ obj.on('event', incr).on('all', incr); })
|
256
|
+
.trigger('event');
|
257
|
+
equal(counter, 0, 'bind does not alter callback list');
|
258
|
+
obj.off()
|
259
|
+
.on('event', function(){ obj.off('event', incr).off('all', incr); })
|
260
|
+
.on('event', incr)
|
261
|
+
.on('all', incr)
|
262
|
+
.trigger('event');
|
263
|
+
equal(counter, 2, 'unbind does not alter callback list');
|
264
|
+
});
|
265
|
+
|
266
|
+
test("#1282 - 'all' callback list is retrieved after each event.", 1, function() {
|
267
|
+
var counter = 0;
|
268
|
+
var obj = _.extend({}, Backbone.Events);
|
269
|
+
var incr = function(){ counter++; };
|
270
|
+
obj.on('x', function() {
|
271
|
+
obj.on('y', incr).on('all', incr);
|
272
|
+
})
|
273
|
+
.trigger('x y');
|
274
|
+
strictEqual(counter, 2);
|
275
|
+
});
|
276
|
+
|
277
|
+
test("if no callback is provided, `on` is a noop", 0, function() {
|
278
|
+
_.extend({}, Backbone.Events).on('test').trigger('test');
|
279
|
+
});
|
280
|
+
|
281
|
+
test("if callback is truthy but not a function, `on` should throw an error just like jQuery", 1, function() {
|
282
|
+
var view = _.extend({}, Backbone.Events).on('test', 'noop');
|
283
|
+
throws(function() {
|
284
|
+
view.trigger('test');
|
285
|
+
});
|
286
|
+
});
|
287
|
+
|
288
|
+
test("remove all events for a specific context", 4, function() {
|
289
|
+
var obj = _.extend({}, Backbone.Events);
|
290
|
+
obj.on('x y all', function() { ok(true); });
|
291
|
+
obj.on('x y all', function() { ok(false); }, obj);
|
292
|
+
obj.off(null, null, obj);
|
293
|
+
obj.trigger('x y');
|
294
|
+
});
|
295
|
+
|
296
|
+
test("remove all events for a specific callback", 4, function() {
|
297
|
+
var obj = _.extend({}, Backbone.Events);
|
298
|
+
var success = function() { ok(true); };
|
299
|
+
var fail = function() { ok(false); };
|
300
|
+
obj.on('x y all', success);
|
301
|
+
obj.on('x y all', fail);
|
302
|
+
obj.off(null, fail);
|
303
|
+
obj.trigger('x y');
|
304
|
+
});
|
305
|
+
|
306
|
+
test("#1310 - off does not skip consecutive events", 0, function() {
|
307
|
+
var obj = _.extend({}, Backbone.Events);
|
308
|
+
obj.on('event', function() { ok(false); }, obj);
|
309
|
+
obj.on('event', function() { ok(false); }, obj);
|
310
|
+
obj.off(null, null, obj);
|
311
|
+
obj.trigger('event');
|
312
|
+
});
|
313
|
+
|
314
|
+
test("once", 2, function() {
|
315
|
+
// Same as the previous test, but we use once rather than having to explicitly unbind
|
316
|
+
var obj = { counterA: 0, counterB: 0 };
|
317
|
+
_.extend(obj, Backbone.Events);
|
318
|
+
var incrA = function(){ obj.counterA += 1; obj.trigger('event'); };
|
319
|
+
var incrB = function(){ obj.counterB += 1; };
|
320
|
+
obj.once('event', incrA);
|
321
|
+
obj.once('event', incrB);
|
322
|
+
obj.trigger('event');
|
323
|
+
equal(obj.counterA, 1, 'counterA should have only been incremented once.');
|
324
|
+
equal(obj.counterB, 1, 'counterB should have only been incremented once.');
|
325
|
+
});
|
326
|
+
|
327
|
+
test("once variant one", 3, function() {
|
328
|
+
var f = function(){ ok(true); };
|
329
|
+
|
330
|
+
var a = _.extend({}, Backbone.Events).once('event', f);
|
331
|
+
var b = _.extend({}, Backbone.Events).on('event', f);
|
332
|
+
|
333
|
+
a.trigger('event');
|
334
|
+
|
335
|
+
b.trigger('event');
|
336
|
+
b.trigger('event');
|
337
|
+
});
|
338
|
+
|
339
|
+
test("once variant two", 3, function() {
|
340
|
+
var f = function(){ ok(true); };
|
341
|
+
var obj = _.extend({}, Backbone.Events);
|
342
|
+
|
343
|
+
obj
|
344
|
+
.once('event', f)
|
345
|
+
.on('event', f)
|
346
|
+
.trigger('event')
|
347
|
+
.trigger('event');
|
348
|
+
});
|
349
|
+
|
350
|
+
test("once with off", 0, function() {
|
351
|
+
var f = function(){ ok(true); };
|
352
|
+
var obj = _.extend({}, Backbone.Events);
|
353
|
+
|
354
|
+
obj.once('event', f);
|
355
|
+
obj.off('event', f);
|
356
|
+
obj.trigger('event');
|
357
|
+
});
|
358
|
+
|
359
|
+
test("once with event maps", function() {
|
360
|
+
var obj = { counter: 0 };
|
361
|
+
_.extend(obj, Backbone.Events);
|
362
|
+
|
363
|
+
var increment = function() {
|
364
|
+
this.counter += 1;
|
365
|
+
};
|
366
|
+
|
367
|
+
obj.once({
|
368
|
+
a: increment,
|
369
|
+
b: increment,
|
370
|
+
c: increment
|
371
|
+
}, obj);
|
372
|
+
|
373
|
+
obj.trigger('a');
|
374
|
+
equal(obj.counter, 1);
|
375
|
+
|
376
|
+
obj.trigger('a b');
|
377
|
+
equal(obj.counter, 2);
|
378
|
+
|
379
|
+
obj.trigger('c');
|
380
|
+
equal(obj.counter, 3);
|
381
|
+
|
382
|
+
obj.trigger('a b c');
|
383
|
+
equal(obj.counter, 3);
|
384
|
+
});
|
385
|
+
|
386
|
+
test("once with off only by context", 0, function() {
|
387
|
+
var context = {};
|
388
|
+
var obj = _.extend({}, Backbone.Events);
|
389
|
+
obj.once('event', function(){ ok(false); }, context);
|
390
|
+
obj.off(null, null, context);
|
391
|
+
obj.trigger('event');
|
392
|
+
});
|
393
|
+
|
394
|
+
test("Backbone object inherits Events", function() {
|
395
|
+
ok(Backbone.on === Backbone.Events.on);
|
396
|
+
});
|
397
|
+
|
398
|
+
asyncTest("once with asynchronous events", 1, function() {
|
399
|
+
var func = _.debounce(function() { ok(true); start(); }, 50);
|
400
|
+
var obj = _.extend({}, Backbone.Events).once('async', func);
|
401
|
+
|
402
|
+
obj.trigger('async');
|
403
|
+
obj.trigger('async');
|
404
|
+
});
|
405
|
+
|
406
|
+
test("once with multiple events.", 2, function() {
|
407
|
+
var obj = _.extend({}, Backbone.Events);
|
408
|
+
obj.once('x y', function() { ok(true); });
|
409
|
+
obj.trigger('x y');
|
410
|
+
});
|
411
|
+
|
412
|
+
test("Off during iteration with once.", 2, function() {
|
413
|
+
var obj = _.extend({}, Backbone.Events);
|
414
|
+
var f = function(){ this.off('event', f); };
|
415
|
+
obj.on('event', f);
|
416
|
+
obj.once('event', function(){});
|
417
|
+
obj.on('event', function(){ ok(true); });
|
418
|
+
|
419
|
+
obj.trigger('event');
|
420
|
+
obj.trigger('event');
|
421
|
+
});
|
422
|
+
|
423
|
+
test("`once` on `all` should work as expected", 1, function() {
|
424
|
+
Backbone.once('all', function() {
|
425
|
+
ok(true);
|
426
|
+
Backbone.trigger('all');
|
427
|
+
});
|
428
|
+
Backbone.trigger('all');
|
429
|
+
});
|
430
|
+
|
431
|
+
test("once without a callback is a noop", 0, function() {
|
432
|
+
_.extend({}, Backbone.Events).once('event').trigger('event');
|
433
|
+
});
|
434
|
+
|
435
|
+
test("event functions are chainable", function() {
|
436
|
+
var obj = _.extend({}, Backbone.Events);
|
437
|
+
var obj2 = _.extend({}, Backbone.Events);
|
438
|
+
var fn = function() {};
|
439
|
+
equal(obj, obj.trigger('noeventssetyet'));
|
440
|
+
equal(obj, obj.off('noeventssetyet'));
|
441
|
+
equal(obj, obj.stopListening('noeventssetyet'));
|
442
|
+
equal(obj, obj.on('a', fn));
|
443
|
+
equal(obj, obj.once('c', fn));
|
444
|
+
equal(obj, obj.trigger('a'));
|
445
|
+
equal(obj, obj.listenTo(obj2, 'a', fn));
|
446
|
+
equal(obj, obj.listenToOnce(obj2, 'b', fn));
|
447
|
+
equal(obj, obj.off('a c'));
|
448
|
+
equal(obj, obj.stopListening(obj2, 'a'));
|
449
|
+
equal(obj, obj.stopListening());
|
450
|
+
});
|
451
|
+
|
452
|
+
});
|
data/test/index.html
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
<!doctype html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<meta charset='utf8'>
|
5
|
+
<title>Backbone Test Suite</title>
|
6
|
+
<link rel="stylesheet" href="vendor/qunit.css" type="text/css" media="screen">
|
7
|
+
<script src="vendor/json2.js"></script>
|
8
|
+
<script src="vendor/jquery.js"></script>
|
9
|
+
<script src="vendor/qunit.js"></script>
|
10
|
+
<script src="vendor/underscore.js"></script>
|
11
|
+
<script src="../backbone.js"></script>
|
12
|
+
<script src="environment.js"></script>
|
13
|
+
<script src="noconflict.js"></script>
|
14
|
+
<script src="events.js"></script>
|
15
|
+
<script src="model.js"></script>
|
16
|
+
<script src="collection.js"></script>
|
17
|
+
<script src="router.js"></script>
|
18
|
+
<script src="view.js"></script>
|
19
|
+
<script src="sync.js"></script>
|
20
|
+
</head>
|
21
|
+
<body>
|
22
|
+
<div id="qunit"></div>
|
23
|
+
<div id="qunit-fixture">
|
24
|
+
<div id='testElement'>
|
25
|
+
<h1>Test</h1>
|
26
|
+
</div>
|
27
|
+
</div>
|
28
|
+
</body>
|
29
|
+
</html>
|
data/test/model.coffee
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
# Quick Backbone/CoffeeScript tests to make sure that inheritance
|
2
|
+
# works correctly.
|
3
|
+
|
4
|
+
{ok, equal, deepEqual} = require 'assert'
|
5
|
+
{Model, Collection, Events} = require '../backbone'
|
6
|
+
|
7
|
+
|
8
|
+
# Patch `ok` to store a count of passed tests...
|
9
|
+
count = 0
|
10
|
+
oldOk = ok
|
11
|
+
ok = ->
|
12
|
+
oldOk arguments...
|
13
|
+
count++
|
14
|
+
|
15
|
+
|
16
|
+
class Document extends Model
|
17
|
+
|
18
|
+
fullName: ->
|
19
|
+
@get('name') + ' ' + @get('surname')
|
20
|
+
|
21
|
+
tempest = new Document
|
22
|
+
id : '1-the-tempest',
|
23
|
+
title : "The Tempest",
|
24
|
+
name : "William"
|
25
|
+
surname : "Shakespeare"
|
26
|
+
length : 123
|
27
|
+
|
28
|
+
ok tempest.fullName() is "William Shakespeare"
|
29
|
+
ok tempest.get('length') is 123
|
30
|
+
|
31
|
+
|
32
|
+
class ProperDocument extends Document
|
33
|
+
|
34
|
+
fullName: ->
|
35
|
+
"Mr. " + super
|
36
|
+
|
37
|
+
properTempest = new ProperDocument tempest.attributes
|
38
|
+
|
39
|
+
ok properTempest.fullName() is "Mr. William Shakespeare"
|
40
|
+
ok properTempest.get('length') is 123
|
41
|
+
|
42
|
+
|
43
|
+
console.log "passed #{count} tests"
|