Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions lib/jsonapi/routing_ext.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
38 changes: 38 additions & 0 deletions test/unit/routing_compatibility_test.rb
Original file line number Diff line number Diff line change
@@ -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
Loading