From 408c405d5846140409ae82a205ff12f896af1160 Mon Sep 17 00:00:00 2001 From: Sean Devine Date: Thu, 8 Oct 2026 17:01:42 -0700 Subject: [PATCH 1/3] fix: pass routing keywords explicitly on Rails 8.1 --- lib/jsonapi/routing_ext.rb | 8 +++--- test/unit/routing_compatibility_test.rb | 38 +++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 4 deletions(-) create mode 100644 test/unit/routing_compatibility_test.rb diff --git a/lib/jsonapi/routing_ext.rb b/lib/jsonapi/routing_ext.rb index 5aae3537e..13ff8a86f 100644 --- a/lib/jsonapi/routing_ext.rb +++ b/lib/jsonapi/routing_ext.rb @@ -44,7 +44,7 @@ def jsonapi_resource(*resources, &_block) options[:except] << :destroy unless options[:except].include?(:destroy) || options[:except].include?('destroy') end - resource @resource_type, options do + resource @resource_type, **options do # :nocov: if @scope.respond_to? :[]= # Rails 4 @@ -57,7 +57,7 @@ def jsonapi_resource(*resources, &_block) end else # Rails 5 - jsonapi_resource_scope(SingletonResource.new(@resource_type, api_only?, @scope[:shallow], options), @resource_type) do + jsonapi_resource_scope(SingletonResource.new(@resource_type, api_only?, @scope[:shallow], **options), @resource_type) do if block_given? yield else @@ -119,7 +119,7 @@ def jsonapi_resources(*resources, &_block) options[:except] << :destroy unless options[:except].include?(:destroy) || options[:except].include?('destroy') end - resources @resource_type, options do + resources @resource_type, **options do # :nocov: if @scope.respond_to? :[]= # Rails 4 @@ -131,7 +131,7 @@ def jsonapi_resources(*resources, &_block) end else # Rails 5 - jsonapi_resource_scope(Resource.new(@resource_type, api_only?, @scope[:shallow], options), @resource_type) do + jsonapi_resource_scope(Resource.new(@resource_type, api_only?, @scope[:shallow], **options), @resource_type) do if block_given? yield else diff --git a/test/unit/routing_compatibility_test.rb b/test/unit/routing_compatibility_test.rb new file mode 100644 index 000000000..6ba466fd5 --- /dev/null +++ b/test/unit/routing_compatibility_test.rb @@ -0,0 +1,38 @@ +require 'logger' +require 'minitest/autorun' +require 'active_support/all' +require 'rails' +require 'action_controller' +require 'jsonapi-resources' + +class RoutingCompatibilityResource < JSONAPI::Resource +end + +class RoutingProfileResource < JSONAPI::Resource + singleton singleton_key: -> (context) { context[:current_user_id] } +end + +class RoutingCompatibilityTest < Minitest::Test + def test_plural_routes_preserve_keyword_options + routes = ActionDispatch::Routing::RouteSet.new + routes.draw do + jsonapi_resources :routing_compatibilities, controller: 'examples', only: [:index, :show] + end + + assert_equal '/routing-compatibilities', routes.url_helpers.routing_compatibilities_path + assert_equal '/routing-compatibilities/42', routes.url_helpers.routing_compatibility_path(42) + assert_equal ['examples'], routes.routes.map { |route| route.defaults[:controller] }.uniq + refute_includes routes.routes.map(&:verb), 'DELETE' + end + + def test_singleton_routes_preserve_keyword_options + routes = ActionDispatch::Routing::RouteSet.new + routes.draw do + jsonapi_resource :routing_profile, controller: 'profiles', only: [:show] + end + + assert_equal '/routing-profile', routes.url_helpers.routing_profile_path + assert_equal ['profiles'], routes.routes.map { |route| route.defaults[:controller] }.uniq + refute_includes routes.routes.map(&:verb), 'DELETE' + end +end From 7c44f3e0ca7cba25871df9c7d501be42c406c16c Mon Sep 17 00:00:00 2001 From: Benjamin Fleischer Date: Wed, 21 Oct 2026 19:29:17 -0500 Subject: [PATCH 2/3] test: load logger before Rails test dependencies --- test/test_helper.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/test/test_helper.rb b/test/test_helper.rb index 30d439ddb..b51eeb6e7 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -1,3 +1,4 @@ +require 'logger' require 'simplecov' require 'database_cleaner' From ab9550034d3a5ec3c0f13a68076e6c7e5e00d574 Mon Sep 17 00:00:00 2001 From: Benjamin Fleischer Date: Wed, 21 Oct 2026 19:29:20 -0500 Subject: [PATCH 3/3] test: honor configured route format in routing regressions --- test/unit/routing_compatibility_test.rb | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/test/unit/routing_compatibility_test.rb b/test/unit/routing_compatibility_test.rb index 6ba466fd5..5e3fb1aa0 100644 --- a/test/unit/routing_compatibility_test.rb +++ b/test/unit/routing_compatibility_test.rb @@ -19,8 +19,9 @@ def test_plural_routes_preserve_keyword_options jsonapi_resources :routing_compatibilities, controller: 'examples', only: [:index, :show] end - assert_equal '/routing-compatibilities', routes.url_helpers.routing_compatibilities_path - assert_equal '/routing-compatibilities/42', routes.url_helpers.routing_compatibility_path(42) + path = JSONAPI.configuration.route_formatter.format('routing_compatibilities') + assert_equal "/#{path}", routes.url_helpers.routing_compatibilities_path + assert_equal "/#{path}/42", routes.url_helpers.routing_compatibility_path(42) assert_equal ['examples'], routes.routes.map { |route| route.defaults[:controller] }.uniq refute_includes routes.routes.map(&:verb), 'DELETE' end @@ -31,7 +32,7 @@ def test_singleton_routes_preserve_keyword_options jsonapi_resource :routing_profile, controller: 'profiles', only: [:show] end - assert_equal '/routing-profile', routes.url_helpers.routing_profile_path + assert_equal "/#{JSONAPI.configuration.route_formatter.format('routing_profile')}", routes.url_helpers.routing_profile_path assert_equal ['profiles'], routes.routes.map { |route| route.defaults[:controller] }.uniq refute_includes routes.routes.map(&:verb), 'DELETE' end