test for added from two different subs

This commit is contained in:
Naomi Seyfer
2013-03-15 18:57:01 -07:00
parent a162d7c4d3
commit 83b99f8c8a
2 changed files with 84 additions and 0 deletions

View File

@@ -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) {

View File

@@ -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);