Skip to content

Commit

Permalink
Merge pull request #8 from healthie/new-version
Browse files Browse the repository at this point in the history
New version
  • Loading branch information
fatkodima committed May 23, 2024
2 parents 742180a + b917ace commit 85ae899
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 5 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
## master (unreleased)

## 0.2.0 (2024-05-23)

- Fix prefixing selected columns when iterating over joined tables
- Change cursor encoding to url safe base64
- Fix `next_cursor`/`previous_cursor` for empty pages
- Fix iterating using only a timestamp column
Expand Down
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
activerecord_cursor_paginate (0.1.0)
activerecord_cursor_paginate (0.2.0)
activerecord (>= 7.0)

GEM
Expand Down
1 change: 0 additions & 1 deletion lib/activerecord_cursor_paginate/cursor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ module ActiveRecordCursorPaginate
class Cursor
class << self
def from_record(record, columns:)
columns = columns.map { |column| column.to_s.split(".").last }
values = columns.map { |column| record[column] }
new(columns: columns, values: values)
end
Expand Down
4 changes: 2 additions & 2 deletions lib/activerecord_cursor_paginate/paginator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,11 @@ def fetch
arel_columns = @columns.map.with_index do |column, i|
arel_column(column).as("cursor_column_#{i + 1}")
end
cursor_column_names = 1.upto(@columns.size).map { |i| "cursor_column_#{i}" }
cursor_column_names = arel_columns.map { |column| column.right.to_s }

relation =
if relation.select_values.empty?
relation.select(Arel.star, arel_columns)
relation.select(relation.arel_table[Arel.star], arel_columns)
else
relation.select(arel_columns)
end
Expand Down
2 changes: 1 addition & 1 deletion lib/activerecord_cursor_paginate/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module ActiveRecordCursorPaginate
VERSION = "0.1.0"
VERSION = "0.2.0"
end
6 changes: 6 additions & 0 deletions test/paginator_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,12 @@ def test_ordering_and_joins
assert_equal([[2, 6], [3, 2]], page2.records.pluck(:id, :stars))
end

def test_ordering_and_joins_correctly_selects_parent_record_attributes
p = User.joins(:projects).cursor_paginate(order: [:id, "projects.id"])
page = p.fetch
assert_equal([1, 1, 2, 2, 3], page.records.pluck(:id))
end

def test_ordering_by_expression
p = User.cursor_paginate(limit: 2, order: Arel.sql("id + 1"))
page1 = p.fetch
Expand Down

0 comments on commit 85ae899

Please sign in to comment.