Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added some tests + fixed problem where ready was called twice (and ea…

…rly).
  • Loading branch information...
commit 81534918f877805d4ccdd4dc1f4d0f19bbe8324e 1 parent 07550a8
@tmeasday tmeasday authored
Showing with 50 additions and 19 deletions.
  1. +2 −1  publish_with_relations.coffee
  2. +48 −18 publish_with_relations_test.coffee
View
3  publish_with_relations.coffee
@@ -31,6 +31,7 @@ Meteor.publishWithRelations = (params) ->
filter: mapFilter
options: mapOptions
mappings: mapping.mappings
+ _noReady: true
else
associations[id][objKey]?.stop()
associations[id][objKey] =
@@ -51,7 +52,7 @@ Meteor.publishWithRelations = (params) ->
removed: (id) ->
handle.stop() for handle in associations[id]
pub.removed(collection._name, id)
- pub.ready()
+ pub.ready() unless params._noReady
pub.onStop ->
for association in associations
View
66 publish_with_relations_test.coffee
@@ -1,41 +1,42 @@
# a 'publication' that just records stuff
class PubMock
constructor: () ->
- @activity = []
+ @activities = []
added: (name, id) ->
- console.log('added')
- @activity.push {type: 'added', collection: name, id: id}
+ @activities.push {type: 'added', collection: name, id: id}
changed: (name, id) ->
- @activity.push {type: 'changed', collection: name, id: id}
+ @activities.push {type: 'changed', collection: name, id: id}
removed: (name, id) ->
- @activity.push {type: 'removed', collection: name, id: id}
+ @activities.push {type: 'removed', collection: name, id: id}
ready: ->
- @activity.push {type: 'ready'}
+ @activities.push {type: 'ready'}
onStop: (cb) ->
- @onStop = cb
+ @_onStop = cb
stop: () ->
- @onStop() if @onStop
+ @_onStop() if @_onStop
-Tinytest.add "Publish with Relations: Nested subscriptions stop", (test) ->
- Boards = new Meteor.Collection 'boards'
- Lists = new Meteor.Collection 'lists'
- Tasks = new Meteor.Collection 'tasks'
+# 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
- # now 'publish'
- pub = new PubMock
- Meteor.publishWithRelations
- handle: pub
+ settings =
collection: Boards
filter: {}
@@ -50,6 +51,35 @@ Tinytest.add "Publish with Relations: Nested subscriptions stop", (test) ->
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
+
+
- # should have three added + a ready event
- test.equal pub.activity.length, 4
+
Please sign in to comment.
Something went wrong with that request. Please try again.