DEV: Add hashtag controller specs (#19983)

This is just cleaning up a TODO I had to add more specs
to this controller -- there are more thorough tests on the
actual HashtagService class and the type-specific hashtag
classes.
This commit is contained in:
Martin Brennan
2023-01-25 17:13:32 +10:00
committed by GitHub
parent 88a972c61b
commit 82182ec0c7
2 changed files with 376 additions and 103 deletions

View File

@@ -9,8 +9,8 @@ module CategoryHashtag
# TODO (martin) Remove this when enable_experimental_hashtag_autocomplete
# becomes the norm, it is reimplemented below for CategoryHashtagDataSourcee
def query_from_hashtag_slug(category_slug)
slug_path = category_slug.split(SEPARATOR)
return nil if slug_path.empty? || slug_path.size > 2
slug_path = split_slug_path(category_slug)
return if slug_path.blank?
slug_path.map! { |slug| CGI.escape(slug) } if SiteSetting.slug_generation_method == "encoded"
@@ -34,7 +34,9 @@ module CategoryHashtag
category_slugs
.map(&:downcase)
.map do |slug|
slug_path = slug.split(":")
slug_path = split_slug_path(slug)
next if slug_path.blank?
if SiteSetting.slug_generation_method == "encoded"
slug_path.map! { |slug| CGI.escape(slug) }
end
@@ -60,5 +62,11 @@ module CategoryHashtag
end
.compact
end
def split_slug_path(slug)
slug_path = slug.split(SEPARATOR)
return if slug_path.empty? || slug_path.size > 2
slug_path
end
end
end