From 4d257aa545385b8f062dd0348c1972dfde426040 Mon Sep 17 00:00:00 2001 From: Avital Oliver Date: Sat, 26 May 2012 03:03:32 -0700 Subject: [PATCH] Improve test for subscriptions on userid change The test service's subscriptions now have some data overlap for different users, verify that we indeed diff the query results correctly. --- packages/livedata/livedata_test_service.js | 15 ++++++++------- packages/livedata/livedata_tests.js | 13 ++++++------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/packages/livedata/livedata_test_service.js b/packages/livedata/livedata_test_service.js index 8671c56d2e..2984d73479 100644 --- a/packages/livedata/livedata_test_service.js +++ b/packages/livedata/livedata_test_service.js @@ -100,15 +100,16 @@ objectsWithUsers = new Meteor.Collection("objectsWithUsers"); if (Meteor.is_server) { objectsWithUsers.remove({}); - objectsWithUsers.insert({name: "owned by none", ownerUserId: null}); - objectsWithUsers.insert({name: "owned by one - a", ownerUserId: 1}); - objectsWithUsers.insert({name: "owned by one - b", ownerUserId: 1}); - objectsWithUsers.insert({name: "owned by two - a", ownerUserId: 2}); - objectsWithUsers.insert({name: "owned by two - b", ownerUserId: 2}); - objectsWithUsers.insert({name: "owned by two - c", ownerUserId: 2}); + objectsWithUsers.insert({name: "owned by none", ownerUserIds: [null]}); + objectsWithUsers.insert({name: "owned by one - a", ownerUserIds: [1]}); + objectsWithUsers.insert({name: "owned by one/two - a", ownerUserIds: [1, 2]}); + objectsWithUsers.insert({name: "owned by one/two - b", ownerUserIds: [1, 2]}); + objectsWithUsers.insert({name: "owned by two - a", ownerUserIds: [2]}); + objectsWithUsers.insert({name: "owned by two - b", ownerUserIds: [2]}); Meteor.publish("objectsWithUsers", function() { - return objectsWithUsers.find({ownerUserId: this.userId()}); + return objectsWithUsers.find({ownerUserIds: this.userId()}, + {fields: {ownerUserIds: 0}}); }); userIdWhenStopped = null; diff --git a/packages/livedata/livedata_tests.js b/packages/livedata/livedata_tests.js index d388ff3111..ee1d8e5d22 100644 --- a/packages/livedata/livedata_tests.js +++ b/packages/livedata/livedata_tests.js @@ -327,8 +327,9 @@ testAsyncMulti("livedata - changing userid reruns subscriptions without flapping testSetAndUnset([ {unset: true}, {set: "owned by one - a"}, - {set: "owned by one - b"}]); - test.equal(objectsWithUsers.find().count(), 2); + {set: "owned by one/two - a"}, + {set: "owned by one/two - b"}]); + test.equal(objectsWithUsers.find().count(), 3); Meteor.defer(sendSecondSetUserId); }); @@ -339,12 +340,10 @@ testAsyncMulti("livedata - changing userid reruns subscriptions without flapping var afterSecondSetUserId = expect(function() { testSetAndUnset([ - {unset: true}, {unset: true}, {set: "owned by two - a"}, - {set: "owned by two - b"}, - {set: "owned by two - c"}]); - test.equal(objectsWithUsers.find().count(), 3); + {set: "owned by two - b"}]); + test.equal(objectsWithUsers.find().count(), 4); Meteor.defer(sendThirdSetUserId); }); @@ -357,7 +356,7 @@ testAsyncMulti("livedata - changing userid reruns subscriptions without flapping // Nothing should have been sent since the results of the // query are the same ("don't flap data on the wire") testSetAndUnset([]); - test.equal(objectsWithUsers.find().count(), 3); + test.equal(objectsWithUsers.find().count(), 4); undoEavesdrop(); }); }