Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix iterating using only a timestamp column #5

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, that's even neater! Thanks

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fix! ❤️ I will merge this and release a new version later today.

@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
Loading