Commit 0b8db094623977b60ff51bb74221624e74c16adf
1 parent
b07e9388
Exists in
relation
and in
1 other branch
Fixed pagination [skip ci]
Showing
2 changed files
with
21 additions
and
9 deletions
Show diff stats
lib/searchkick/relation.rb
@@ -50,8 +50,12 @@ module Searchkick | @@ -50,8 +50,12 @@ module Searchkick | ||
50 | self | 50 | self |
51 | end | 51 | end |
52 | 52 | ||
53 | - def offset(value) | ||
54 | - spawn.offset!(value) | 53 | + def offset(*args) |
54 | + if args.empty? | ||
55 | + execute.offset | ||
56 | + else | ||
57 | + spawn.offset!(*args) | ||
58 | + end | ||
55 | end | 59 | end |
56 | 60 | ||
57 | def offset!(value) | 61 | def offset!(value) |
@@ -94,8 +98,12 @@ module Searchkick | @@ -94,8 +98,12 @@ module Searchkick | ||
94 | self | 98 | self |
95 | end | 99 | end |
96 | 100 | ||
97 | - def per_page(value) | ||
98 | - spawn.per_page!(value) | 101 | + def per_page(*args) |
102 | + if args.empty? | ||
103 | + execute.per_page | ||
104 | + else | ||
105 | + spawn.per_page!(*args) | ||
106 | + end | ||
99 | end | 107 | end |
100 | 108 | ||
101 | def per_page!(value) | 109 | def per_page!(value) |
@@ -103,8 +111,12 @@ module Searchkick | @@ -103,8 +111,12 @@ module Searchkick | ||
103 | self | 111 | self |
104 | end | 112 | end |
105 | 113 | ||
106 | - def padding(value) | ||
107 | - spawn.padding!(value) | 114 | + def padding(*args) |
115 | + if args.empty? | ||
116 | + execute.padding | ||
117 | + else | ||
118 | + spawn.padding!(*args) | ||
119 | + end | ||
108 | end | 120 | end |
109 | 121 | ||
110 | def padding!(value) | 122 | def padding!(value) |
test/pagination_test.rb
@@ -49,8 +49,8 @@ class PaginationTest < Minitest::Test | @@ -49,8 +49,8 @@ class PaginationTest < Minitest::Test | ||
49 | assert_equal ["Product D", "Product E"], products.map(&:name) | 49 | assert_equal ["Product D", "Product E"], products.map(&:name) |
50 | assert_equal "product", products.entry_name | 50 | assert_equal "product", products.entry_name |
51 | assert_equal 2, products.current_page | 51 | assert_equal 2, products.current_page |
52 | - # assert_equal 1, products.padding | ||
53 | - # assert_equal 2, products.per_page | 52 | + assert_equal 1, products.padding |
53 | + assert_equal 2, products.per_page | ||
54 | assert_equal 2, products.size | 54 | assert_equal 2, products.size |
55 | assert_equal 2, products.length | 55 | assert_equal 2, products.length |
56 | assert_equal 3, products.total_pages | 56 | assert_equal 3, products.total_pages |
@@ -58,7 +58,7 @@ class PaginationTest < Minitest::Test | @@ -58,7 +58,7 @@ class PaginationTest < Minitest::Test | ||
58 | assert_equal 6, products.total_entries | 58 | assert_equal 6, products.total_entries |
59 | assert_equal 2, products.limit_value | 59 | assert_equal 2, products.limit_value |
60 | assert_equal 3, products.offset_value | 60 | assert_equal 3, products.offset_value |
61 | - # assert_equal 3, products.offset | 61 | + assert_equal 3, products.offset |
62 | assert_equal 3, products.next_page | 62 | assert_equal 3, products.next_page |
63 | assert_equal 1, products.previous_page | 63 | assert_equal 1, products.previous_page |
64 | assert_equal 1, products.prev_page | 64 | assert_equal 1, products.prev_page |