continue refactoring savedsearch

This commit is contained in:
Albert Yi
2018-11-13 18:05:05 -08:00
parent df02eb7951
commit 0508b127fd
17 changed files with 171 additions and 186 deletions

View File

@@ -2265,25 +2265,35 @@ class PostTest < ActiveSupport::TestCase
assert_tag_match([post], "pixiv_id:none")
end
# should "return posts for a pixiv novel id search" do
# url = "http://www.pixiv.net/novel/show.php?id=2156088"
# post = FactoryBot.create(:post, :source => url)
# assert_equal(1, Post.tag_match("pixiv_novel_id:2156088").count)
# end
context "saved searches" do
setup do
SavedSearch.stubs(:enabled?).returns(true)
@post1 = FactoryBot.create(:post, tag_string: "aaa")
@post2 = FactoryBot.create(:post, tag_string: "bbb")
FactoryBot.create(:saved_search, query: "aaa", labels: ["zzz"], user: CurrentUser.user)
FactoryBot.create(:saved_search, query: "bbb", user: CurrentUser.user)
end
should "return posts for a search:<category> metatag" do
post1 = FactoryBot.create(:post, tag_string: "aaa")
post2 = FactoryBot.create(:post, tag_string: "bbb")
FactoryBot.create(:saved_search, query: "aaa", labels: ["zzz"], user: CurrentUser.user)
FactoryBot.create(:saved_search, query: "bbb", user: CurrentUser.user)
context "labeled" do
should "work" do
SavedSearch.expects(:post_ids_for).with(CurrentUser.id, label: "zzz").returns([@post1.id])
assert_tag_match([@post1], "search:zzz")
end
end
SavedSearch.expects(:post_ids).with(CurrentUser.id, "zzz").returns([post1.id])
SavedSearch.expects(:post_ids).with(CurrentUser.id, "uncategorized").returns([post2.id])
SavedSearch.expects(:post_ids).with(CurrentUser.id).returns([post1.id, post2.id])
context "missing" do
should "work" do
SavedSearch.expects(:post_ids_for).with(CurrentUser.id, label: "uncategorized").returns([@post2.id])
assert_tag_match([@post2], "search:uncategorized")
end
end
assert_tag_match([post1], "search:zzz")
assert_tag_match([post2], "search:uncategorized")
assert_tag_match([post2, post1], "search:all")
context "all" do
should "work" do
SavedSearch.expects(:post_ids_for).with(CurrentUser.id).returns([@post1.id, @post2.id])
assert_tag_match([@post2, @post1], "search:all")
end
end
end
should "return posts for a rating:<s|q|e> metatag" do