pools: add ability to search for pools linking to given tag.

Add ability to search for pools linking to a given tag in the pool
description. Example:

    https://danbooru.donmai.us/pools?search[linked_to]=touhou

(This isn't actually exposed in the UI to avoid cluttering the pool
search form with rarely used options.)

Pools with broken links can be found here:

    https://danbooru.donmai.us/dtext_links?search[has_linked_tag]=No&search[has_linked_wiki]=No&search[model_type]=Pool

Lays the groundwork for fixing #4629.
This commit is contained in:
evazion
2022-01-15 20:16:06 -06:00
parent c3c4f5a2a7
commit 33103f6dc4
10 changed files with 72 additions and 42 deletions

View File

@@ -6,6 +6,7 @@ class DtextLinksControllerTest < ActionDispatch::IntegrationTest
as(@user) do
@wiki = create(:wiki_page, title: "case", body: "[[test]]")
@forum = create(:forum_post, topic: build(:forum_topic, title: "blah"), body: "[[case]]")
@pool = create(:pool, description: "[[case]]")
create(:tag, name: "test")
end
end
@@ -16,13 +17,14 @@ class DtextLinksControllerTest < ActionDispatch::IntegrationTest
assert_response :success
end
should respond_to_search({}).with { @forum.dtext_links + @wiki.dtext_links }
should respond_to_search({}).with { @pool.dtext_links + @forum.dtext_links + @wiki.dtext_links }
context "using includes" do
should respond_to_search(model_type: "WikiPage").with { @wiki.dtext_links }
should respond_to_search(model_type: "ForumPost").with { @forum.dtext_links }
should respond_to_search(model_type: "Pool").with { @pool.dtext_links }
should respond_to_search(has_linked_tag: "true").with { @wiki.dtext_links }
should respond_to_search(has_linked_wiki: "true").with { @forum.dtext_links }
should respond_to_search(has_linked_wiki: "true").with { @pool.dtext_links + @forum.dtext_links }
should respond_to_search(ForumPost: {topic: {title_matches: "blah"}}).with { @forum.dtext_links }
should respond_to_search(ForumPost: {topic: {title_matches: "nah"}}).with { [] }
end

View File

@@ -9,7 +9,7 @@ class PoolsControllerTest < ActionDispatch::IntegrationTest
end
as(@user) do
@post = create(:post)
@pool = create(:pool)
@pool = create(:pool, name: "pool", description: "[[touhou]]")
end
end
@@ -19,17 +19,15 @@ class PoolsControllerTest < ActionDispatch::IntegrationTest
assert_response :success
end
should "list all pools (with search)" do
get pools_path, params: {:search => {:name_matches => @pool.name}}
assert_response :success
end
should "render for a sitemap" do
get pools_path(format: :sitemap)
assert_response :success
assert_equal(Pool.count, response.parsed_body.css("urlset url loc").size)
end
should respond_to_search(name_matches: "pool").with { @pool }
should respond_to_search(linked_to: "touhou").with { @pool }
should respond_to_search(not_linked_to: "touhou").with { [] }
end
context "show action" do