pools: allow searching pools by post id or post count.

All pools containing post #1:

    https://danbooru.donmai.us/pools?search[post_ids_include]=1

All pools containing either post #1 or #2:

    https://danbooru.donmai.us/pools?search[post_ids_include]=1,2
    https://danbooru.donmai.us/pools?search[post_ids_include]=1+2

Pools with 1-100 posts:

    https://danbooru.donmai.us/pools?search[post_id_count]=1..100

Pools with no posts (empty pools):

    https://danbooru.donmai.us/pools?search[post_id_count]=0
This commit is contained in:
evazion
2019-09-06 16:18:29 -05:00
parent 7d07b5f289
commit a9b7503aa7
3 changed files with 54 additions and 3 deletions

View File

@@ -59,6 +59,25 @@ class PoolTest < ActiveSupport::TestCase
assert_equal(@pool.id, Pool.find_by_name("test pool").id)
assert_equal(@pool.id, Pool.search(name_matches: "test pool").first.id)
end
should "find pools by post id" do
@pool1 = create(:pool, name: "pool1")
@pool2 = create(:pool, name: "pool2")
@post1 = create(:post, tag_string: "pool:pool1")
@post2 = create(:post, tag_string: "pool:pool2")
assert_equal([@pool1.id], Pool.search(post_ids_include: @post1.id).pluck(:id))
assert_equal([@pool2.id, @pool1.id], Pool.search(post_ids_include: "#{@post1.id} #{@post2.id}").pluck(:id))
end
should "find pools by post id count" do
@pool1 = create(:pool, name: "pool1")
@pool2 = create(:pool, name: "pool2")
@post1 = create(:post, tag_string: "pool:pool1")
@post2 = create(:post, tag_string: "pool:pool1")
assert_equal([@pool1.id], Pool.search(post_id_count: 2).pluck(:id))
end
end
context "Creating a pool" do