Skip to content

A platform for community discussion. Free, open, simple.

topic fixup

Jarek Radosz19b7cdd21fe1
diff --git a/app/assets/javascripts/discourse/app/models/topic.js b/app/assets/javascripts/discourse/app/models/topic.js
index ed0d7c2c339..2170c0ee4cd 100644
--- a/app/assets/javascripts/discourse/app/models/topic.js
+++ b/app/assets/javascripts/discourse/app/models/topic.js
@@ -225,8 +225,14 @@ const Topic = RestModel.extend({
},
@discourseComputed("category_id")
- category(categoryId) {
- return Category.findById(categoryId);
+ category: {
+ get(categoryId) {
+ return Category.findById(categoryId);
+ },
+ set(category) {
+ this.set("category_id", category.id);
+ return category;
+ },
},
categoryClass: fmt("category.fullSlug", "category-%@"),
diff --git a/app/assets/javascripts/discourse/tests/unit/models/topic-test.js b/app/assets/javascripts/discourse/tests/unit/models/topic-test.js
index 1866b91d0b8..c427c3d01ba 100644
--- a/app/assets/javascripts/discourse/tests/unit/models/topic-test.js
+++ b/app/assets/javascripts/discourse/tests/unit/models/topic-test.js
@@ -5,6 +5,7 @@ import Category from "discourse/models/category";
import Topic from "discourse/models/topic";
import User from "discourse/models/user";
import { discourseModule } from "discourse/tests/helpers/qunit-helpers";
+import createStore from "discourse/tests/helpers/create-store";
discourseModule("Unit | Model | topic", function () {
test("defaults", function (assert) {
@@ -36,7 +37,9 @@ discourseModule("Unit | Model | topic", function () {
});
test("lastUnreadUrl", function (assert) {
- const category = EmberObject.create({
+ const store = createStore();
+ const category = store.createRecord("category", {
+ id: 1,
navigate_to_first_post_after_read: true,
});
@@ -45,10 +48,9 @@ discourseModule("Unit | Model | topic", function () {
highest_post_number: 10,
last_read_post_number: 10,
slug: "hello",
+ category_id: category.id,
});
- topic.set("category", category);
-
assert.equal(topic.get("lastUnreadUrl"), "/t/hello/101/1");
});