forked from Lepozepo/meteor-publish-with-relations
-
Notifications
You must be signed in to change notification settings - Fork 1
/
publish_with_relations_test.coffee
85 lines (59 loc) · 1.97 KB
/
publish_with_relations_test.coffee
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# a 'publication' that just records stuff
class PubMock
constructor: () ->
@activities = []
added: (name, id) ->
@activities.push {type: 'added', collection: name, id: id}
changed: (name, id) ->
@activities.push {type: 'changed', collection: name, id: id}
removed: (name, id) ->
@activities.push {type: 'removed', collection: name, id: id}
ready: ->
@activities.push {type: 'ready'}
onStop: (cb) ->
@_onStop = cb
stop: () ->
@_onStop() if @_onStop
# will be overwritten
Boards = Lists = Tasks = null
settings = null
prepare = (test) ->
run = test.runId()
Boards = new Meteor.Collection "boards_#{run}"
Lists = new Meteor.Collection "lists_#{run}"
Tasks = new Meteor.Collection "tasks_#{run}"
# insert some data
boardId = Boards.insert name: 'board'
listId = Lists.insert name: 'list', boardId: boardId
taskId = Tasks.insert name: 'task', listId: listId
settings =
collection: Boards
filter: {}
mappings: [{
collection: Lists
key: 'boardId'
reverse: true
mappings: [{
collection: Tasks
key: 'listId'
reverse: true
}]
}]
Tinytest.add "Publish with Relations: ready is only called once", (test) ->
prepare(test)
pub = new PubMock
Meteor.publishWithRelations _.extend(settings, {handle: pub})
readys = (activity for activity in pub.activities when activity.type == 'ready')
test.equal readys.length, 1
Tinytest.add "Publish with Relations: Nested subscriptions stop", (test) ->
prepare(test)
pub = new PubMock
Meteor.publishWithRelations _.extend(settings, {handle: pub})
count = pub.activities.length
# stop the sub, but then insert some more stuff
pub.stop()
boardId = Boards.insert name: 'new board'
listId = Lists.insert name: 'new list', boardId: boardId
taskId = Tasks.insert name: 'new task', listId: listId
# nothing new has happened
test.equal pub.activities.length, count