From 96eef89f866a1fc43f09c9107828ad9e8dc08ceb Mon Sep 17 00:00:00 2001 From: Sai Asish Y Date: Mon, 24 Aug 2026 18:32:09 -0700 Subject: [PATCH] fix ArgumentError building routes on Rails 8.1 Signed-off-by: Sai Asish Y --- lib/jsonapi/routing_ext.rb | 4 ++-- test/unit/routing_ext_test.rb | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 2 deletions(-) create mode 100644 test/unit/routing_ext_test.rb diff --git a/lib/jsonapi/routing_ext.rb b/lib/jsonapi/routing_ext.rb index b0b940138..2bc480feb 100644 --- a/lib/jsonapi/routing_ext.rb +++ b/lib/jsonapi/routing_ext.rb @@ -59,7 +59,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 @@ -133,7 +133,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_ext_test.rb b/test/unit/routing_ext_test.rb new file mode 100644 index 000000000..74bb028a0 --- /dev/null +++ b/test/unit/routing_ext_test.rb @@ -0,0 +1,34 @@ +require 'minitest/autorun' +require 'active_support/all' +require 'rails/railtie' +require 'rails/version' + +# rails/test_help wants a booted Rails.application before it will even +# load on current Rails, which this gem's own test_helper.rb can't give it +# yet. jsonapi_resources itself doesn't need a booted app, just a RouteSet, +# so this test builds the smallest environment that lets us draw routes +# with it directly. +module Rails + def self.env + ActiveSupport::StringInquirer.new('test') + end +end + +require 'action_controller' +require 'jsonapi-resources' + +class ExampleResource < JSONAPI::Resource +end + +class RoutingExtTest < Minitest::Test + def test_jsonapi_resources_draws_routes + route_set = ActionDispatch::Routing::RouteSet.new + route_set.draw do + jsonapi_resources :examples + end + + paths = route_set.routes.map { |r| r.path.spec.to_s } + assert_includes paths, '/examples(.:format)' + assert_includes paths, '/examples/:id(.:format)' + end +end