Skip to content

Commit 3ccd586

Browse files
Andrew DunkmanAndrew Dunkman
authored andcommitted
Merged from joeandaverde
1 parent 4ffbbf8 commit 3ccd586

10 files changed

Lines changed: 384 additions & 353 deletions

test/collections/tags.spec.coffee

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,16 @@ getTags = (key) ->
1212
callback(null, [])
1313
return tags
1414

15-
describe 'When find() is called for Tags with criteria and a callback', ->
16-
getTags('test1').find { 'one': true }, ->
15+
describe('Tags (collections/tags)', ->
16+
describe('when find() is called with criteria and a callback', ->
17+
getTags('test1').find({ 'one': true }, ->)
1718

18-
it 'should call find() in \'tags\' collection on base', ->
19-
callsToFind.test1.should.have.length(1)
20-
callsToFind.test1[0].should.have.length(3)
21-
callsToFind.test1[0][0].should.equal('tags')
22-
23-
it 'should call find() with criteria on base', ->
24-
callsToFind.test1[0][1].should.eql({ 'one': true })
19+
it 'should call find() in \'tags\' collection on base', ->
20+
callsToFind.test1.should.have.length(1)
21+
callsToFind.test1[0].should.have.length(3)
22+
callsToFind.test1[0][0].should.equal('tags')
2523

24+
it 'should call find() with criteria on base', ->
25+
callsToFind.test1[0][1].should.eql({ 'one': true })
26+
)
27+
)

test/collections/users.spec.coffee

Lines changed: 37 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -12,35 +12,40 @@ getUsers = (key) ->
1212
callback(null, [])
1313
return users
1414

15-
describe 'When find() is called for Users with just a callback', ->
16-
getUsers('test1').find ->
17-
18-
it 'should call find() in \'users\' collection on base', ->
19-
callsToFind.test1.should.have.length(1)
20-
callsToFind.test1[0].should.have.length(3)
21-
callsToFind.test1[0][0].should.equal('users')
22-
23-
it 'should call find() with empty criteria on base', ->
24-
callsToFind.test1[0][1].should.eql({})
25-
26-
describe 'When find() is called with criteria and a callback', ->
27-
getUsers('test2').find { 'one': true }, ->
28-
29-
it 'should call find() in \'users\' collection on base', ->
30-
callsToFind.test2.should.have.length(1)
31-
callsToFind.test2[0].should.have.length(3)
32-
callsToFind.test2[0][0].should.equal('users')
33-
34-
it 'should call find() with criteria on base', ->
35-
callsToFind.test2[0][1].should.eql({ 'one': true })
36-
37-
describe 'When all() is called', ->
38-
getUsers('test3').all ->
39-
40-
it 'should call find() in \'users\' collection on base', ->
41-
callsToFind.test3.should.have.length(1)
42-
callsToFind.test3[0].should.have.length(3)
43-
callsToFind.test3[0][0].should.equal('users')
44-
45-
it 'should call find() with empty criteria on base', ->
46-
callsToFind.test3[0][1].should.eql({})
15+
describe('Users (collections/users)', ->
16+
describe('when find() is called with just a callback', ->
17+
getUsers('test1').find(->)
18+
19+
it 'should call find() in \'users\' collection on base', ->
20+
callsToFind.test1.should.have.length(1)
21+
callsToFind.test1[0].should.have.length(3)
22+
callsToFind.test1[0][0].should.equal('users')
23+
24+
it 'should call find() with empty criteria on base', ->
25+
callsToFind.test1[0][1].should.eql({})
26+
)
27+
28+
describe('when find() is called with criteria and a callback', ->
29+
getUsers('test2').find({ 'one': true }, ->)
30+
31+
it 'should call find() in \'users\' collection on base', ->
32+
callsToFind.test2.should.have.length(1)
33+
callsToFind.test2[0].should.have.length(3)
34+
callsToFind.test2[0][0].should.equal('users')
35+
36+
it 'should call find() with criteria on base', ->
37+
callsToFind.test2[0][1].should.eql({ 'one': true })
38+
)
39+
40+
describe('when all() is called', ->
41+
getUsers('test3').all(->)
42+
43+
it 'should call find() in \'users\' collection on base', ->
44+
callsToFind.test3.should.have.length(1)
45+
callsToFind.test3[0].should.have.length(3)
46+
callsToFind.test3[0][0].should.equal('users')
47+
48+
it 'should call find() with empty criteria on base', ->
49+
callsToFind.test3[0][1].should.eql({})
50+
)
51+
)

test/data/adapters/inMemory.spec.coffee

Lines changed: 78 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,24 @@ sampleObjects = [
66
{ 'one': true, 'two': false }
77
]
88

