Skip to content

Commit

Permalink
Improve test isolation in livedata_tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
glasser committed Nov 17, 2012
1 parent 6c19b05 commit e93e35c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 18 deletions.
12 changes: 6 additions & 6 deletions packages/livedata/livedata_test_service.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,20 +133,20 @@ if (Meteor.isServer) {
});

(function () {
var userIdWhenStopped = null;
Meteor.publish("recordUserIdOnStop", function() {
var self = this;
var userIdWhenStopped = {};
Meteor.publish("recordUserIdOnStop", function (key) {
var self = this;
self.onStop(function() {
userIdWhenStopped = self.userId;
userIdWhenStopped[key] = self.userId;
});
});

Meteor.methods({
setUserId: function(userId) {
this.setUserId(userId);
},
userIdWhenStopped: function() {
return userIdWhenStopped;
userIdWhenStopped: function (key) {
return userIdWhenStopped[key];
}
});
})();
Expand Down
24 changes: 12 additions & 12 deletions packages/livedata/livedata_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -285,9 +285,9 @@ var eavesdropOnCollection = function(livedata_connection,
};
};

testAsyncMulti("livedata - changing userid reruns subscriptions without flapping data on the wire", [
function(test, expect) {
if (Meteor.isClient) {
if (Meteor.isClient) {
testAsyncMulti("livedata - changing userid reruns subscriptions without flapping data on the wire", [
function(test, expect) {
var messages = [];
var undoEavesdrop = eavesdropOnCollection(
Meteor.default_connection, "objectsWithUsers", messages);
Expand Down Expand Up @@ -342,18 +342,18 @@ testAsyncMulti("livedata - changing userid reruns subscriptions without flapping
test.equal(objectsWithUsers.find().count(), 4);
undoEavesdrop();
});
}
}, function(test, expect) {
if (Meteor.isClient) {
Meteor.subscribe("recordUserIdOnStop");
Meteor.apply("setUserId", [100], {wait: true}, expect(function() {}));
Meteor.apply("setUserId", [101], {wait: true}, expect(function() {}));
Meteor.call("userIdWhenStopped", expect(function(err, result) {
}, function(test, expect) {
var key = Meteor.uuid();
Meteor.subscribe("recordUserIdOnStop", key);
Meteor.apply("setUserId", [100], {wait: true}, expect(function () {}));
Meteor.apply("setUserId", [101], {wait: true}, expect(function () {}));
Meteor.call("userIdWhenStopped", key, expect(function (err, result) {
test.isFalse(err);
test.equal(result, 100);
}));
}
}
]);
]);
}

Tinytest.add("livedata - setUserId error when called from server", function(test) {
if (Meteor.isServer) {
Expand Down

0 comments on commit e93e35c

Please sign in to comment.