search: fix searches for private favorites raising privilege errors.

* Fix fav:<user> searches to return no results instead of raising a
  UserPrivilege error when the user has private favorites.

* Fix fav:<nonexistent_user> raising a UserPrivilege error instead of
  returning no results.

* Fix -ordfav:<user> not being supported.
This commit is contained in:
evazion
2020-04-16 20:20:59 -05:00
parent f8d420d6c0
commit 8009699cf7
2 changed files with 58 additions and 36 deletions

View File

@@ -2016,13 +2016,25 @@ class PostTest < ActiveSupport::TestCase
end
should "return posts for the fav:<name> metatag" do
users = FactoryBot.create_list(:user, 2)
posts = users.map do |u|
CurrentUser.scoped(u) { FactoryBot.create(:post, tag_string: "fav:#{u.name}") }
end
user1 = create(:user)
user2 = create(:user)
user3 = create(:user, enable_private_favorites: true)
post1 = as(user1) { create(:post, tag_string: "fav:true") }
post2 = as(user2) { create(:post, tag_string: "fav:true") }
post3 = as(user3) { create(:post, tag_string: "fav:true") }
assert_tag_match([posts[0]], "fav:#{users[0].name}")
assert_tag_match([posts[1]], "-fav:#{users[0].name}")
assert_tag_match([post1], "fav:#{user1.name}")
assert_tag_match([post2], "fav:#{user2.name}")
assert_tag_match([], "fav:#{user3.name}")
assert_tag_match([], "fav:dne")
assert_tag_match([post3, post2], "-fav:#{user1.name}")
assert_tag_match([post3, post2, post1], "-fav:dne")
as(user3) do
assert_tag_match([post3], "fav:#{user3.name}")
assert_tag_match([post2, post1], "-fav:#{user3.name}")
end
end
should "return posts for the ordfav:<name> metatag" do