require 'test_helper' class PaddingTest < ActiveSupport::TestCase test "negative padding should have 1 page" do 11.times.each { |index| Model.create name: index } @relation = Model.page(1).per(15).padding(-4) assert_equal @relation.total_pages, 1 @relation = Model.page(2).per(15).padding(-4) assert_equal @relation.total_pages, 1 @relation = Model.page(3).per(15).padding(-4) assert_equal @relation.total_pages, 1 end test "negative padding should have 2 pages" do 12.times.each { |index| Model.create name: index } @relation = Model.page(1).per(15).padding(-4) assert_equal @relation.total_pages, 2 @relation = Model.page(2).per(15).padding(-4) assert_equal @relation.total_pages, 2 @relation = Model.page(3).per(15).padding(-4) assert_equal @relation.total_pages, 2 end test "negative padding should have 3 pages" do 27.times.each { |index| Model.create name: index } @relation = Model.page(1).per(15).padding(-4) assert_equal @relation.total_pages, 3 @relation = Model.page(2).per(15).padding(-4) assert_equal @relation.total_pages, 3 @relation = Model.page(3).per(15).padding(-4) assert_equal @relation.total_pages, 3 end test "positive padding should have 1 page" do 15.times.each { |index| Model.create name: index } @relation = Model.page(1).per(15).padding(4) assert_equal @relation.total_pages, 1 @relation = Model.page(2).per(15).padding(4) assert_equal @relation.total_pages, 1 @relation = Model.page(3).per(15).padding(4) assert_equal @relation.total_pages, 1 end test "positive padding should have 2 pages" do 16.times.each { |index| Model.create name: index } @relation = Model.page(1).per(15).padding(4) assert_equal @relation.total_pages, 2 @relation = Model.page(2).per(15).padding(4) assert_equal @relation.total_pages, 2 @relation = Model.page(3).per(15).padding(4) assert_equal @relation.total_pages, 2 end test "positive padding should have 3 pages" do 31.times.each { |index| Model.create name: index } @relation = Model.page(1).per(15).padding(4) assert_equal @relation.total_pages, 3 @relation = Model.page(2).per(15).padding(4) assert_equal @relation.total_pages, 3 @relation = Model.page(3).per(15).padding(4) assert_equal @relation.total_pages, 3 end end