REFACTOR: Remove `Discourse` constant from `get-owner`

REFACTOR: Remove Discourse constant from get-owner

diff --git a/app/assets/javascripts/discourse-common/addon/lib/get-owner.js b/app/assets/javascripts/discourse-common/addon/lib/get-owner.js
index 0fd653b..23a7218 100644
--- a/app/assets/javascripts/discourse-common/addon/lib/get-owner.js
+++ b/app/assets/javascripts/discourse-common/addon/lib/get-owner.js
@@ -1,14 +1,20 @@
 import deprecated from "discourse-common/lib/deprecated";
-import { getOwner as emberGetOwner } from "@ember/application";
+import { getOwner as emberGetOwner, setOwner } from "@ember/application";
+
+let _default = {};
 
 export function getOwner(obj) {
   if (emberGetOwner) {
-    return emberGetOwner(obj) || Discourse.__container__;
+    return emberGetOwner(obj) || emberGetOwner(_default);
   }
 
   return obj.container;
 }
 
+export function setDefaultOwner(container) {
+  setOwner(_default, container);
+}
+
 // `this.container` is deprecated, but we can still build a container-like
 // object for components to use
 export function getRegister(obj) {
diff --git a/app/assets/javascripts/discourse/app/mixins/singleton.js b/app/assets/javascripts/discourse/app/mixins/singleton.js
index 5c4ac82..20b95f8 100644
--- a/app/assets/javascripts/discourse/app/mixins/singleton.js
+++ b/app/assets/javascripts/discourse/app/mixins/singleton.js
@@ -82,6 +82,7 @@ const Singleton = Mixin.create({
 
   resetCurrent(val) {
     this._current = val;
+    return val;
   }
 });
 
diff --git a/app/assets/javascripts/discourse/app/pre-initializers/discourse-bootstrap.js b/app/assets/javascripts/discourse/app/pre-initializers/discourse-bootstrap.js
index 3cfabb5..d8772f3 100644
--- a/app/assets/javascripts/discourse/app/pre-initializers/discourse-bootstrap.js
+++ b/app/assets/javascripts/discourse/app/pre-initializers/discourse-bootstrap.js
@@ -14,6 +14,7 @@ import { setIconList } from "discourse-common/lib/icon-library";
 import { setPluginContainer } from "discourse/lib/plugin-api";
 import { setURLContainer } from "discourse/lib/url";
 import { setModalContainer } from "discourse/lib/show-modal";
+import { setDefaultOwner } from "discourse-common/lib/get-owner";
 
 export default {
   name: "discourse-bootstrap",
@@ -23,6 +24,7 @@ export default {
     setPluginContainer(container);
     setURLContainer(container);
     setModalContainer(container);
+    setDefaultOwner(container);
 
     // Our test environment has its own bootstrap code
     if (isTesting()) {
diff --git a/test/javascripts/admin/components/themes-list-item-test.js b/test/javascripts/admin/components/themes-list-item-test.js
index 134cf6c..5235d8f 100644
--- a/test/javascripts/admin/components/themes-list-item-test.js
+++ b/test/javascripts/admin/components/themes-list-item-test.js
@@ -53,17 +53,21 @@ componentTest("broken theme", {
   }
 });
 
-const childrenList = [1, 2, 3, 4, 5].map(num =>
-  Theme.create({ name: `Child ${num}`, component: true })
-);
-
 componentTest("with children", {
   template: "{{themes-list-item theme=theme}}",
 
   beforeEach() {
+    this.childrenList = [1, 2, 3, 4, 5].map(num =>
+      Theme.create({ name: `Child ${num}`, component: true })
+    );
+
     this.set(
       "theme",
-      Theme.create({ name: "Test", childThemes: childrenList, default: true })
+      Theme.create({
+        name: "Test",
+        childThemes: this.childrenList,
+        default: true
+      })
     );
   },
 
@@ -76,7 +80,7 @@ componentTest("with children", {
         .split(",")
         .map(n => n.trim())
         .join(","),
-      childrenList
+      this.childrenList
         .splice(0, 4)
         .map(theme => theme.get("name"))
         .join(","),
diff --git a/test/javascripts/admin/components/themes-list-test.js b/test/javascripts/admin/components/themes-list-test.js
index 8a2d595..2fc6856 100644
--- a/test/javascripts/admin/components/themes-list-test.js
+++ b/test/javascripts/admin/components/themes-list-test.js
@@ -4,25 +4,24 @@ import Theme, { THEMES, COMPONENTS } from "admin/models/theme";
 
 moduleForComponent("themes-list", { integration: true });
 
-const themes = [1, 2, 3, 4, 5].map(num =>
-  Theme.create({ name: `Theme ${num}` })
-);
-const components = [1, 2, 3, 4, 5].map(num =>
-  Theme.create({
-    name: `Child ${num}`,
-    component: true,
-    parentThemes: [themes[num - 1]],
-    parent_themes: [1, 2, 3, 4, 5]
-  })
-);
-
 componentTest("current tab is themes", {
   template:
     "{{themes-list themes=themes components=components currentTab=currentTab}}",
   beforeEach() {
+    this.themes = [1, 2, 3, 4, 5].map(num =>
+      Theme.create({ name: `Theme ${num}` })
+    );
+    this.components = [1, 2, 3, 4, 5].map(num =>
+      Theme.create({
+        name: `Child ${num}`,
+        component: true,
+        parentThemes: [this.themes[num - 1]],
+        parent_themes: [1, 2, 3, 4, 5]
+      })
+    );
     this.setProperties({
-      themes,
-      components,
+      themes: this.themes,
+      components: this.components,
       currentTab: THEMES
     });
   },
@@ -46,10 +45,10 @@ componentTest("current tab is themes", {
     );
     assert.equal(find(".themes-list-item").length, 5, "displays all themes");
 
-    [2, 3].forEach(num => themes[num].set("user_selectable", true));
-    themes[4].set("default", true);
-    this.set("themes", themes);
-    const names = [4, 2, 3, 0, 1].map(num => themes[num].get("name")); // default theme always on top, followed by user-selectable ones and then the rest
+    [2, 3].forEach(num => this.themes[num].set("user_selectable", true));
+    this.themes[4].set("default", true);
+    this.set("themes", this.themes);
+    const names = [4, 2, 3, 0, 1].map(num => this.themes[num].get("name")); // default theme always on top, followed by user-selectable ones and then the rest
     assert.deepEqual(
       Array.from(find(".themes-list-item").find(".name")).map(node =>
         node.innerText.trim()
@@ -63,8 +62,8 @@ componentTest("current tab is themes", {
       "the separator is in the right location"
     );
 
-    themes.forEach(theme => theme.set("user_selectable", true));
-    this.set("themes", themes);
+    this.themes.forEach(theme => theme.set("user_selectable", true));
+    this.set("themes", this.themes);
     assert.equal(
       find(".inactive-indicator").index(),
       -1,
@@ -91,9 +90,20 @@ componentTest("current tab is components", {
   template:
     "{{themes-list themes=themes components=components currentTab=currentTab}}",
   beforeEach() {
+    this.themes = [1, 2, 3, 4, 5].map(num =>
+      Theme.create({ name: `Theme ${num}` })
+    );
+    this.components = [1, 2, 3, 4, 5].map(num =>
+      Theme.create({
+        name: `Child ${num}`,
+        component: true,
+        parentThemes: [this.themes[num - 1]],
+        parent_themes: [1, 2, 3, 4, 5]
+      })
+    );
     this.setProperties({
-      themes,
-      components,
+      themes: this.themes,
+      components: this.components,
       currentTab: COMPONENTS
     });
   },
diff --git a/test/javascripts/helpers/qunit-helpers.js b/test/javascripts/helpers/qunit-helpers.js
index 70f8a27..931d09d 100644
--- a/test/javascripts/helpers/qunit-helpers.js
+++ b/test/javascripts/helpers/qunit-helpers.js
@@ -30,6 +30,7 @@ import { getOwner } from "discourse-common/lib/get-owner";
 import { setTopicList } from "discourse/lib/topic-list-tracker";
 import { setURLContainer } from "discourse/lib/url";
 import { setModalContainer } from "discourse/lib/show-modal";
+import { setDefaultOwner } from "discourse-common/lib/get-owner";
 
 export function currentUser() {
   return User.create(sessionFixtures["/session/current.json"].current_user);
@@ -166,18 +167,21 @@ export function acceptance(name, options) {
       }
       this.siteSettings = currentSettings();
 
-      if (options.site) {
-        resetSite(currentSettings(), options.site);
-      }
-
       clearOutletCache();
       clearHTMLCache();
       resetPluginApi();
+
       Discourse.reset();
       this.container = getOwner(this);
       setPluginContainer(this.container);

[... diff too long, it was truncated ...]

GitHub sha: 347a4981

This commit appears in #10480 which was merged by eviltrout.