Skip to content

Commit

Permalink
Fix iterating using only a timestamp column (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
scottmatthewman committed May 13, 2024
1 parent 0c26280 commit 76c4bf3
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
## master (unreleased)

- Fix iterating using only a timestamp column

- Add the ability to skip implicitly appending a primary key to the list of sorting columns.

It may be useful to disable it for the table with a UUID primary key or when the sorting
Expand Down
4 changes: 2 additions & 2 deletions lib/activerecord_cursor_paginate/cursor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ def deserialize_time_if_needed(value)
attr_reader :columns, :values

def initialize(columns:, values:)
@columns = Array(columns)
@values = Array(values)
@columns = Array.wrap(columns)
@values = Array.wrap(values)

raise ArgumentError, "Cursor values can not be nil" if @values.any?(nil)
raise ArgumentError, ":columns and :values have different sizes" if @columns.size != @values.size
Expand Down
9 changes: 9 additions & 0 deletions test/paginator_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,15 @@ def test_paginating_over_time_column
assert_equal([7, 4, 10], page2.records.pluck(:id))
end

def test_paginating_over_time_column_without_primary_key
p = User.cursor_paginate(limit: 3, order: { created_at: :asc }, append_primary_key: false)
page1 = p.fetch
assert_equal([5, 3, 8], page1.records.pluck(:id))

page2 = p.fetch
assert_equal([7, 4, 10], page2.records.pluck(:id))
end

def test_paginating_over_all_pages
p = User.cursor_paginate(limit: 2)

Expand Down

0 comments on commit 76c4bf3

Please sign in to comment.