Forum link search: also include BURs

This commit is contained in:
nonamethanks
2021-07-21 10:27:02 +02:00
committed by evazion
parent 606b311841
commit b4b80b9618
2 changed files with 17 additions and 12 deletions

View File

@@ -45,7 +45,10 @@ class ForumPost < ApplicationRecord
end
def wiki_link_matches(title)
where(id: DtextLink.forum_post.wiki_link.where(link_target: WikiPage.normalize_title(title)).select(:model_id))
dtext_links = DtextLink.forum_post.wiki_link.where(link_target: WikiPage.normalize_title(title)).select(:model_id)
bur_links = BulkUpdateRequest.where_array_includes_any(:tags, title).select(:forum_post_id)
where(id: dtext_links).or(where(id: bur_links))
end
def search(params)

View File

@@ -54,12 +54,14 @@ class ForumPostsControllerTest < ActionDispatch::IntegrationTest
context "index action" do
setup do
@admin = create(:admin_user)
@other_forum = as(@user) { create(:forum_post, body: "[[test]]", topic: build(:forum_topic, title: "my topic", category_id: 1)) }
@linked_forum = as(@user) { create(:forum_post, body: "[[yyy]]", topic: build(:forum_topic, title: "my topic", category_id: 1)) }
@mod_forum = as(@mod) { create(:forum_post, creator: @mod, topic: build(:forum_topic, min_level: User::Levels::MODERATOR)) }
@admin_forum = as(@admin) { create(:forum_post, creator: @admin, topic: build(:forum_topic, min_level: User::Levels::ADMIN)) }
@unrelated_forum = as (@user) { create(:forum_post, is_deleted: true) }
as (@user) { create(:forum_post_vote, forum_post: @forum_post) }
create(:bulk_update_request, forum_post: @other_forum)
@unrelated_forum = as(@user) { create(:forum_post, is_deleted: true) }
as(@user) { create(:forum_post_vote, forum_post: @forum_post) }
@bur_forum = as(@user) { create(:forum_post, topic: build(:forum_topic, title: "bur")) }
create(:bulk_update_request, forum_post: @bur_forum, script: "alias xxx -> yyy")
end
context "as a user" do
@@ -72,18 +74,18 @@ class ForumPostsControllerTest < ActionDispatch::IntegrationTest
assert_response :success
end
should respond_to_search({}).with { [@unrelated_forum, @other_forum, @forum_post] }
should respond_to_search({}).with { [@bur_forum, @unrelated_forum, @linked_forum, @forum_post] }
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 }
should respond_to_search(linked_to: "yyy").with { [@bur_forum, @linked_forum] }
context "using includes" do
should respond_to_search(topic: {title_matches: "my forum topic"}).with { @forum_post }
should respond_to_search(topic: {category_id: 1}).with { @other_forum }
should respond_to_search(has_bulk_update_request: "true").with { @other_forum }
should respond_to_search(topic: {category_id: 1}).with { @linked_forum }
should respond_to_search(has_bulk_update_request: "true").with { @bur_forum }
should respond_to_search(has_votes: "true").with { @forum_post }
should respond_to_search(has_dtext_links: "true").with { @other_forum }
should respond_to_search(has_dtext_links: "true").with { @linked_forum }
should respond_to_search(creator_id: 999).with { @forum_post }
should respond_to_search(creator: {name: "okuu"}).with { [] }
end
@@ -94,7 +96,7 @@ class ForumPostsControllerTest < ActionDispatch::IntegrationTest
CurrentUser.user = @mod
end
should respond_to_search({}).with { [@unrelated_forum, @mod_forum, @other_forum, @forum_post] }
should respond_to_search({}).with { [@bur_forum, @unrelated_forum, @mod_forum, @linked_forum, @forum_post] }
context "using includes" do
should respond_to_search(creator: {name: "okuu"}).with { @mod_forum }
@@ -106,7 +108,7 @@ class ForumPostsControllerTest < ActionDispatch::IntegrationTest
CurrentUser.user = @admin
end
should respond_to_search({}).with { [@unrelated_forum, @admin_forum, @mod_forum, @other_forum, @forum_post] }
should respond_to_search({}).with { [@bur_forum, @unrelated_forum, @admin_forum, @mod_forum, @linked_forum, @forum_post] }
end
end