Skip to content

Commit b069c78

Browse files
committed
Fix Paginator#limit to return default page size by default
Fixes #19.
1 parent f318eab commit b069c78

File tree

3 files changed

+5
-1
lines changed

3 files changed

+5
-1
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
## master (unreleased)
22

3+
- Fix `Paginator#limit` to return default page size by default
4+
35
## 0.4.0 (2025-03-10)
46

57
- Add ability to paginate backward from the end of the collection

lib/activerecord_cursor_paginate/paginator.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ def limit=(value)
104104
config = ActiveRecordCursorPaginate.config
105105
@page_size = value || config.default_page_size
106106
@page_size = [@page_size, config.max_page_size].min if config.max_page_size
107-
@limit = value
107+
@limit = @page_size
108108
end
109109

110110
def order=(value)

test/paginator_test.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,13 +93,15 @@ def test_paginating_backward_from_the_end
9393
def test_uses_default_limit
9494
ActiveRecordCursorPaginate.config.stub(:default_page_size, 4) do
9595
p = User.cursor_paginate
96+
assert_equal 4, p.limit
9697
users = p.fetch.records
9798
assert_equal([1, 2, 3, 4], users.pluck(:id))
9899
end
99100
end
100101

101102
def test_custom_limit
102103
p = User.cursor_paginate(limit: 3)
104+
assert_equal 3, p.limit
103105
users = p.fetch.records
104106
assert_equal([1, 2, 3], users.pluck(:id))
105107
end

0 commit comments

Comments
 (0)