A platform for community discussion. Free, open, simple.
DEV: Use `store.createRecord` for Topic models (#18837)
Jarek Radoszf61e36384fea
diff --git a/app/assets/javascripts/discourse/app/components/user-menu/messages-list.js b/app/assets/javascripts/discourse/app/components/user-menu/messages-list.jsindex 192967c3ca0..1b04b491458 100644--- a/app/assets/javascripts/discourse/app/components/user-menu/messages-list.js+++ b/app/assets/javascripts/discourse/app/components/user-menu/messages-list.js@@ -7,8 +7,11 @@ import UserMenuNotificationItem from "discourse/lib/user-menu/notification-item"import UserMenuMessageItem from "discourse/lib/user-menu/message-item";import Topic from "discourse/models/topic";import { mergeSortedLists } from "discourse/lib/utilities";+import { inject as service } from "@ember/service";export default class UserMenuMessagesList extends UserMenuNotificationsList {+ @service store;+get dismissTypes() {return this.filterByTypes;}@@ -22,7 +25,7 @@ export default class UserMenuMessagesList extends UserMenuNotificationsList {}get showDismiss() {- return this.#unreadMessaagesNotifications > 0;+ return this.#unreadMessagesNotifications > 0;}get dismissTitle() {@@ -37,7 +40,7 @@ export default class UserMenuMessagesList extends UserMenuNotificationsList {return "user-menu/messages-list-empty-state";}- get #unreadMessaagesNotifications() {+ get #unreadMessagesNotifications() {const key = `grouped_unread_notifications.${this.site.notification_types.private_message}`;// we're retrieving the value with get() so that Ember tracks the property// and re-renders the UI when it changes.@@ -66,7 +69,7 @@ export default class UserMenuMessagesList extends UserMenuNotificationsList {);});- const topics = data.topics.map((t) => Topic.create(t));+ const topics = data.topics.map((t) => this.store.createRecord("topic", t));await Topic.applyTransformations(topics);const readNotifications = await Notification.initializeNotifications(@@ -100,7 +103,7 @@ export default class UserMenuMessagesList extends UserMenuNotificationsList {modalController.set("confirmationMessage",I18n.t("notifications.dismiss_confirmation.body.messages", {- count: this.#unreadMessaagesNotifications,+ count: this.#unreadMessagesNotifications,}));return modalController;diff --git a/app/assets/javascripts/discourse/tests/integration/components/select-kit/pinned-options-test.js b/app/assets/javascripts/discourse/tests/integration/components/select-kit/pinned-options-test.jsindex 0d436f578cb..f952008a6a1 100644--- a/app/assets/javascripts/discourse/tests/integration/components/select-kit/pinned-options-test.js+++ b/app/assets/javascripts/discourse/tests/integration/components/select-kit/pinned-options-test.js@@ -1,29 +1,27 @@import { module, test } from "qunit";import { setupRenderingTest } from "discourse/tests/helpers/component-test";import { render } from "@ember/test-helpers";-import Topic from "discourse/models/topic";import { hbs } from "ember-cli-htmlbars";import selectKit from "discourse/tests/helpers/select-kit-helper";--const buildTopic = function (pinned = true) {- return Topic.create({- id: 1234,- title: "Qunit Test Topic",- deleted_at: new Date(),- pinned,- });-};+import { getOwner } from "discourse-common/lib/get-owner";module("Integration | Component | select-kit/pinned-options", function (hooks) {setupRenderingTest(hooks);- hooks.beforeEach(function () {- this.set("subject", selectKit());- });-test("unpinning", async function (assert) {this.siteSettings.automatically_unpin_topics = false;- this.set("topic", buildTopic());+ this.set("subject", selectKit());++ const store = getOwner(this).lookup("service:store");+ this.set(+ "topic",+ store.createRecord("topic", {+ id: 1234,+ title: "Qunit Test Topic",+ deleted_at: new Date(),+ pinned: true,+ })+ );await render(hbs`<PinnedOptions @value={{this.topic.pinned}} @topic={{this.topic}} />`@@ -39,7 +37,17 @@ module("Integration | Component | select-kit/pinned-options", function (hooks) {test("pinning", async function (assert) {this.siteSettings.automatically_unpin_topics = false;- this.set("topic", buildTopic(false));+ this.set("subject", selectKit());+ const store = getOwner(this).lookup("service:store");+ this.set(+ "topic",+ store.createRecord("topic", {+ id: 1234,+ title: "Qunit Test Topic",+ deleted_at: new Date(),+ pinned: false,+ })+ );await render(hbs`<PinnedOptions @value={{this.topic.pinned}} @topic={{this.topic}} />`diff --git a/app/assets/javascripts/discourse/tests/integration/components/select-kit/topic-notifications-button-test.js b/app/assets/javascripts/discourse/tests/integration/components/select-kit/topic-notifications-button-test.jsindex 1a507c33ec4..d605269d556 100644--- a/app/assets/javascripts/discourse/tests/integration/components/select-kit/topic-notifications-button-test.js+++ b/app/assets/javascripts/discourse/tests/integration/components/select-kit/topic-notifications-button-test.js@@ -2,15 +2,14 @@ import { module, test } from "qunit";import { setupRenderingTest } from "discourse/tests/helpers/component-test";import { render } from "@ember/test-helpers";import I18n from "I18n";-import Topic from "discourse/models/topic";import { query } from "discourse/tests/helpers/qunit-helpers";import { hbs } from "ember-cli-htmlbars";import selectKit from "discourse/tests/helpers/select-kit-helper";+import { getOwner } from "discourse-common/lib/get-owner";-const buildTopic = function (opts) {- return Topic.create({+function buildTopic(opts) {+ return this.store.createRecord("topic", {id: 4563,- }).updateFromJson({title: "Qunit Test Topic",details: {notification_level: opts.level,@@ -20,7 +19,7 @@ const buildTopic = function (opts) {category_id: opts.category_id || null,tags: opts.tags || [],});-};+}const originalTranslation =I18n.translations.en.js.topic.notifications.tracking_pm.title;@@ -30,13 +29,17 @@ module(function (hooks) {setupRenderingTest(hooks);+ hooks.beforeEach(function () {+ this.store = getOwner(this).lookup("service:store");+ });+hooks.afterEach(function () {I18n.translations.en.js.topic.notifications.tracking_pm.title =originalTranslation;});test("the header has a localized title", async function (assert) {- this.set("topic", buildTopic({ level: 1 }));+ this.set("topic", buildTopic.call(this, { level: 1 }));await render(hbs`<TopicNotificationsButton@@ -51,7 +54,7 @@ module("it has the correct label");- this.set("topic", buildTopic({ level: 2 }));+ this.set("topic", buildTopic.call(this, { level: 2 }));assert.strictEqual(selectKit().header().label(),@@ -62,7 +65,10 @@ module(test("the header has a localized title", async function (assert) {I18n.translations.en.js.topic.notifications.tracking_pm.title = `${originalTranslation} PM`;- this.set("topic", buildTopic({ level: 2, archetype: "private_message" }));+ this.set(+ "topic",+ buildTopic.call(this, { level: 2, archetype: "private_message" })+ );await render(hbs`<TopicNotificationsButton@@ -80,7 +86,7 @@ module(test("notification reason text - user mailing list mode", async function (assert) {this.currentUser.set("mailing_list_mode", true);- this.set("topic", buildTopic({ level: 2 }));+ this.set("topic", buildTopic.call(this, { level: 2 }));await render(hbs`<TopicNotificationsButton@@ -97,7 +103,7 @@ module(});test("notification reason text - bad notification reason", async function (assert) {- this.set("topic", buildTopic({ level: 2 }));+ this.set("topic", buildTopic.call(this, { level: 2 }));await render(hbs`<TopicNotificationsButton@@ -106,7 +112,7 @@ module(/>`);- this.set("topic", buildTopic({ level: 3, reason: 999 }));+ this.set("topic", buildTopic.call(this, { level: 3, reason: 999 }));assert.strictEqual(query(".topic-notifications-button .text").innerText,@@ -117,7 +123,10 @@ module(test("notification reason text - user tracking category", async function (assert) {this.currentUser.set("tracked_category_ids", [88]);- this.set("topic", buildTopic({ level: 2, reason: 8, category_id: 88 }));+ this.set(+ "topic",+ buildTopic.call(this, { level: 2, reason: 8, category_id: 88 })+ );await render(hbs`<TopicNotificationsButton@@ -135,7 +144,10 @@ module(test("notification reason text - user no longer tracking category", async function (assert) {this.currentUser.set("tracked_category_ids", []);- this.set("topic", buildTopic({ level: 2, reason: 8, category_id: 88 }));+ this.set(+ "topic",+ buildTopic.call(this, { level: 2, reason: 8, category_id: 88 })+ );await render(hbs`<TopicNotificationsButton@@ -153,7 +165,10 @@ module(test("notification reason text - user watching category", async function (assert) {this.currentUser.set("watched_category_ids", [88]);- this.set("topic", buildTopic({ level: 3, reason: 6, category_id: 88 }));+ this.set(+ "topic",+ buildTopic.call(this, { level: 3, reason: 6, category_id: 88 })+ );await render(hbs`<TopicNotificationsButton@@ -171,7 +186,10 @@ module(test("notification reason text - user no longer watching category", async function (assert) {this.currentUser.set("watched_category_ids", []);- this.set("topic", buildTopic({ level: 3, reason: 6, category_id: 88 }));+ this.set(+ "topic",+ buildTopic.call(this, { level: 3, reason: 6, category_id: 88 })+ );await render(hbs`<TopicNotificationsButton@@ -189,7 +207,10 @@ module(test("notification reason text - user watching tag", async function (assert) {this.currentUser.set("watched_tags", ["test"]);- this.set("topic", buildTopic({ level: 3, reason: 10, tags: ["test"] }));+ this.set(+ "topic",+ buildTopic.call(this, { level: 3, reason: 10, tags: ["test"] })+ );await render(hbs`<TopicNotificationsButton@@ -207,7 +228,10 @@ module(test("notification reason text - user no longer watching tag", async function (assert) {this.currentUser.set("watched_tags", []);- this.set("topic", buildTopic({ level: 3, reason: 10, tags: ["test"] }));+ this.set(+ "topic",+ buildTopic.call(this, { level: 3, reason: 10, tags: ["test"] })+ );await render(hbs`<TopicNotificationsButtondiff --git a/app/assets/javascripts/discourse/tests/integration/components/select-kit/topic-notifications-options-test.js b/app/assets/javascripts/discourse/tests/integration/components/select-kit/topic-notifications-options-test.jsindex c0e55a3664c..f83006c9c60 100644--- a/app/assets/javascripts/discourse/tests/integration/components/select-kit/topic-notifications-options-test.js+++ b/app/assets/javascripts/discourse/tests/integration/components/select-kit/topic-notifications-options-test.js@@ -2,21 +2,9 @@ import { module, test } from "qunit";import { setupRenderingTest } from "discourse/tests/helpers/component-test";import { render } from "@ember/test-helpers";import I18n from "I18n";-import Topic from "discourse/models/topic";import { hbs } from "ember-cli-htmlbars";import selectKit from "discourse/tests/helpers/select-kit-helper";--const buildTopic = function (archetype) {- return Topic.create({- id: 4563,- }).updateFromJson({- title: "Qunit Test Topic",- details: {- notification_level: 1,- },- archetype,- });-};+import { getOwner } from "discourse-common/lib/get-owner";function extractDescriptions(rows) {return [...rows].map((el) => el.querySelector(".desc").textContent.trim());@@ -34,7 +22,18 @@ module(setupRenderingTest(hooks);test("regular topic notification level descriptions", async function (assert) {- this.set("topic", buildTopic("regular"));+ const store = getOwner(this).lookup("service:store");+ this.set(+ "topic",+ store.createRecord("topic", {+ id: 4563,+ title: "Qunit Test Topic",+ archetype: "regular",+ details: {+ notification_level: 1,+ },+ })+ );await render(hbs`<TopicNotificationsOptions@@ -64,7 +63,18 @@ module(});test("PM topic notification level descriptions", async function (assert) {- this.set("topic", buildTopic("private_message"));+ const store = getOwner(this).lookup("service:store");+ this.set(+ "topic",+ store.createRecord("topic", {+ id: 4563,+ title: "Qunit Test Topic",+ archetype: "private_message",+ details: {+ notification_level: 1,+ },+ })+ );await render(hbs`<TopicNotificationsOptionsdiff --git a/app/assets/javascripts/discourse/tests/integration/components/topic-list-item-test.js b/app/assets/javascripts/discourse/tests/integration/components/topic-list-item-test.jsindex e9b0348e128..bd484fea49b 100644--- a/app/assets/javascripts/discourse/tests/integration/components/topic-list-item-test.js+++ b/app/assets/javascripts/discourse/tests/integration/components/topic-list-item-test.js@@ -2,15 +2,16 @@ import { module, test } from "qunit";import { setupRenderingTest } from "discourse/tests/helpers/component-test";import { render } from "@ember/test-helpers";import { queryAll } from "discourse/tests/helpers/qunit-helpers";-import Topic from "discourse/models/topic";import { hbs } from "ember-cli-htmlbars";+import { getOwner } from "discourse-common/lib/get-owner";module("Integration | Component | topic-list-item", function (hooks) {setupRenderingTest(hooks);test("checkbox is rendered checked if topic is in selected array", async function (assert) {- const topic = Topic.create({ id: 24234 });- const topic2 = Topic.create({ id: 24235 });+ const store = getOwner(this).lookup("service:store");+ const topic = store.createRecord("topic", { id: 24234 });+ const topic2 = store.createRecord("topic", { id: 24235 });this.setProperties({topic,topic2,diff --git a/app/assets/javascripts/discourse/tests/integration/components/topic-list-test.js b/app/assets/javascripts/discourse/tests/integration/components/topic-list-test.jsindex 0e909f8bb25..36b52b1c71c 100644--- a/app/assets/javascripts/discourse/tests/integration/components/topic-list-test.js+++ b/app/assets/javascripts/discourse/tests/integration/components/topic-list-test.js@@ -1,15 +1,19 @@import { module, test } from "qunit";import { setupRenderingTest } from "discourse/tests/helpers/component-test";import { click, render } from "@ember/test-helpers";-import Topic from "discourse/models/topic";import { hbs } from "ember-cli-htmlbars";+import { getOwner } from "discourse-common/lib/get-owner";module("Integration | Component | topic-list", function (hooks) {setupRenderingTest(hooks);test("bulk select", async function (assert) {+ const store = getOwner(this).lookup("service:store");this.setProperties({- topics: [Topic.create({ id: 24234 }), Topic.create({ id: 24235 })],+ topics: [+ store.createRecord("topic", { id: 24234 }),+ store.createRecord("topic", { id: 24235 }),+ ],selected: [],bulkSelectEnabled: false,autoAddTopicsToBulkSelect: false,diff --git a/app/assets/javascripts/discourse/tests/integration/components/user-menu/messages-list-test.js b/app/assets/javascripts/discourse/tests/integration/components/user-menu/messages-list-test.jsindex 49de60fb0c8..cfee3b6fe9c 100644--- a/app/assets/javascripts/discourse/tests/integration/components/user-menu/messages-list-test.js+++ b/app/assets/javascripts/discourse/tests/integration/components/user-menu/messages-list-test.js@@ -171,14 +171,17 @@ module("Integration | Component | user-menu | messages-list", function (hooks) {copy.unread_notifications = [];copy.topics = [getMessage({+ id: 8090,bumped_at: "2014-07-26T01:29:24.177Z",fancy_title: "Test Topic 0003",}),getMessage({+ id: 8091,bumped_at: "2012-07-26T01:29:24.177Z",fancy_title: "Test Topic 0002",}),getMessage({+ id: 8092,bumped_at: "2010-07-26T01:29:24.177Z",fancy_title: "Test Topic 0001",}),diff --git a/app/assets/javascripts/discourse/tests/integration/components/widgets/post-stream-test.js b/app/assets/javascripts/discourse/tests/integration/components/widgets/post-stream-test.jsindex 81f9c543079..279f5cf9944 100644--- a/app/assets/javascripts/discourse/tests/integration/components/widgets/post-stream-test.js+++ b/app/assets/javascripts/discourse/tests/integration/components/widgets/post-stream-test.js@@ -4,7 +4,7 @@ import { render } from "@ember/test-helpers";import { count } from "discourse/tests/helpers/qunit-helpers";import { hbs } from "ember-cli-htmlbars";import Post from "discourse/models/post";-import Topic from "discourse/models/topic";+import { getOwner } from "discourse-common/lib/get-owner";function postStreamTest(name, attrs) {test(name, async function (assert) {@@ -27,8 +27,10 @@ module("Integration | Component | Widget | post-stream", function (hooks) {postStreamTest("basics", {posts() {const site = this.container.lookup("service:site");- const topic = Topic.create();+ const store = getOwner(this).lookup("service:store");+ const topic = store.createRecord("topic");topic.set("details.created_by", { id: 123 });+return [Post.create({topic,@@ -126,8 +128,10 @@ module("Integration | Component | Widget | post-stream", function (hooks) {postStreamTest("deleted posts", {posts() {- const topic = Topic.create();+ const store = getOwner(this).lookup("service:store");+ const topic = store.createRecord("topic");topic.set("details.created_by", { id: 123 });+return [Post.create({topic,diff --git a/app/assets/javascripts/discourse/tests/integration/components/widgets/topic-admin-menu-test.js b/app/assets/javascripts/discourse/tests/integration/components/widgets/topic-admin-menu-test.jsindex a5af0938f61..83de8824037 100644--- a/app/assets/javascripts/discourse/tests/integration/components/widgets/topic-admin-menu-test.js+++ b/app/assets/javascripts/discourse/tests/integration/components/widgets/topic-admin-menu-test.js@@ -4,7 +4,7 @@ import { render } from "@ember/test-helpers";import { exists } from "discourse/tests/helpers/qunit-helpers";import { hbs } from "ember-cli-htmlbars";import Category from "discourse/models/category";-import Topic from "discourse/models/topic";+import { getOwner } from "discourse-common/lib/get-owner";const createArgs = (topic) => {return {@@ -36,8 +36,13 @@ module(moderator: true,id: 123,});- const topic = Topic.create({ user_id: this.currentUser.id });++ const store = getOwner(this).lookup("service:store");+ const topic = store.createRecord("topic", {+ user_id: this.currentUser.id,+ });topic.set("category_id", Category.create({ read_restricted: true }).id);+this.siteSettings.allow_featured_topic_on_user_profiles = true;this.set("args", createArgs(topic));@@ -54,8 +59,13 @@ module(moderator: false,id: 123,});- const topic = Topic.create({ user_id: this.currentUser.id });++ const store = getOwner(this).lookup("service:store");+ const topic = store.createRecord("topic", {+ user_id: this.currentUser.id,+ });topic.set("category_id", Category.create({ read_restricted: true }).id);+this.siteSettings.allow_featured_topic_on_user_profiles = true;this.set("args", createArgs(topic));diff --git a/app/assets/javascripts/discourse/tests/unit/controllers/topic-test.js b/app/assets/javascripts/discourse/tests/unit/controllers/topic-test.jsindex 803f6586e8f..ce9696e2725 100644--- a/app/assets/javascripts/discourse/tests/unit/controllers/topic-test.js+++ b/app/assets/javascripts/discourse/tests/unit/controllers/topic-test.js@@ -4,12 +4,12 @@ import { settled } from "@ember/test-helpers";import pretender, { response } from "discourse/tests/helpers/create-pretender";import EmberObject from "@ember/object";import { Placeholder } from "discourse/lib/posts-with-placeholders";-import Topic from "discourse/models/topic";import User from "discourse/models/user";import { next } from "@ember/runloop";+import { getOwner } from "discourse-common/lib/get-owner";function topicWithStream(streamDetails) {- let topic = Topic.create();+ const topic = this.store.createRecord("topic");topic.postStream.setProperties(streamDetails);return topic;}@@ -17,9 +17,13 @@ function topicWithStream(streamDetails) {module("Unit | Controller | topic", function (hooks) {setupTest(hooks);+ hooks.beforeEach(function () {+ this.store = getOwner(this).lookup("service:store");+ });+test("editTopic", function (assert) {- const controller = this.owner.lookup("controller:topic");- const model = Topic.create();+ const controller = getOwner(this).lookup("controller:topic");+ const model = this.store.createRecord("topic");controller.setProperties({ model });assert.notOk(controller.editingTopic, "we are not editing by default");@@ -50,15 +54,15 @@ module("Unit | Controller | topic", function (hooks) {});test("deleteTopic", function (assert) {- const model = Topic.create();+ const model = this.store.createRecord("topic");let destroyed = false;let modalDisplayed = false;model.destroy = async () => (destroyed = true);- const siteSettings = this.owner.lookup("service:site-settings");+ const siteSettings = getOwner(this).lookup("service:site-settings");siteSettings.min_topic_views_for_delete_confirm = 5;- const controller = this.owner.lookup("controller:topic");+ const controller = getOwner(this).lookup("controller:topic");controller.setProperties({model,deleteTopicModal: () => (modalDisplayed = true),@@ -75,8 +79,8 @@ module("Unit | Controller | topic", function (hooks) {});test("toggleMultiSelect", async function (assert) {- const model = Topic.create();- const controller = this.owner.lookup("controller:topic");+ const model = this.store.createRecord("topic");+ const controller = getOwner(this).lookup("controller:topic");controller.setProperties({ model });assert.notOk(@@ -118,8 +122,10 @@ module("Unit | Controller | topic", function (hooks) {});test("selectedPosts", function (assert) {- const model = topicWithStream({ posts: [{ id: 1 }, { id: 2 }, { id: 3 }] });- const controller = this.owner.lookup("controller:topic");+ const model = topicWithStream.call(this, {+ posts: [{ id: 1 }, { id: 2 }, { id: 3 }],+ });+ const controller = getOwner(this).lookup("controller:topic");controller.setProperties({ model });controller.set("selectedPostIds", [1, 2, 42]);@@ -136,8 +142,8 @@ module("Unit | Controller | topic", function (hooks) {});test("selectedAllPosts", function (assert) {- const model = topicWithStream({ stream: [1, 2, 3] });- const controller = this.owner.lookup("controller:topic");+ const model = topicWithStream.call(this, { stream: [1, 2, 3] });+ const controller = getOwner(this).lookup("controller:topic");controller.setProperties({ model });controller.set("selectedPostIds", [1, 2]);@@ -163,7 +169,7 @@ module("Unit | Controller | topic", function (hooks) {});test("selectedPostsUsername", function (assert) {- const model = topicWithStream({+ const model = topicWithStream.call(this, {posts: [{ id: 1, username: "gary" },{ id: 2, username: "gary" },@@ -171,7 +177,7 @@ module("Unit | Controller | topic", function (hooks) {],stream: [1, 2, 3],});- const controller = this.owner.lookup("controller:topic");+ const controller = getOwner(this).lookup("controller:topic");controller.setProperties({ model });assert.strictEqual(@@ -210,13 +216,13 @@ module("Unit | Controller | topic", function (hooks) {});test("showSelectedPostsAtBottom", function (assert) {- const model = Topic.create({ posts_count: 3 });- const controller = this.owner.lookup("controller:topic");+ const model = this.store.createRecord("topic", { posts_count: 3 });+ const controller = getOwner(this).lookup("controller:topic");controller.setProperties({ model });assert.notOk(controller.showSelectedPostsAtBottom, "false on desktop");- const site = this.owner.lookup("service:site");+ const site = getOwner(this).lookup("service:site");site.set("mobileView", true);assert.notOk(@@ -233,7 +239,7 @@ module("Unit | Controller | topic", function (hooks) {test("canDeleteSelected", function (assert) {const currentUser = User.create({ admin: false });- const model = topicWithStream({+ const model = topicWithStream.call(this, {posts: [{ id: 1, can_delete: false },{ id: 2, can_delete: true },@@ -242,7 +248,7 @@ module("Unit | Controller | topic", function (hooks) {stream: [1, 2, 3],});- const controller = this.owner.lookup("controller:topic");+ const controller = getOwner(this).lookup("controller:topic");controller.setProperties({model,currentUser,@@ -279,7 +285,7 @@ module("Unit | Controller | topic", function (hooks) {});test("Can split/merge topic", function (assert) {- const model = topicWithStream({+ const model = topicWithStream.call(this, {posts: [{ id: 1, post_number: 1, post_type: 1 },{ id: 2, post_number: 2, post_type: 4 },@@ -289,7 +295,7 @@ module("Unit | Controller | topic", function (hooks) {});model.set("details.can_move_posts", false);- const controller = this.owner.lookup("controller:topic");+ const controller = getOwner(this).lookup("controller:topic");controller.setProperties({ model });assert.notOk(@@ -326,7 +332,7 @@ module("Unit | Controller | topic", function (hooks) {test("canChangeOwner", function (assert) {const currentUser = User.create({ admin: false });- const model = topicWithStream({+ const model = topicWithStream.call(this, {posts: [{ id: 1, username: "gary" },{ id: 2, username: "lili" },@@ -335,7 +341,7 @@ module("Unit | Controller | topic", function (hooks) {});model.set("currentUser", currentUser);- const controller = this.owner.lookup("controller:topic");+ const controller = getOwner(this).lookup("controller:topic");controller.setProperties({ model, currentUser });assert.notOk(controller.canChangeOwner, "false when no posts are selected");@@ -358,7 +364,7 @@ module("Unit | Controller | topic", function (hooks) {test("modCanChangeOwner", function (assert) {const currentUser = User.create({ moderator: false });- const model = topicWithStream({+ const model = topicWithStream.call(this, {posts: [{ id: 1, username: "gary" },{ id: 2, username: "lili" },@@ -367,10 +373,10 @@ module("Unit | Controller | topic", function (hooks) {});model.set("currentUser", currentUser);- const siteSettings = this.owner.lookup("service:site-settings");+ const siteSettings = getOwner(this).lookup("service:site-settings");siteSettings.moderators_change_post_ownership = true;- const controller = this.owner.lookup("controller:topic");+ const controller = getOwner(this).lookup("controller:topic");controller.setProperties({ model, currentUser });assert.notOk(controller.canChangeOwner, "false when no posts are selected");@@ -392,7 +398,7 @@ module("Unit | Controller | topic", function (hooks) {});test("canMergePosts", function (assert) {- const model = topicWithStream({+ const model = topicWithStream.call(this, {posts: [{ id: 1, username: "gary", can_delete: true },{ id: 2, username: "lili", can_delete: true },@@ -402,7 +408,7 @@ module("Unit | Controller | topic", function (hooks) {stream: [1, 2, 3],});- const controller = this.owner.lookup("controller:topic");+ const controller = getOwner(this).lookup("controller:topic");controller.setProperties({ model });assert.notOk(controller.canMergePosts, "false when no posts are selected");@@ -433,8 +439,8 @@ module("Unit | Controller | topic", function (hooks) {});test("Select/deselect all", function (assert) {- const controller = this.owner.lookup("controller:topic");- const model = topicWithStream({ stream: [1, 2, 3] });+ const controller = getOwner(this).lookup("controller:topic");+ const model = topicWithStream.call(this, { stream: [1, 2, 3] });controller.setProperties({ model });assert.strictEqual(@@ -459,7 +465,7 @@ module("Unit | Controller | topic", function (hooks) {});test("togglePostSelection", function (assert) {- const controller = this.owner.lookup("controller:topic");+ const controller = getOwner(this).lookup("controller:topic");assert.strictEqual(controller.selectedPostIds[0],@@ -483,10 +489,10 @@ module("Unit | Controller | topic", function (hooks) {});test("selectBelow", function (assert) {- const site = this.owner.lookup("service:site");+ const site = getOwner(this).lookup("service:site");site.set("post_types", { small_action: 3, whisper: 4 });- const model = topicWithStream({+ const model = topicWithStream.call(this, {stream: [1, 2, 3, 4, 5, 6, 7, 8],posts: [{ id: 5, cooked: "whisper post", post_type: 4 },@@ -495,7 +501,7 @@ module("Unit | Controller | topic", function (hooks) {],});- const controller = this.owner.lookup("controller:topic");+ const controller = getOwner(this).lookup("controller:topic");controller.setProperties({ model });assert.deepEqual(@@ -513,11 +519,11 @@ module("Unit | Controller | topic", function (hooks) {response([{ id: 2, level: 1 }]));- const model = topicWithStream({+ const model = topicWithStream.call(this, {posts: [{ id: 1 }, { id: 2 }],});- const controller = this.owner.lookup("controller:topic");+ const controller = getOwner(this).lookup("controller:topic");controller.setProperties({ model });controller.send("selectReplies", { id: 1 });@@ -552,10 +558,10 @@ module("Unit | Controller | topic", function (hooks) {});test("topVisibleChanged", function (assert) {- const model = topicWithStream({+ const model = topicWithStream.call(this, {posts: [{ id: 1 }],});- const controller = this.owner.lookup("controller:topic");+ const controller = getOwner(this).lookup("controller:topic");controller.setProperties({ model });const placeholder = new Placeholder("post-placeholder");@@ -581,12 +587,12 @@ module("Unit | Controller | topic", function (hooks) {});const currentUser = EmberObject.create({ moderator: true });- const model = topicWithStream({+ const model = topicWithStream.call(this, {stream: [2, 3, 4],posts: [post, { id: 3 }, { id: 4 }],});- const controller = this.owner.lookup("controller:topic");+ const controller = getOwner(this).lookup("controller:topic");controller.setProperties({ model, currentUser });const done = assert.async();diff --git a/app/assets/javascripts/discourse/tests/unit/models/topic-details-test.js b/app/assets/javascripts/discourse/tests/unit/models/topic-details-test.jsindex 23093db921c..5daeb9f65b9 100644--- a/app/assets/javascripts/discourse/tests/unit/models/topic-details-test.js+++ b/app/assets/javascripts/discourse/tests/unit/models/topic-details-test.js@@ -1,21 +1,21 @@import { module, test } from "qunit";-import Topic from "discourse/models/topic";import User from "discourse/models/user";--function buildDetails(id, topicParams = {}) {- const topic = Topic.create(Object.assign({ id }, topicParams));- return topic.get("details");-}+import { getOwner } from "discourse-common/lib/get-owner";module("Unit | Model | topic-details", function () {test("defaults", function (assert) {- let details = buildDetails(1234);+ const store = getOwner(this).lookup("service:store");+ const topic = store.createRecord("topic", { id: 1234 });+ const details = topic.details;+assert.present(details, "the details are present by default");assert.ok(!details.get("loaded"), "details are not loaded by default");});test("updateFromJson", function (assert) {- let details = buildDetails(1234);+ const store = getOwner(this).lookup("service:store");+ const topic = store.createRecord("topic", { id: 1234 });+ const details = topic.details;details.updateFromJson({allowed_users: [{ username: "eviltrout" }],diff --git a/app/assets/javascripts/discourse/tests/unit/models/topic-tracking-state-test.js b/app/assets/javascripts/discourse/tests/unit/models/topic-tracking-state-test.jsindex e37011fec32..434972596ac 100644--- a/app/assets/javascripts/discourse/tests/unit/models/topic-tracking-state-test.js+++ b/app/assets/javascripts/discourse/tests/unit/models/topic-tracking-state-test.js@@ -11,13 +11,14 @@ import {import { NotificationLevels } from "discourse/lib/notification-levels";import TopicTrackingState from "discourse/models/topic-tracking-state";import User from "discourse/models/user";-import Topic from "discourse/models/topic";import createStore from "discourse/tests/helpers/create-store";import sinon from "sinon";+import { getOwner } from "discourse-common/lib/get-owner";discourseModule("Unit | Model | topic-tracking-state", function (hooks) {hooks.beforeEach(function () {this.clock = fakeTime("2012-12-31 12:00");+ this.store = getOwner(this).lookup("service:store");});hooks.afterEach(function () {@@ -295,7 +296,7 @@ discourseModule("Unit | Model | topic-tracking-state", function (hooks) {trackingState.updateSeen(111, 7);const list = {topics: [- Topic.create({+ this.store.createRecord("topic", {highest_post_number: null,id: 111,unread_posts: 10,@@ -325,7 +326,7 @@ discourseModule("Unit | Model | topic-tracking-state", function (hooks) {const list = {topics: [- Topic.create({+ this.store.createRecord("topic", {id: 111,unseen: false,seen: true,@@ -366,12 +367,12 @@ discourseModule("Unit | Model | topic-tracking-state", function (hooks) {const list = {topics: [- Topic.create({+ this.store.createRecord("topic", {id: 111,last_read_post_number: null,unseen: true,}),- Topic.create({+ this.store.createRecord("topic", {id: 222,last_read_post_number: null,unseen: true,@@ -400,7 +401,7 @@ discourseModule("Unit | Model | topic-tracking-state", function (hooks) {const list = {topics: [- Topic.create({+ this.store.createRecord("topic", {id: 111,unseen: true,seen: false,@@ -409,7 +410,7 @@ discourseModule("Unit | Model | topic-tracking-state", function (hooks) {category_id: 1,tags: ["pending"],}),- Topic.create({+ this.store.createRecord("topic", {id: 222,unseen: false,seen: true,@@ -588,12 +589,12 @@ discourseModule("Unit | Model | topic-tracking-state", function (hooks) {assert.strictEqual(trackingState.filterTag, "test");assert.strictEqual(trackingState.filter, "latest");- trackingState.trackIncoming("c/cat/subcat/6/l/latest");+ trackingState.trackIncoming("c/cat/sub-cat/6/l/latest");assert.strictEqual(trackingState.filterCategory.id, 6);assert.strictEqual(trackingState.filterTag, undefined);assert.strictEqual(trackingState.filter, "latest");- trackingState.trackIncoming("tags/c/cat/subcat/6/test/l/latest");+ trackingState.trackIncoming("tags/c/cat/sub-cat/6/test/l/latest");assert.strictEqual(trackingState.filterCategory.id, 6);assert.strictEqual(trackingState.filterTag, "test");assert.strictEqual(trackingState.filter, "latest");