| 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" |