9-
describe 'When using a In-memory store (data/adapters/inMemory)', ->
10-
9+
describe('In-memory store (data/adapters/inMemory)', ->
1110
beforeEach ->
1211
@adapter = new InMemoryDataAdapter()
13-
12+
1413
it 'should require no constructor arguments', ->
1514
should.exist(@adapter)
16-
15+
1716
it 'should be empty when nothing has been added', ->
1817
@adapter.items.should.eql({})
1918

20-
describe 'when saving a new item', ->
21-
19+
describe('when saving a new item', ->
2220
beforeEach (done) ->
23-
@adapter.save 'testObjects', sampleObjects[0], (e, a) =>
21+
@adapter.save('testObjects', sampleObjects[0], (e, a) =>
2422
@attributes = a
2523
@err = e
2624
done()
27-
25+
)
26+
2827
it 'should pass back the original attributes', ->
2928
should.not.exist(@err)
3029
@attributes.test.should.be.true
@@ -33,79 +32,88 @@ describe 'When using a In-memory store (data/adapters/inMemory)', ->
3332

3433
it 'should not simply use the same object in memory', ->
3534
# standard equal compares memory addresses
36-
@attributes.should.not.equal(sampleObjects[0])
35+
@attributes.should.not.equal(sampleObjects[0])
3736

3837
it 'should add an _id attribute', ->
3938
@attributes.should.have.property('_id')
40-
@attributes._id.should.equal(0)
41-
42-
describe 'when updating an existing item', ->
43-
44-
beforeEach (done) ->
45-
@adapter.save 'testObjects', {
46-
'_id': 0
47-
'newObject': sampleObjects[1]
48-
}, (e, a) =>
49-
@err = e
50-
@attributes = a
51-
done()
52-
53-
it 'should pass back the new attributes', ->
54-
should.not.exist(@err)
55-
should.exist(@attributes)
56-
@attributes._id.should.equal(0)
57-
@attributes.newObject.should.eql(sampleObjects[1])
58-
59-
describe 'When finding an object by real id', ->
60-
61-
beforeEach (done) ->
62-
@adapter.find 'testObjects', {'_id': 0}, (e, i) =>
63-
@err = e
64-
@foundItems = i
65-
done()
39+
@attributes._id.should.equal(0)
40+
)
6641

67-
it 'should return the object stored', ->
68-
should.not.exist(@err)
69-
should.exist(@foundItems)
70-
@foundItems.should.have.length(1)
71-
@foundItems[0]._id.should.equal(0)
42+
describe('when updating an existing item', ->
43+
beforeEach (done) ->
44+
attributes = { '_id': 0, 'newObject': sampleObjects[1] }
45+
@adapter.save('testObjects', attributes, (e, a) =>
46+
@err = e
47+
@attributes = a
48+
done()
49+
)
7250

73-
describe 'when finding an object by a fake id', ->
74-
75-
beforeEach (done) ->
76-
@adapter.find 'testObjects', {'_id': 1}, (e, i) =>
51+
it 'should pass back the new attributes', ->
52+
should.not.exist(@err)
53+
should.exist(@attributes)
54+
@attributes._id.should.equal(0)
55+
@attributes.newObject.should.eql(sampleObjects[1])
56+
)
57+
58+
describe('When finding an object by real id', ->
59+
beforeEach (done) ->
60+
@adapter.save('testObjects', sampleObjects[0], (e, a) =>
61+
@adapter.find('testObjects', {'_id': 0}, (e, i) =>
7762
@err = e
7863
@foundItems = i
7964
done()
65+
)
66+
)
67+
68+
it 'should return the object stored', ->
69+
should.not.exist(@err)
70+
should.exist(@foundItems)
71+
@foundItems.should.have.length(1)
72+
@foundItems[0]._id.should.equal(0)
73+
)
8074

81-
it 'should not return any items', ->
82-
should.not.exist(@err)
83-
should.exist(@foundItems)
84-
@foundItems.should.have.length(0)
75+
describe('when finding an object by a fake id', ->
76+
beforeEach (done) ->
77+
@adapter.find('testObjects', {'_id': 1}, (e, i) =>
78+
@err = e
79+
@foundItems = i
80+
done()
81+
)
8582

86-
describe 'when finding an object in a non-existent collection', ->
87-
88-
beforeEach (done) ->
89-
@adapter.find 'notestObjects', {'_id': 0}, (e, i) =>
90-
@err = e
91-
@foundItems = i
92-
done()
83+
it 'should not return any items', ->
84+
should.not.exist(@err)
85+
should.exist(@foundItems)
86+
@foundItems.should.have.length(0)
87+
)
9388

94-
it 'should not return any items', ->
95-
should.not.exist(@err)
96-
should.exist(@foundItems)
97-
@foundItems.should.have.length(0)
89+
describe('when finding an object in a non-existent collection', ->
90+
beforeEach (done) ->
91+
@adapter.find('notestObjects', {'_id': 0}, (e, i) =>
92+
@err = e
93+
@foundItems = i
94+
done()
95+
)
96+
97+
it 'should not return any items', ->
98+
should.not.exist(@err)
99+
should.exist(@foundItems)
100+
@foundItems.should.have.length(0)
101+
)
98102

99-
describe 'when searching with no parameters', ->
100-
101-
beforeEach (done) ->
102-
@adapter.find 'testObjects', {}, (e, i) =>
103+
describe('when searching with no parameters', ->
104+
beforeEach (done) ->
105+
@adapter.save('testObjects', sampleObjects[0], (e, a) =>
106+
@adapter.find('testObjects', {}, (e, i) =>
103107
@err = e
104108
@foundItems = i
105-
done()
106-
107-
it 'should return all items in the collection', ->
108-
should.not.exist(@err)
109-
should.exist(@foundItems)
110-
@foundItems.should.have.length(1)
111-
@foundItems[0]._id.should.equal(0)
109+
done()
110+
)
111+
)
112+
113+
it 'should return all items in the collection', ->
114+
should.not.exist(@err)
115+
should.exist(@foundItems)
116+
@foundItems.should.have.length(1)
117+
@foundItems[0]._id.should.equal(0)
118+
)
119+
)

