From 363a8d6e4fd129fd8ed29b7d40df11a69d029c8e Mon Sep 17 00:00:00 2001 From: Wojciech Zawistowski Date: Mon, 30 Sep 2013 21:46:42 +0200 Subject: [PATCH] adds unit tests for Discourse.HasCurrentUser --- .../mixins/has_current_user_test.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 test/javascripts/mixins/has_current_user_test.js diff --git a/test/javascripts/mixins/has_current_user_test.js b/test/javascripts/mixins/has_current_user_test.js new file mode 100644 index 00000000000..4eab06d27b1 --- /dev/null +++ b/test/javascripts/mixins/has_current_user_test.js @@ -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"); +});