forum: fix /forum_posts?search[linked_to] not normalizing tags.

Fix searches like https://danbooru.donmai.us/forum_posts?search[linked_to]=touhou%20
not working because the tag wasn't normalized.
This commit is contained in:
evazion
2020-12-13 00:52:30 -06:00
parent b002bf25f5
commit 71ba45c57c
2 changed files with 6 additions and 1 deletions

View File

@@ -36,13 +36,17 @@ class ForumPost < ApplicationRecord
where(topic_id: ForumTopic.visible(user))
end
def wiki_link_matches(title)
where(id: DtextLink.forum_post.wiki_link.where(link_target: WikiPage.normalize_title(title)).select(:model_id))
end
def search(params)
q = super
q = q.search_attributes(params, :is_deleted, :body)
q = q.text_attribute_matches(:body, params[:body_matches], index_column: :text_index)
if params[:linked_to].present?
q = q.where(id: DtextLink.forum_post.wiki_link.where(link_target: params[:linked_to]).select(:model_id))
q = q.wiki_link_matches(params[:linked_to])
end
q.apply_default_order(params)

View File

@@ -76,6 +76,7 @@ class ForumPostsControllerTest < ActionDispatch::IntegrationTest
should respond_to_search(body_matches: "xxx").with { @forum_post }
should respond_to_search(body_matches: "bababa").with { [] }
should respond_to_search(is_deleted: "true").with { @unrelated_forum }
should respond_to_search(linked_to: "TEST").with { @other_forum }
context "using includes" do
should respond_to_search(topic: {title_matches: "my forum topic"}).with { @forum_post }