From 83b99f8c8a513970fb856da36f0345288604d680 Mon Sep 17 00:00:00 2001 From: Naomi Seyfer Date: Fri, 15 Mar 2013 18:57:01 -0700 Subject: [PATCH] test for added from two different subs --- packages/livedata/livedata_tests.js | 65 +++++++++++++++++++++++++ packages/livedata/session_view_tests.js | 19 ++++++++ 2 files changed, 84 insertions(+) diff --git a/packages/livedata/livedata_tests.js b/packages/livedata/livedata_tests.js index 02a8f9a6a4..ac1b4ae1ab 100644 --- a/packages/livedata/livedata_tests.js +++ b/packages/livedata/livedata_tests.js @@ -400,6 +400,71 @@ Tinytest.add("livedata - setUserId error when called from server", function(test } }); + +if (Meteor.isServer) { + var pubHandles = {}; +}; +Meteor.methods({ + "livedata/setup" : function (id) { + if (Meteor.isServer) { + pubHandles[id] = {}; + Meteor.publish("pub1"+id, function () { + pubHandles[id].pub1 = this; + this.ready(); + }); + Meteor.publish("pub2"+id, function () { + pubHandles[id].pub2 = this; + this.ready(); + }); + + } + }, + "livedata/pub1go" : function (id) { + if (Meteor.isServer) { + + pubHandles[id].pub1.added("MultiPubCollection" + id, "foo", {a: "aa"}); + return 1; + } + return 0; + }, + "livedata/pub2go" : function (id) { + if (Meteor.isServer) { + pubHandles[id].pub2.added("MultiPubCollection" + id , "foo", {b: "bb"}); + return 2; + } + return 0; + } +}); + +if (Meteor.isClient) { + (function () { + var MultiPub; + var id = Random.id(); + testAsyncMulti("livedata - added from two different subs", [ + function (test, expect) { + Meteor.call('livedata/setup', id, expect(function () {})); + }, + function (test, expect) { + MultiPub = new Meteor.Collection("MultiPubCollection" + id); + var sub1 = Meteor.subscribe("pub1"+id, expect(function () {})); + var sub2 = Meteor.subscribe("pub2"+id, expect(function () {})); + }, + function (test, expect) { + Meteor.call("livedata/pub1go", id, expect(function (err, res) {test.equal(res, 1);})); + }, + function (test, expect) { + test.equal(MultiPub.findOne("foo"), {_id: "foo", a: "aa"}); + }, + function (test, expect) { + Meteor.call("livedata/pub2go", id, expect(function (err, res) {test.equal(res, 2);})); + }, + function (test, expect) { + test.equal(MultiPub.findOne("foo"), {_id: "foo", a: "aa", b: "bb"}); + } + ]); + })(); +}; + if (Meteor.isClient) { testAsyncMulti("livedata - overlapping universal subs", [ function (test, expect) { diff --git a/packages/livedata/session_view_tests.js b/packages/livedata/session_view_tests.js index 3e9b71aac6..ad6f09e2db 100644 --- a/packages/livedata/session_view_tests.js +++ b/packages/livedata/session_view_tests.js @@ -52,6 +52,25 @@ Tinytest.add('livedata - sessionview - exists reveal', function (test) { v.expectNoResult(); }); +Tinytest.add('livedata - sessionview - added a second field in another sub', function (test) { + var v = newView(test); + + v.added("A", "A1", {a: "foo"}); + v.expectResult({fun: 'added', id: "A1", fields: {a: "foo"}}); + v.expectNoResult(); + + v.added("B", "A1", {a: "foo", b: "bar"}); + v.expectResult({fun: 'changed', 'id': "A1", changed: {b: "bar"}}); + + v.removed("A", "A1"); + v.expectNoResult(); + + v.removed("B", "A1"); + v.expectResult({fun: 'removed', id: "A1"}); + v.expectNoResult(); +}); + + Tinytest.add('livedata - sessionview - field reveal', function (test) { var v = newView(test);