forked from flatiron/cradle
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
cloudhead
committed
Aug 2, 2010
1 parent
f68cdef
commit e2f88e1
Showing
1 changed file
with
57 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,57 @@ | |||
var path = require('path'), | |||
sys = require('sys'), | |||
assert = require('assert'), | |||
events = require('events'), | |||
http = require('http'), | |||
fs = require('fs'); | |||
|
|||
require.paths.unshift(path.join(__dirname, '..', 'lib')); | |||
|
|||
var vows = require('vows'); | |||
var cradle = require('cradle'); | |||
|
|||
var document = { _rev: '2-76be', _id: 'f6av8', name: 'buzz', age: 99 }; | |||
|
|||
vows.describe('cradle/Response').addBatch({ | |||
'A cradle.Response instance': { | |||
'from a document': { | |||
topic: new(cradle.Response)(document), | |||
|
|||
'should only have the original keys': function (topic) { | |||
assert.length (Object.keys(topic), 4); | |||
assert.equal (topic.name, 'buzz'); | |||
assert.equal (topic.age, 99); | |||
assert.deepEqual (document, topic); | |||
}, | |||
'should own the keys': function (topic) { | |||
assert.include (topic, 'name'); | |||
assert.include (topic, 'age'); | |||
}, | |||
'should return the original document, when `json` is called': function (topic) { | |||
assert.isObject (topic.json); | |||
assert.deepEqual (topic.json, document); | |||
assert.isUndefined (topic.json.json); | |||
assert.isUndefined (topic.headers); | |||
assert.length (Object.keys(topic.json), 4); | |||
}, | |||
'when using a `for .. in` loop, should only return the original keys': function (topic) { | |||
var keys = []; | |||
for (var k in topic) { keys.push(k) } | |||
|
|||
assert.length (keys, 4); | |||
assert.include (keys, 'name'); | |||
assert.include (keys, 'age'); | |||
}, | |||
'should stringify': function (topic) { | |||
var expected = JSON.stringify(document); | |||
assert.equal (topic.toString(), expected); | |||
assert.equal (JSON.stringify(topic), expected); | |||
}, | |||
'should respond to both `id` and `_id`': function (topic) { | |||
assert.equal (topic.id, 'f6av8'); | |||
assert.equal (topic._id, 'f6av8'); | |||
} | |||
} | |||
} | |||
}).export(module); | |||
|