Skip to content

Commit 0565488

Browse files
committed
Switching testing framework to mocha from vows
2 parents d9f75da + 729ddac commit 0565488

18 files changed

+397
-91
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#Stalkqr
22

3-
[![Build Status](https://secure.travis-ci.org/joeandaverde/stalkqr.png?branch=master)](http://travis-ci.org/joeandaverde/stalkqr)
3+
[![Build Status](https://secure.travis-ci.org/adunkman/stalkqr.png?branch=master)](http://travis-ci.org/adunkman/stalkqr)
44

55
An open source project by the NodeKC group.
66

collections/tags.coffee

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
StoredCollection = require '../data/storedCollection'
2+
3+
class Tags extends StoredCollection
4+
constructor: () -> super
5+
6+
find: (criteria, callback) ->
7+
super(Tags._collectionName, criteria, callback)
8+
9+
Tags._collectionName = 'tags'
10+
module.exports = Tags

collections/users.coffee

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
StoredCollection = require '../data/storedCollection'
2+
3+
class Users extends StoredCollection
4+
constructor: () -> super
5+
6+
find: () ->
7+
if arguments.length is 1
8+
criteria = {}
9+
[callback] = arguments
10+
11+
if arguments.length is 2
12+
[criteria, callback] = arguments
13+
14+
super(Users._collectionName, criteria, callback)
15+
16+
all: (callback) ->
17+
@find(callback)
18+
19+
Users._collectionName = 'users'
20+
module.exports = Users

data/adapters/inMemory.coffee

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ class InMemoryDataAdapter
77
if attributes._id? then @update(collection, attributes, callback)
88
else @insert(collection, attributes, callback)
99

10-
find: (collection, parameters, callback) =>
10+
find: (collection, critera, callback) =>
1111
results = []
1212

1313
for item in @items[collection] || []
1414
allTrue = true
1515

16-
for name, value of parameters
16+
for name, value of critera
1717
if item[name] isnt value
1818
allTrue = false
1919

data/storedCollection.coffee

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
InMemoryDataAdapter = require './adapters/inMemory'
2+
3+
class StoredCollection
4+
constructor: () ->
5+
@_adapter = new InMemoryDataAdapter()
6+
7+
find: () ->
8+
if arguments.length is 2
9+
criteria = {}
10+
[collection, callback] = arguments
11+
12+
if arguments.length is 3
13+
[collection, criteria, callback] = arguments
14+
@_adapter.find(collection, criteria, callback)
15+
16+
module.exports = StoredCollection

data/storedObject.coffee

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
InMemoryDataAdapter = require './adapters/inMemory'
22

33
class StoredObject
4-
_adapter: new InMemoryDataAdapter()
4+
constructor: () ->
5+
@_adapter = new InMemoryDataAdapter()
56

67
save: (collection, attributes, callback) ->
78
@_adapter.save(collection, attributes, callback)

models/model.coffee

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,14 @@ StoredObject = require '../data/storedObject'
33

44
class Model extends StoredObject
55
constructor: (attributes) ->
6+
super
67
@attributes = clone(attributes) || {}
78

89
save: (collection, callback) ->
9-
super @collection, @toJSON(), callback
10+
super(collection, @toJSON(), (err, attributes) =>
11+
@attributes = attributes if not err?
12+
callback(err, attributes) if callback?
13+
)
1014

1115
toJSON: () ->
1216
clone(@attributes)

models/tag.coffee

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
Model = require './model'
2+
Code = require './codes'
3+
Tags = require '../collections/tags'
4+
5+
class Tag extends Model
6+
constructor: (attributes = {}) ->
7+
super
8+
@attributes._id or= undefined
9+
@attributes.user or= undefined
10+
@attributes.event or= undefined
11+
@attributes.generatedOn or= new Date()
12+
@attributes.code or= Code.generate()
13+
14+
save: (callback) ->
15+
super(Tags._collectionName, callback)
16+
17+
module.exports = Tag

models/user.coffee

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
Model = require './model'
2+
Users = require '../collections/users'
23

34
defaults =
45
slugs: []
@@ -7,19 +8,26 @@ defaults =
78

89
class User extends Model
910
constructor: (attributes = defaults) ->
10-
super attributes
11-
12-
setCredential: (provider, id) ->
11+
super
12+
@attributes._id or= undefined
13+
@attributes.name or= undefined
14+
@attributes.userSince or= undefined
15+
@attributes.slugs or= []
16+
@attributes.handles or= []
1317
@attributes.credentials or= []
14-
18+
19+
setCredential: (provider, id) ->
1520
existingAttributes = @attributes.credentials.filter (c) ->
1621
c.provider.toLowerCase().trim() == provider.toLowerCase().trim()
17-
22+
1823
if existingAttributes.length > 0
1924
existingAttributes[0].id = id
2025
else
2126
@attributes.credentials.push
2227
provider: provider
2328
id: id
29+
30+
save: (callback) ->
31+
super(Users._collectionName, callback)
2432

2533
module.exports = User

test/collections/tags_test.coffee

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
vows = require 'vows'
2+
should = require 'should'
3+
Tags = require '../../collections/tags'
4+
5+
vows.describe('Tags (collections/tags)').addBatch(
6+
'when find() is called with criteria and a callback': {
7+
topic: () -> getTags('test1').find({ 'one': true }, @callback)
8+
9+
'it should call find() in \'tags\' collection on base': (err, items) ->
10+
callsToFind.test1.should.have.length(1)
11+
callsToFind.test1[0].should.have.length(3)
12+
callsToFind.test1[0][0].should.equal('tags')
13+
14+
'it should call find() with criteria on base': (err, items) ->
15+
callsToFind.test1[0][1].should.eql({ 'one': true })
16+
}
17+
).export(module)
18+
19+
callsToFind = {}
20+
21+
getTags = (key) ->
22+
callsToFind[key] = []
23+
tags = new Tags()
24+
tags._adapter =
25+
find: (collection, criteria, callback) ->
26+
callsToFind[key].push([collection, criteria, callback])
27+
callback(null, [])
28+
return tags

0 commit comments

Comments
 (0)