From 07007e6cbcac30ac0da2da19ca9f0b42043ee114 Mon Sep 17 00:00:00 2001 From: Robin Ward Date: Mon, 12 May 2014 14:01:21 -0400 Subject: [PATCH] ES6: Notification controllers, added helper to create via ES6/container --- ...notification_controller.js => notification.js.es6} | 2 +- .../discourse/controllers/notifications.js.es6 | 4 ++++ .../discourse/controllers/notifications_controller.js | 4 ---- .../controllers/notification_controller_test.js | 7 ++----- .../controllers/notifications_controller_test.js | 6 ++---- test/javascripts/helpers/qunit_helpers.js | 11 ++++++++++- 6 files changed, 19 insertions(+), 15 deletions(-) rename app/assets/javascripts/discourse/controllers/{notification_controller.js => notification.js.es6} (91%) create mode 100644 app/assets/javascripts/discourse/controllers/notifications.js.es6 delete mode 100644 app/assets/javascripts/discourse/controllers/notifications_controller.js diff --git a/app/assets/javascripts/discourse/controllers/notification_controller.js b/app/assets/javascripts/discourse/controllers/notification.js.es6 similarity index 91% rename from app/assets/javascripts/discourse/controllers/notification_controller.js rename to app/assets/javascripts/discourse/controllers/notification.js.es6 index 765ca1d85a..dc23b69362 100644 --- a/app/assets/javascripts/discourse/controllers/notification_controller.js +++ b/app/assets/javascripts/discourse/controllers/notification.js.es6 @@ -1,4 +1,4 @@ -Discourse.NotificationController = Discourse.ObjectController.extend({ +export default Discourse.ObjectController.extend({ scope: function() { return "notifications." + Discourse.Site.currentProp("notificationLookup")[this.get("notification_type")]; }.property(), diff --git a/app/assets/javascripts/discourse/controllers/notifications.js.es6 b/app/assets/javascripts/discourse/controllers/notifications.js.es6 new file mode 100644 index 0000000000..9276251382 --- /dev/null +++ b/app/assets/javascripts/discourse/controllers/notifications.js.es6 @@ -0,0 +1,4 @@ +export default Ember.ArrayController.extend(Discourse.HasCurrentUser, { + needs: ['header'], + itemController: "notification" +}); diff --git a/app/assets/javascripts/discourse/controllers/notifications_controller.js b/app/assets/javascripts/discourse/controllers/notifications_controller.js deleted file mode 100644 index 3f6738a15d..0000000000 --- a/app/assets/javascripts/discourse/controllers/notifications_controller.js +++ /dev/null @@ -1,4 +0,0 @@ -Discourse.NotificationsController = Ember.ArrayController.extend(Discourse.HasCurrentUser, { - needs: ['header'], - itemController: "notification" -}); diff --git a/test/javascripts/controllers/notification_controller_test.js b/test/javascripts/controllers/notification_controller_test.js index 2628a98036..e30aae5bbc 100644 --- a/test/javascripts/controllers/notification_controller_test.js +++ b/test/javascripts/controllers/notification_controller_test.js @@ -11,13 +11,10 @@ var notificationFixture = { }; var postUrlStub = "post-url-stub"; -module("Discourse.NotificationController", { +module("controller:notification", { setup: function() { sinon.stub(Discourse.Utilities, "postUrl").returns(postUrlStub); - - controller = Discourse.NotificationController.create({ - content: notificationFixture - }); + controller = testController('notification', notificationFixture); }, teardown: function() { diff --git a/test/javascripts/controllers/notifications_controller_test.js b/test/javascripts/controllers/notifications_controller_test.js index 35aae22680..8400dfe9ff 100644 --- a/test/javascripts/controllers/notifications_controller_test.js +++ b/test/javascripts/controllers/notifications_controller_test.js @@ -10,16 +10,14 @@ var noItemsMessageSelector = "div.none"; var itemListSelector = "ul"; var itemSelector = "li"; -module("Discourse.NotificationsController", { +module("controller:notifications", { setup: function() { sinon.stub(I18n, "t", function (scope, options) { options = options || {}; return [scope, options.username, options.link].join(" ").trim(); }); - controller = Discourse.NotificationsController.create({ - container: Discourse.__container__ - }); + controller = testController('notifications'); view = Ember.View.create({ container: Discourse.__container__, diff --git a/test/javascripts/helpers/qunit_helpers.js b/test/javascripts/helpers/qunit_helpers.js index 448adf8dff..b5b96263d1 100644 --- a/test/javascripts/helpers/qunit_helpers.js +++ b/test/javascripts/helpers/qunit_helpers.js @@ -1,4 +1,4 @@ -/* global asyncTest */ +/* global asyncTest, requirejs, require */ /* exported integration, testController, controllerFor, asyncTestDiscourse, fixture */ function integration(name, lifecycle) { module("Integration: " + name, { @@ -25,6 +25,15 @@ function integration(name, lifecycle) { } function testController(klass, model) { + // HAX until we get ES6 everywhere: + if (typeof klass === "string") { + var moduleName = 'discourse/controllers/' + klass, + module = requirejs.entries[moduleName]; + if (module) { + klass = require(moduleName, null, null, true).default; + } + } + return klass.create({model: model, container: Discourse.__container__}); }