Fix #5177: ordfav with commentary search raises exception.
This commit is contained in:
@@ -242,9 +242,15 @@ class PostQueryBuilder
|
|||||||
in :not
|
in :not
|
||||||
children.first.negate_relation
|
children.first.negate_relation
|
||||||
in :and
|
in :and
|
||||||
children.reduce(&:and)
|
joins = children.flat_map(&:joins_values)
|
||||||
|
orders = children.flat_map(&:order_values)
|
||||||
|
nodes = children.map { |child| child.joins(joins).order(orders) }
|
||||||
|
nodes.reduce(&:and)
|
||||||
in :or
|
in :or
|
||||||
children.reduce(&:or)
|
joins = children.flat_map(&:joins_values)
|
||||||
|
orders = children.flat_map(&:order_values)
|
||||||
|
nodes = children.map { |child| child.joins(joins).order(orders) }
|
||||||
|
nodes.reduce(&:or)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ require 'test_helper'
|
|||||||
|
|
||||||
class PostQueryBuilderTest < ActiveSupport::TestCase
|
class PostQueryBuilderTest < ActiveSupport::TestCase
|
||||||
def assert_tag_match(posts, query, current_user: CurrentUser.user, tag_limit: nil, **options)
|
def assert_tag_match(posts, query, current_user: CurrentUser.user, tag_limit: nil, **options)
|
||||||
assert_equal(posts.map(&:id), Post.user_tag_match(query, current_user, tag_limit: tag_limit, **options).pluck(:id))
|
assert_equal(posts.map(&:id), Post.user_tag_match(query, current_user, tag_limit: tag_limit, **options).pluck("posts.id"))
|
||||||
end
|
end
|
||||||
|
|
||||||
def assert_search_error(query, current_user: CurrentUser.user, **options)
|
def assert_search_error(query, current_user: CurrentUser.user, **options)
|
||||||
@@ -284,6 +284,11 @@ class PostQueryBuilderTest < ActiveSupport::TestCase
|
|||||||
|
|
||||||
assert_tag_match([post2, post1], "ordfav:#{CurrentUser.user.name}")
|
assert_tag_match([post2, post1], "ordfav:#{CurrentUser.user.name}")
|
||||||
assert_tag_match([], "ordfav:does_not_exist")
|
assert_tag_match([], "ordfav:does_not_exist")
|
||||||
|
|
||||||
|
assert_tag_match([post2, post1], "ordfav:#{CurrentUser.user.name} commentary:false")
|
||||||
|
assert_tag_match([post2, post1], "ordfav:#{CurrentUser.user.name} favcount:>0")
|
||||||
|
assert_tag_match([post2, post1], "ordfav:#{CurrentUser.user.name} comments:0")
|
||||||
|
assert_tag_match([post2, post1], "ordfav:#{CurrentUser.user.name} -has:comments")
|
||||||
end
|
end
|
||||||
|
|
||||||
should "return posts for the pool:<name> metatag" do
|
should "return posts for the pool:<name> metatag" do
|
||||||
|
|||||||
Reference in New Issue
Block a user