mirror of
https://github.com/Growstuff/growstuff.git
synced 2026-10-30 18:58:39 -04:00
- Create AGENTS.md with layout advice for coding agents. - Update timeline feature spec to use rack_test driver and improve context descriptions. - Enhance spec_helper to log feature spec execution time. - Add support for Wikidata service mocking in specs.
68 lines
2.3 KiB
Ruby
68 lines
2.3 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
# JSONAPI::Resources (0.10.7) is currently incompatible with Rails 8.1
|
|
# because ActionDispatch::Routing::Mapper::Resources::Resource.initialize now expects keyword arguments for only/except.
|
|
# This patch ensures that it passes keyword arguments correctly.
|
|
# Remove when https://github.com/JSONAPI-Resources/jsonapi-resources/issues/1488 is fixed
|
|
|
|
if defined?(JSONAPI)
|
|
module ActionDispatch
|
|
module Routing
|
|
class Mapper
|
|
module Resources
|
|
class Resource
|
|
alias_method :original_initialize, :initialize
|
|
|
|
def initialize(entities, api_only, shallow, options = {})
|
|
# In Rails 8.1, initialize(entities, api_only, shallow, only: nil, except: nil, **options)
|
|
# and jsonapi-resources passes them in the options hash.
|
|
if options.is_a?(Hash)
|
|
only = options.delete(:only)
|
|
except = options.delete(:except)
|
|
original_initialize(entities, api_only, shallow, only: only, except: except, **options)
|
|
else
|
|
original_initialize(entities, api_only, shallow, options)
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|
|
|
|
# The gem also calls `resources name, options` with the options as a positional hash, which Rails 8.1
|
|
# deprecates ("resources received a hash argument ..."). Pass them as keywords instead.
|
|
module ActionDispatch
|
|
module Routing
|
|
class Mapper
|
|
module Resources
|
|
module KeywordOptions
|
|
def resources(*args, **options, &)
|
|
options = args.pop.merge(options) if args.last.is_a?(Hash)
|
|
super
|
|
end
|
|
end
|
|
|
|
prepend KeywordOptions
|
|
end
|
|
end
|
|
end
|
|
end
|
|
|
|
module JSONAPI
|
|
module RoutingExt
|
|
module Mapper
|
|
def jsonapi_resource_scope(resource, resource_type)
|
|
# The original implementation uses Resource.new which we patched above.
|
|
# We need to make sure we don't break Rails 5/6/7/8 logic if it were to run there.
|
|
@scope = @scope.new(scope_level_resource: resource, jsonapi_resource: resource_type)
|
|
|
|
controller(resource.resource_scope) { yield }
|
|
ensure
|
|
@scope = @scope.parent
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|