Permalink
Browse files

Fixed in memory tests.

  • Loading branch information...
1 parent b81fb4e commit 2bb05825813e0768212027d366de7c92c1aff014 @joeandaverde joeandaverde committed Mar 2, 2012
Showing with 67 additions and 84 deletions.
  1. +67 −84 test/data/adapters/inMemory.spec.coffee
@@ -8,122 +8,105 @@ sampleObjects = [
]
describe 'When using a In-memory store (data/adapters/inMemory)', ->
- adapter = undefined
beforeEach ->
- adapter = new InMemoryDataAdapter()
+ @adapter = new InMemoryDataAdapter()
it 'should require no constructor arguments', ->
- should.exist(adapter)
+ should.exist(@adapter)
it 'should be empty when nothing has been added', ->
- adapter.items.should.eql({})
-
- describe 'when saving a new item', ->
-
- attributes = undefined
+ @adapter.items.should.eql({})
- callback = (err, att) ->
- attributes = att
+ describe 'when saving a new item', ->
- beforeEach ->
- adapter.save('testObjects', sampleObjects[0], callback)
+ beforeEach (done) ->
+ @adapter.save 'testObjects', sampleObjects[0], (e, a) =>
+ @attributes = a
+ @err = e
+ done()
it 'should pass back the original attributes', ->
- should.not.exist(err)
- attributes.test.should.be.true
- attributes.numeric.should.equal(52)
- attributes.items.should.eql(['one', 'two'])
+ should.not.exist(@err)
+ @attributes.test.should.be.true
+ @attributes.numeric.should.equal(52)
+ @attributes.items.should.eql(['one', 'two'])
it 'should not simply use the same object in memory', ->
# standard equal compares memory addresses
- attributes.should.not.equal(sampleObjects[0])
+ @attributes.should.not.equal(sampleObjects[0])
it 'should add an _id attribute', ->
- attributes.should.have.property('_id')
- attributes._id.should.equal(0)
+ @attributes.should.have.property('_id')
+ @attributes._id.should.equal(0)
describe 'when updating an existing item', ->
- beforeEach ->
- adapter.save('testObjects', {
+
+ beforeEach (done) ->
+ @adapter.save 'testObjects', {
'_id': 0
'newObject': sampleObjects[1]
- }, callback)
+ }, (e, a) =>
+ @err = e
+ @attributes = a
+ done()
it 'should pass back the new attributes', ->
- should.not.exist(err)
- should.exist(attributes)
- attributes._id.should.equal(0)
- attributes.newObject.should.eql(sampleObjects[1])
-
- describe 'when finding an object by real id', ->
- foundItems = null
- err = undefined
+ should.not.exist(@err)
+ should.exist(@attributes)
+ @attributes._id.should.equal(0)
+ @attributes.newObject.should.eql(sampleObjects[1])
- findCallback = (e, items) ->
- err = e
- foundItems = items
-
- beforeEach ->
- adapter.find('testObjects', {
- '_id': 0
- }, findCallback)
+ describe 'When finding an object by real id', ->
+
+ beforeEach (done) ->
+ @adapter.find 'testObjects', {'_id': 0}, (e, i) =>
+ @err = e
+ @foundItems = i
+ done()
it 'should return the object stored', ->
- should.not.exist(err)
- should.exist(foundItems)
- foundItems.should.have.length(1)
- foundItems[0]._id.should.equal(0)
- foundItems[0].newObject.should.eql(sampleObjects[1])
+ should.not.exist(@err)
+ should.exist(@foundItems)
+ @foundItems.should.have.length(1)
+ @foundItems[0]._id.should.equal(0)
describe 'when finding an object by a fake id', ->
- foundItems = null
- err = undefined
-
- findCallback = (e, items) ->
- err = e
- foundItems = items
- beforeEach ->
- adapter.find('testObjects', {
- '_id': 1
- }, findCallback)
+
+ beforeEach (done) ->
+ @adapter.find 'testObjects', {'_id': 1}, (e, i) =>
+ @err = e
+ @foundItems = i
+ done()
it 'should not return any items', ->
- should.not.exist(err)
- should.exist(foundItems)
- foundItems.should.have.length(0)
+ should.not.exist(@err)
+ should.exist(@foundItems)
+ @foundItems.should.have.length(0)
describe 'when finding an object in a non-existent collection', ->
- foundItems = null
- err = undefined
- findCallback = (e, items) ->
- err = e
- foundItems = items
- beforeEach ->
- adapter.find('noTestObjects', {
- '_id': 0
- }, findCallback)
-
+ beforeEach (done) ->
+ @adapter.find 'notestObjects', {'_id': 0}, (e, i) =>
+ @err = e
+ @foundItems = i
+ done()
+
it 'should not return any items', ->
- should.not.exist(err)
- should.exist(foundItems)
- foundItems.should.have.length(0)
+ should.not.exist(@err)
+ should.exist(@foundItems)
+ @foundItems.should.have.length(0)
describe 'when searching with no parameters', ->
- foundItems = null
- err = undefined
-
- findCallback = (e, items) ->
- err = e
- foundItems = items
-
- beforeEach ->
- adapter.find('testObjects', {}, findCallback)
-
+
+ beforeEach (done) ->
+ @adapter.find 'testObjects', {}, (e, i) =>
+ @err = e
+ @foundItems = i
+ done()
+
it 'should return all items in the collection', ->
- should.not.exist(err)
- should.exist(foundItems)
- foundItems.should.have.length(1)
- foundItems[0]._id.should.equal(0)
- foundItems[0].newObject.should.eql(sampleObjects[1])
+ should.not.exist(@err)
+ should.exist(@foundItems)
+ @foundItems.should.have.length(1)
+ @foundItems[0]._id.should.equal(0)

0 comments on commit 2bb0582

Please sign in to comment.