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
4 changes: 2 additions & 2 deletions lib/jsonapi/routing_ext.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
34 changes: 34 additions & 0 deletions test/unit/routing_ext_test.rb
Original file line number Diff line number Diff line change
@@ -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
Loading