pagination_test.rb
1.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
require_relative "test_helper"
class PaginationTest < Minitest::Test
def test_limit
store_names ["Product A", "Product B", "Product C", "Product D"]
assert_order "product", ["Product A", "Product B"], order: {name: :asc}, limit: 2
end
def test_no_limit
names = 20.times.map { |i| "Product #{i}" }
store_names names
assert_search "product", names
end
def test_offset
store_names ["Product A", "Product B", "Product C", "Product D"]
assert_order "product", ["Product C", "Product D"], order: {name: :asc}, offset: 2
end
def test_pagination
store_names ["Product A", "Product B", "Product C", "Product D", "Product E", "Product F"]
products = Product.search("product", order: {name: :asc}, page: 2, per_page: 2, padding: 1)
assert_equal ["Product D", "Product E"], products.map(&:name)
assert_equal "product", products.entry_name
assert_equal 2, products.current_page
assert_equal 1, products.padding
assert_equal 2, products.per_page
assert_equal 2, products.size
assert_equal 2, products.length
assert_equal 3, products.total_pages
assert_equal 6, products.total_count
assert_equal 6, products.total_entries
assert_equal 2, products.limit_value
assert_equal 3, products.offset_value
assert_equal 3, products.offset
assert_equal 3, products.next_page
assert_equal 1, products.previous_page
assert_equal 1, products.prev_page
assert !products.first_page?
assert !products.last_page?
assert !products.empty?
assert !products.out_of_range?
assert products.any?
end
def test_pagination_nil_page
store_names ["Product A", "Product B", "Product C", "Product D", "Product E"]
products = Product.search("product", order: {name: :asc}, page: nil, per_page: 2)
assert_equal ["Product A", "Product B"], products.map(&:name)
assert_equal 1, products.current_page
assert products.first_page?
end
end