Skip to content

Commit

Permalink
Merge pull request #7 from johanbrook/fix/array-collections
Browse files Browse the repository at this point in the history
Return empty array when publication returns empty cursor
  • Loading branch information
johanbrook authored Sep 9, 2016
2 parents 757921a + b2d0fa1 commit 1170b19
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@
},
"devDependencies": {
"babel-preset-es2015": "^6.3.13",
"eslint": "^2.10.2",
"babel-eslint": "^6.0.0",
"eslint": "^3.3.0",
"eslint-config-lookback": "lookback/eslint-config-lookback",
"eslint-formatter-pretty": "^0.2.0"
}
Expand Down
8 changes: 7 additions & 1 deletion publication-collector.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,13 @@ PublicationCollector = class PublicationCollector extends EventEmitter {
// TODO -- we should check that result has _publishCursor? What does _runHandler do?
if (result) {
// array-ize
[].concat(result).forEach(cur => cur._publishCursor(this));
[].concat(result).forEach(cur => {
if (cur._cursorDescription && cur._cursorDescription.collectionName) {
this._ensureCollectionInRes(cur._cursorDescription.collectionName);
}

cur._publishCursor(this);
});
this.ready();
}
}
Expand Down
14 changes: 14 additions & 0 deletions tests/publication-collector.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ describe('PublicationCollector', () => {

afterEach(() => {
Documents.remove({});
Documents.find().fetch();
_.times(10, () => Documents.insert({foo: 'bar'}));
});

Expand Down Expand Up @@ -50,6 +51,19 @@ describe('PublicationCollector', () => {
});
});

it('should return an empty array for when there are no documents', (done) => {
Documents.remove({});
assert.equal(Documents.find().fetch().length, 0);

const collector = new PublicationCollector();

collector.collect('publication', collections => {
assert.typeOf(collections.documents, 'array');
assert.equal(collections.documents.length, 0);
done();
});
});

it('should pass the correct scope to the publication', (done) => {
const collector = new PublicationCollector({userId: 'foo'});

Expand Down

0 comments on commit 1170b19

Please sign in to comment.