From 135b8919df111bf591f176d5a50606d82c4e3536 Mon Sep 17 00:00:00 2001 From: David Mihal Date: Sun, 11 Dec 2016 21:48:52 +0200 Subject: [PATCH 1/2] Don't pass the callback to the handler The publish handler was being passed the callback function as an argument. This can cause issues with publish functions that set default values for the last parameter. --- publication-collector.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/publication-collector.js b/publication-collector.js index a016630..a872983 100755 --- a/publication-collector.js +++ b/publication-collector.js @@ -27,9 +27,6 @@ PublicationCollector = class PublicationCollector extends EventEmitter { } collect(name, ...args) { - const handler = Meteor.server.publish_handlers[name]; - const result = handler.call(this, ...args); - if (_.isFunction(args[args.length - 1])) { const callback = args.pop(); this.on('ready', collections => { @@ -38,6 +35,9 @@ PublicationCollector = class PublicationCollector extends EventEmitter { }); } + const handler = Meteor.server.publish_handlers[name]; + const result = handler.call(this, ...args); + // TODO -- we should check that result has _publishCursor? What does _runHandler do? if (result) { // array-ize From 1afc5fb2ddff9515955c5baa03cedef81e13176f Mon Sep 17 00:00:00 2001 From: David Mihal Date: Fri, 23 Dec 2016 12:03:07 +0200 Subject: [PATCH 2/2] Add test for not passing callback to handler --- tests/publication-collector.test.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tests/publication-collector.test.js b/tests/publication-collector.test.js index 82ef2f2..501a385 100644 --- a/tests/publication-collector.test.js +++ b/tests/publication-collector.test.js @@ -109,6 +109,18 @@ describe('PublicationCollector', () => { collector.collect('publicationWithArgs', 'foo', 'bar'); }); + + it('should support optional publication arguments', (done) => { + Meteor.publish('publicationWithOptionalArg', function(arg1 = 'foo') { + assert.equal(arg1, 'foo'); + this.ready(); + done(); + }); + + const collector = new PublicationCollector(); + + collector.collect('publicationWithOptionalArg', function(){}); + }); }); describe('Added', () => {