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

Category.query_from_hashtag_slug is the only source of truth.
This commit is contained in:
Dan Ungureanu 2020-07-08 21:24:09 +03:00
parent 56f42d89c5
commit e88b17c044
No known key found for this signature in database
GPG Key ID: 0AA2A00D6ACC8B84
2 changed files with 5 additions and 8 deletions

View File

@ -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

View File

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