Skip to content
This repository has been archived by the owner on Apr 29, 2021. It is now read-only.

Commit

Permalink
Finished get tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pksunkara committed Jan 14, 2012
1 parent ea363a8 commit 5734bf5
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 2 deletions.
4 changes: 2 additions & 2 deletions nosqlite.coffee
Expand Up @@ -73,10 +73,10 @@ nosqlite.Connection::database = (name, mode) ->
# Get doc by id
get: (id, cb) ->
fs.readFile @file(id), 'utf8', (err, data) ->
cb err, JSON.parse(data)
cb err, (JSON.parse(data) if data)

getSync: (id) ->
JSON.parse fs.readFileSync @files(id), 'utf8'
JSON.parse fs.readFileSync @file(id), 'utf8'

# Remove doc by id
delete: (id, cb) ->
Expand Down
37 changes: 37 additions & 0 deletions test/database-test.coffee
Expand Up @@ -117,5 +117,42 @@ vows
assert.isUndefined db.destroySync()
assert.isFalse path.existsSync(path.resolve(__dirname, 'fixtures/dummy'))

.addBatch
'Database "test"':
topic: () ->
connection.database 'test'

'get()':
topic: (db) ->
db.get 'bob', @callback

'should be successful': (err, data) ->
assert.isNull err
assert.equal data.name, 'bob'
assert.equal data.age, 35

'getSync()':
topic: (db) ->
db.getSync 'bob'

'should be successful': (data) ->
assert.equal data.name, 'bob'
assert.equal data.age, 35

'get() non-existing':
topic: (db) ->
db.get 'tim', @callback

'should throw error': (err, data) ->
assert.isUndefined data
assert.equal err.code, 'ENOENT'

'getSync() non-existing':
topic: (db) ->
db

'should throw error': (db) ->
assert.throws ->
db.getSync 'tim'

.export(module)
4 changes: 4 additions & 0 deletions test/fixtures/test/bob.json
@@ -0,0 +1,4 @@
{
"name": "bob",
"age": 35
}

0 comments on commit 5734bf5

Please sign in to comment.