Skip to content

Commit c4808c7

Browse files
committed
Fix
1 parent d4f6fea commit c4808c7

File tree

8 files changed

+32
-32
lines changed

8 files changed

+32
-32
lines changed

.github/workflows/push.yml

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,25 @@ jobs:
3434
fail-fast: false
3535
matrix:
3636
ruby: ['3.0', '3.1', '3.2', '3.3']
37-
rails: ['6.1', '7.0', '7.1', '7.2', '8.0']
37+
rails: ['6.1', '7.0', '7.1', '7.2', '8.0', '8.1']
38+
pagy: ['9.0', '43']
3839
exclude:
3940
- ruby: '3.0'
4041
rails: '8.0'
4142
- ruby: '3.1'
4243
rails: '8.0'
44+
- ruby: '3.0'
45+
rails: '8.1'
46+
- ruby: '3.1'
47+
rails: '8.1'
4348
- ruby: '3.0'
4449
rails: '7.2'
4550
- ruby: '3.1'
4651
rails: '7.2'
52+
- ruby: '3.0'
53+
pagy: '43'
54+
- ruby: '3.1'
55+
pagy: '43'
4756

4857
runs-on: ubuntu-latest
4958
name: Test against Ruby ${{ matrix.ruby }} / Rails ${{ matrix.rails }}
@@ -69,8 +78,10 @@ jobs:
6978
bundler-cache: true
7079
env:
7180
RAILS_VERSION: ${{ matrix.rails }}
81+
PAGY_VERSION: ${{ matrix.pagy }}
7282

7383
- name: Run tests
7484
run: bundle exec rspec --tag ~type:generator
7585
env:
7686
RAILS_VERSION: ${{ matrix.rails }}
87+
PAGY_VERSION: ${{ matrix.pagy }}

Gemfile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ source 'https://rubygems.org'
55
# Specify your gem's dependencies in inertia_rails.gemspec
66
gemspec
77

8-
version = ENV['RAILS_VERSION'] || '8.0'
8+
version = ENV.fetch('RAILS_VERSION', '8.1')
9+
pagy_version = ENV.fetch('PAGY_VERSION', '43')
910
gem 'rails', "~> #{version}.0"
1011

1112
gem 'bundler', '~> 2.0'
@@ -19,4 +20,4 @@ gem 'rubocop', '~> 1.21'
1920
gem 'sqlite3'
2021

2122
gem 'kaminari'
22-
gem 'pagy'
23+
gem 'pagy', "~> #{pagy_version}"

docs/guide/infinite-scroll.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ To configure your paginated data for infinite scrolling, you should use the `Ine
1414

1515
```ruby
1616
class UsersController < ApplicationController
17-
include Pagy::Backend
17+
include Pagy::Method
1818

1919
def index
20-
pagy, records = pagy(User.all)
20+
pagy, records = pagy(:countless, User.all)
2121

2222
render inertia: {
2323
users: InertiaRails.scroll(pagy) { records.as_json(...) }
@@ -1112,11 +1112,11 @@ Sometimes you may need to render multiple infinite scroll components on a single
11121112

11131113
```ruby
11141114
class DashboardController < ApplicationController
1115-
include Pagy::Backend
1115+
include Pagy::Method
11161116

11171117
def index
1118-
pagy_users, users = pagy(User.all, page_param: :users)
1119-
pagy_orders, orders = pagy(Order.all, page_param: :orders)
1118+
pagy_users, users = pagy(:countless, User.all, page_param: :users)
1119+
pagy_orders, orders = pagy(:countless, Order.all, page_param: :orders)
11201120

11211121
render inertia: {
11221122
users: InertiaRails.scroll(pagy_users) { users.as_json(...) },

docs/guide/merging-props.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ To merge a prop instead of overwriting it, you may use the `InertiaRails.merge`
1212

1313
```ruby
1414
class UsersController < ApplicationController
15-
include Pagy::Backend
15+
include Pagy::Method
1616

1717
def index
18-
_pagy, records = pagy(User.all)
18+
_pagy, records = pagy(:offset, User.all)
1919

2020
render inertia: {
2121
users: InertiaRails.merge { records.as_json(...) },
@@ -133,10 +133,10 @@ You can also combine [deferred props](/guide/deferred-props) with mergeable prop
133133

134134
```ruby
135135
class UsersController < ApplicationController
136-
include Pagy::Backend
136+
include Pagy::Method
137137

138138
def index
139-
pagy, records = pagy(User.all)
139+
pagy, records = pagy(:offset, User.all)
140140

141141
render inertia: {
142142
results: InertiaRails.defer(deep_merge: true) { records.as_json(...) },

lib/inertia_rails/scroll_metadata.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def call(metadata, **_options)
4646
page_name = metadata.respond_to?(:vars) ? metadata.vars.fetch(:page_param) : metadata.options[:page_key]
4747
{
4848
page_name: page_name.to_s,
49-
previous_page: metadata.previous,
49+
previous_page: metadata.try(:prev) || metadata.try(:previous),
5050
next_page: metadata.next,
5151
current_page: metadata.page,
5252
}

spec/dummy/app/controllers/inertia_render_test_controller.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,9 +130,7 @@ def deferred_props
130130
end
131131

132132
def scroll_test
133-
pagy = Pagy.new(
134-
vars: { page_param: 'page' },
135-
prev: nil,
133+
pagy = (defined?(Pagy::Offset) ? Pagy::Offset : Pagy).new(
136134
next: 2,
137135
page: 1,
138136
count: 100

spec/inertia/scroll_metadata_spec.rb

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -59,16 +59,12 @@
5959
end
6060

6161
context 'with Pagy adapter' do
62-
before do
63-
stub_const('Pagy', Class.new)
64-
end
65-
6662
let(:pagy_metadata) do
67-
instance_double('Pagy').tap do |metadata|
63+
instance_double('Pagy::Offset').tap do |metadata|
6864
allow(metadata).to receive(:is_a?).and_return(false)
6965
allow(metadata).to receive(:is_a?).with(Pagy).and_return(true)
70-
allow(metadata).to receive(:vars).and_return({ page_param: :page })
71-
allow(metadata).to receive(:prev).and_return(1)
66+
allow(metadata).to receive(:options).and_return({ page_key: :page })
67+
allow(metadata).to receive(:previous).and_return(1)
7268
allow(metadata).to receive(:next).and_return(3)
7369
allow(metadata).to receive(:page).and_return(2)
7470
end
@@ -85,14 +81,6 @@
8581
)
8682
end
8783

88-
it 'raises error when page_param is missing from vars' do
89-
allow(pagy_metadata).to receive(:vars).and_return({})
90-
91-
expect do
92-
described_class.extract(pagy_metadata)
93-
end.to raise_error(KeyError)
94-
end
95-
9684
it 'allows options to override metadata values' do
9785
result = described_class.extract(
9886
pagy_metadata,

spec/inertia/scroll_prop_spec.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
describe '#metadata' do
77
it 'resolves metadata from Pagy paginator' do
88
collection = Array.new(100) { |i| "item#{i}" }
9-
pagy, = Pagy.new(count: collection.size, page: 1, items: 20)
9+
pagy, = (defined?(Pagy::Offset) ? Pagy::Offset : Pagy).new(
10+
count: collection.size, page: 1, items: 20
11+
)
1012

1113
prop = described_class.new(metadata: pagy) { collection }
1214
metadata = prop.metadata

0 commit comments

Comments
 (0)