Permalink
Browse files

Fix server-side `observe` with no `added` callback. Fixes #589.

The cursor de-dup code introduced in Meteor 0.5.1 had a bug where a server-side
`observe` with no `added` callback would throw an error if the `observe` was
de-duped.
  • Loading branch information...
1 parent 203a82d commit 95974f82fbc419a52c71c0de92a59b277b8c45b0 @glasser glasser committed Jan 3, 2013
Showing with 23 additions and 10 deletions.
  1. +2 −0 History.md
  2. +6 −4 packages/mongo-livedata/mongo_driver.js
  3. +15 −6 packages/mongo-livedata/mongo_livedata_tests.js
View
@@ -59,6 +59,8 @@
* Always use the `autoReconnect` flag when connecting to Mongo. #425
+* Fix server-side `observe` with no `added` callback. #589
+
* Fix re-sending method calls on reconnect. #538
* Remove deprecated `/sockjs` URL support from `Meteor.connect`.
@@ -715,10 +715,12 @@ _.extend(LiveResultsSet.prototype, {
--self._addHandleTasksScheduledButNotPerformed;
// Send initial adds.
- _.each(self._results, function (doc, i) {
- handle._added(LocalCollection._deepcopy(doc),
- self._ordered ? i : undefined);
- });
+ if (handle._added) {
+ _.each(self._results, function (doc, i) {
+ handle._added(LocalCollection._deepcopy(doc),
+ self._ordered ? i : undefined);
+ });
+ }
});
},
@@ -421,16 +421,19 @@ if (Meteor.isServer) {
var run = test.runId();
var coll = new Meteor.Collection("cursorDedup-"+run);
- var observer = function () {
+ var observer = function (noAdded) {
var output = [];
- var handle = coll.find({foo: 22}).observe({
- added: function (doc) {
- output.push({added: doc._id});
- },
+ var callbacks = {
changed: function (newDoc) {
output.push({changed: newDoc._id});
}
- });
+ };
+ if (!noAdded) {
+ callbacks.added = function (doc) {
+ output.push({added: doc._id});
+ };
+ }
+ var handle = coll.find({foo: 22}).observe(callbacks);
return {output: output, handle: handle};
};
@@ -510,7 +513,13 @@ if (Meteor.isServer) {
test.length(o2.output, 0);
// White-box: Different LiveResultsSet.
test.isTrue(liveResultsSet !== o3.handle._liveResultsSet);
+
+ // Start another handle with no added callback. Regression test for #589.
+ var o4 = observer(true);
+
o3.handle.stop();
+ o4.handle.stop();
+
onComplete();
});
}

0 comments on commit 95974f8

Please sign in to comment.