topic fixup

This commit is contained in:
Jarek Radosz 2020-11-11 14:49:29 +01:00 committed by Robin Ward
parent 20108f834c
commit 19b7cdd21f
2 changed files with 13 additions and 5 deletions

View File

@ -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-%@"),

View File

@ -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");
});