DEV: Use category ids in more URLs preferentially

DEV: Use category ids in more URLs preferentially

This is a followup to 374534f0

diff --git a/app/assets/javascripts/discourse/controllers/edit-category.js.es6 b/app/assets/javascripts/discourse/controllers/edit-category.js.es6
index a529f05e87..36c961c7e1 100644
--- a/app/assets/javascripts/discourse/controllers/edit-category.js.es6
+++ b/app/assets/javascripts/discourse/controllers/edit-category.js.es6
@@ -107,7 +107,7 @@ export default Controller.extend(ModalFunctionality, {
             slug: result.category.slug,
             id: result.category.id
           });
-          DiscourseURL.redirectTo("/c/" + Category.slugFor(model));
+          DiscourseURL.redirectTo(`/c/${Category.slugFor(model)}/${model.id}`);
         })
         .catch(error => {
           this.flash(extractError(error), "error");
diff --git a/app/assets/javascripts/discourse/helpers/category-link.js.es6 b/app/assets/javascripts/discourse/helpers/category-link.js.es6
index 4e11a911b2..b8a6198797 100644
--- a/app/assets/javascripts/discourse/helpers/category-link.js.es6
+++ b/app/assets/javascripts/discourse/helpers/category-link.js.es6
@@ -79,7 +79,7 @@ function defaultCategoryLinkRenderer(category, opts) {
   let restricted = get(category, "read_restricted");
   let url = opts.url
     ? opts.url
-    : Discourse.getURL("/c/") + Category.slugFor(category);
+    : Discourse.getURL(`/c/${Category.slugFor(category)}/${category.id}`);
   let href = opts.link === false ? "" : url;
   let tagName = opts.link === false || opts.link === "false" ? "span" : "a";
   let extraClasses = opts.extraClasses ? " " + opts.extraClasses : "";
diff --git a/app/assets/javascripts/discourse/models/category.js.es6 b/app/assets/javascripts/discourse/models/category.js.es6
index 82084aada3..1b442db7c5 100644
--- a/app/assets/javascripts/discourse/models/category.js.es6
+++ b/app/assets/javascripts/discourse/models/category.js.es6
@@ -67,7 +67,7 @@ const Category = RestModel.extend({
 
   @discourseComputed("name")
   url() {
-    return Discourse.getURL("/c/") + Category.slugFor(this);
+    return Discourse.getURL(`/c/${Category.slugFor(this)}/${this.id}`);
   },
 
   @discourseComputed
diff --git a/test/javascripts/acceptance/category-edit-test.js.es6 b/test/javascripts/acceptance/category-edit-test.js.es6
index fed9c84531..efdf73d90d 100644
--- a/test/javascripts/acceptance/category-edit-test.js.es6
+++ b/test/javascripts/acceptance/category-edit-test.js.es6
@@ -36,7 +36,7 @@ QUnit.test("Editing the category", async assert => {
   assert.ok(!visible(".d-modal"), "it closes the modal");
   assert.equal(
     DiscourseURL.redirectedTo,
-    "/c/bug",
+    "/c/bug/1",
     "it does one of the rare full page redirects"
   );
 });
diff --git a/test/javascripts/helpers/create-pretender.js.es6 b/test/javascripts/helpers/create-pretender.js.es6
index 9beff0a169..95a63b0e09 100644
--- a/test/javascripts/helpers/create-pretender.js.es6
+++ b/test/javascripts/helpers/create-pretender.js.es6
@@ -265,6 +265,7 @@ export default function() {
 
     this.put("/categories/:category_id", request => {
       const category = parsePostData(request.requestBody);
+      category.id = parseInt(request.params.category_id, 10);
 
       if (category.email_in === "duplicate@example.com") {
         return response(422, { errors: ["duplicate email"] });

GitHub sha: 6e5fedb3

1 Like