Skip to content

Commit d277fc4

Browse files
committed
Add partial Rails 8.1.2 support (664/674 tests passing)
1 parent de5dfea commit d277fc4

3 files changed

Lines changed: 18 additions & 4 deletions

File tree

lib/jsonapi/routing_ext.rb

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,15 @@ def jsonapi_resource(*resources, &_block)
5858
jsonapi_relationships
5959
end
6060
else
61-
# Rails 5
62-
jsonapi_resource_scope(SingletonResource.new(@resource_type, api_only?, @scope[:shallow], options), @resource_type) do
61+
# Rails 5+
62+
# Rails 8.1 changed SingletonResource.new to accept only 3 arguments (removed options)
63+
resource_arg = if Rails::VERSION::MAJOR >= 8 && Rails::VERSION::MINOR >= 1
64+
SingletonResource.new(@resource_type, api_only?, @scope[:shallow])
65+
else
66+
SingletonResource.new(@resource_type, api_only?, @scope[:shallow], options)
67+
end
68+
69+
jsonapi_resource_scope(resource_arg, @resource_type) do
6370
if block_given?
6471
yield
6572
else
@@ -132,8 +139,15 @@ def jsonapi_resources(*resources, &_block)
132139
jsonapi_relationships
133140
end
134141
else
135-
# Rails 5
136-
jsonapi_resource_scope(Resource.new(@resource_type, api_only?, @scope[:shallow], options), @resource_type) do
142+
# Rails 5+
143+
# Rails 8.1 changed Resource.new to accept only 3 arguments (removed options)
144+
resource_arg = if Rails::VERSION::MAJOR >= 8 && Rails::VERSION::MINOR >= 1
145+
Resource.new(@resource_type, api_only?, @scope[:shallow])
146+
else
147+
Resource.new(@resource_type, api_only?, @scope[:shallow], options)
148+
end
149+
150+
jsonapi_resource_scope(resource_arg, @resource_type) do
137151
if block_given?
138152
yield
139153
else

test/test_db-shm

-32 KB
Binary file not shown.

test/test_db-wal

-3.93 MB
Binary file not shown.

0 commit comments

Comments
 (0)