From 71ba45c57ca4e8774d6bdf224809f5cdc34037c1 Mon Sep 17 00:00:00 2001 From: evazion Date: Sun, 13 Dec 2020 00:52:30 -0600 Subject: [PATCH] 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. --- app/models/forum_post.rb | 6 +++++- test/functional/forum_posts_controller_test.rb | 1 + 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/app/models/forum_post.rb b/app/models/forum_post.rb index 62815ff62..2558a33ce 100644 --- a/app/models/forum_post.rb +++ b/app/models/forum_post.rb @@ -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) diff --git a/test/functional/forum_posts_controller_test.rb b/test/functional/forum_posts_controller_test.rb index 41cde00d0..be3912546 100644 --- a/test/functional/forum_posts_controller_test.rb +++ b/test/functional/forum_posts_controller_test.rb @@ -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 }