FIX: Sync client and server side behavior for category hashtag lookup

FIX: Sync client and server side behavior for category hashtag lookup

Category.query_from_hashtag_slug is the only source of truth.

diff --git a/app/controllers/category_hashtags_controller.rb b/app/controllers/category_hashtags_controller.rb
index 4f6601e..b40b9f6 100644
--- a/app/controllers/category_hashtags_controller.rb
+++ b/app/controllers/category_hashtags_controller.rb
@@ -10,8 +10,7 @@ class CategoryHashtagsController < ApplicationController
 
     slugs_and_urls = {}
 
-    Category.secured(guardian).where(id: ids).order(:id).each do |category|
-      slugs_and_urls[category.slug] ||= category.url
+    Category.secured(guardian).where(id: ids).each do |category|
       slugs_and_urls[category.slug_path.last(2).join(':')] ||= category.url
     end
 
diff --git a/spec/requests/category_hashtags_controller_spec.rb b/spec/requests/category_hashtags_controller_spec.rb
index f4135ae..707a5aa 100644
--- a/spec/requests/category_hashtags_controller_spec.rb
+++ b/spec/requests/category_hashtags_controller_spec.rb
@@ -68,10 +68,10 @@ describe CategoryHashtagsController do
 
           get "/category_hashtags/check.json", params: {
             category_slugs: [
-              ":",
+              ":", # should not work
               "foo",
-              "bar",
-              "baz",
+              "bar", # should not work
+              "baz", # should not work
               "foo:bar",
               "bar:baz",
               "foo:bar:baz", # should not work
@@ -84,10 +84,8 @@ describe CategoryHashtagsController do
           expect(response.status).to eq(200)
           expect(response.parsed_body["valid"]).to contain_exactly(
             { "slug" => "foo",     "url" => foo.url },
-            { "slug" => "bar",     "url" => foobar.url },
             { "slug" => "foo:bar", "url" => foobar.url },
-            { "slug" => "baz",     "url" => foobarbaz.url },
-            { "slug" => "bar:baz", "url" => foobarbaz.url },
+            { "slug" => "bar:baz", "url" => foobarbaz.id < quxbarbaz.id ? foobarbaz.url : quxbarbaz.url },
             { "slug" => "qux",     "url" => qux.url },
             { "slug" => "qux:bar", "url" => quxbar.url }
           )

GitHub sha: e88b17c0

1 Like