test/data/storedCollection.spec.coffee

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,24 @@ callsToFind = []
55

66
getStoredCollection = () ->
77
storedCollection = new StoredCollection()
8-
storedCollection._adapter =
8+
storedCollection._adapter =
99
find: (collection, criteria, callback) ->
1010
callsToFind.push([collection, criteria, callback])
1111
callback(null, criteria)
1212
return storedCollection
1313

14-
describe 'When find() is called on Base store collection(data/storedCollection)', ->
15-
callback = ->
16-
17-
getStoredCollection().find 'testCollection', {'one': true }, callback
14+
describe('StoredCollection (data/storedCollection)', ->
15+
describe('when find() is called', ->
16+
expectedCallback = ->
17+
getStoredCollection().find('testCollection', {'one': true }, expectedCallback)
1818

19-
it 'should call the adapter\'s find() method', ->
20-
callsToFind.should.have.length(1)
19+
it 'should call the adapter\'s find() method', ->
20+
callsToFind.should.have.length(1)
2121

22-
it 'should pass collection and attributes to the adapter', ->
23-
callsToFind[0].should.have.length(3)
24-
callsToFind[0][0].should.equal('testCollection')
25-
callsToFind[0][1].should.eql({ 'one': true })
26-
callsToFind[0][2].should.equal(callback)
22+
it 'should pass collection and attributes to the adapter', ->
23+
callsToFind[0].should.have.length(3)
24+
callsToFind[0][0].should.equal('testCollection')
25+
callsToFind[0][1].should.eql({ 'one': true })
26+
callsToFind[0][2].should.equal(expectedCallback)
27+
)
28+
)

test/data/storedObject.spec.coffee

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,25 @@ callsToSave = []
55

66
getStoredObject = () ->
77
storedObject = new StoredObject()
8-
storedObject._adapter =
8+
storedObject._adapter =
99
save: (collection, attributes, callback) ->
1010
callsToSave.push([collection, attributes, callback])
1111
callback(null, attributes)
1212
return storedObject
1313

14-
describe 'when save() is called on Base stored object (data/storedObject)', ->
15-
callback = ->
14+
describe('StoredObject (data/storedObject)', ->
15+
describe('when save() is called', ->
16+
expectedCallback = ->
1617

17-
getStoredObject().save('testCollection', {
18-
'one': true
19-
}, callback)
20-
21-
it 'should call the adapter\'s save() method', ->
22-
callsToSave.should.have.length(1)
23-
24-
it 'should pass collection and attributes to the adapter', ->
25-
callsToSave[0].should.have.length(3)
26-
callsToSave[0][0].should.equal('testCollection')
27-
callsToSave[0][1].should.eql({ 'one': true })
28-
callsToSave[0][2].should.equal(callback)
18+
getStoredObject().save('testCollection', { 'one': true }, expectedCallback)
19+
20+
it 'should call the adapter\'s save() method', ->
21+
callsToSave.should.have.length(1)
22+
23+
it 'should pass collection and attributes to the adapter', ->
24+
callsToSave[0].should.have.length(3)
25+
callsToSave[0][0].should.equal('testCollection')
26+
callsToSave[0][1].should.eql({ 'one': true })
27+
callsToSave[0][2].should.equal(expectedCallback)
28+
)
29+
)

0 commit comments

Comments
 (0)