adds unit tests for Discourse.HasCurrentUser

This commit is contained in:
Wojciech Zawistowski 2013-09-30 21:46:42 +02:00
parent 3f0c03a20c
commit 363a8d6e4f
1 changed files with 19 additions and 0 deletions

View File

@ -0,0 +1,19 @@
module("Discourse.HasCurrentUser", {
setup: function() {
sinon.stub(Discourse.User, "current");
},
teardown: function() {
Discourse.User.current.restore();
}
});
test("adds `currentUser` property to an object and ensures it is not cached", function() {
var testObj = Ember.Object.createWithMixins(Discourse.HasCurrentUser, {});
Discourse.User.current.returns("first user");
equal(testObj.get("currentUser"), "first user", "on the first call property returns initial user");
Discourse.User.current.returns("second user");
equal(testObj.get("currentUser"), "second user", "if the user changes, on the second call property returns changed user");
});