Files
danbooru/test/unit/post_sets/intro_test.rb
evazion 93dd952949 pagination: refactor to avoid counting pages in API.
Previously the page-based (numbered) paginator would always count the
total_pages, even in API calls when it wasn't needed. This could be very
slow in some cases. Refactor so that total_pages isn't calculated unless
it's called.

While we're at it, refactor to condense all the sequential vs. numbered
pagination logic into one module. This incidentally fixes a couple more
bugs:

* "page=b0" returned all pages rather than nothing.
* Bad parameters like "page=blaha123" and "page=a123blah" were accepted.
2019-10-07 22:01:37 -05:00

41 lines
1.1 KiB
Ruby

require 'test_helper'
module PostSets
class IntroTest < ActiveSupport::TestCase
context "In all cases" do
setup do
@user = FactoryBot.create(:user)
CurrentUser.user = @user
CurrentUser.ip_addr = "127.0.0.1"
@post_1 = FactoryBot.create(:post, :tag_string => "a")
@post_2 = FactoryBot.create(:post, :tag_string => "b")
@post_3 = FactoryBot.create(:post, :tag_string => "c")
end
teardown do
CurrentUser.user = nil
CurrentUser.ip_addr = nil
end
context "a set for the 'a' tag query" do
setup do
@post_4 = FactoryBot.create(:post, :tag_string => "a", :fav_count => 5)
@post_5 = FactoryBot.create(:post, :tag_string => "a", :fav_count => 5)
end
context "with no page" do
setup do
@set = PostSets::Intro.new("a")
::Post.stubs(:records_per_page).returns(1)
end
should "return the first element" do
assert_equal(@post_5.id, @set.posts.first.id)
end
end
end
end
end
end