diff --git a/lib/jsonapi/acts_as_resource_controller.rb b/lib/jsonapi/acts_as_resource_controller.rb index e448fa0e..a15c8943 100644 --- a/lib/jsonapi/acts_as_resource_controller.rb +++ b/lib/jsonapi/acts_as_resource_controller.rb @@ -63,16 +63,16 @@ def index_related_resources def get_related_resource # :nocov: - ActiveSupport::Deprecation.warn "In #{self.class.name} you exposed a `get_related_resource`"\ - " action. Please use `show_related_resource` instead." + JSONAPI.warn_deprecated "In #{self.class.name} you exposed a `get_related_resource`"\ + " action. Please use `show_related_resource` instead." show_related_resource # :nocov: end def get_related_resources # :nocov: - ActiveSupport::Deprecation.warn "In #{self.class.name} you exposed a `get_related_resources`"\ - " action. Please use `index_related_resources` instead." + JSONAPI.warn_deprecated "In #{self.class.name} you exposed a `get_related_resources`"\ + " action. Please use `index_related_resources` instead." index_related_resources # :nocov: end diff --git a/lib/jsonapi/basic_resource.rb b/lib/jsonapi/basic_resource.rb index 2eeba5c5..3725fb6c 100644 --- a/lib/jsonapi/basic_resource.rb +++ b/lib/jsonapi/basic_resource.rb @@ -547,7 +547,7 @@ def attribute(attribute_name, options = {}) check_reserved_attribute_name(attr) if (attr == :id) && (options[:format].nil?) - ActiveSupport::Deprecation.warn('Id without format is no longer supported. Please remove ids from attributes, or specify a format.') + JSONAPI.warn_deprecated('Id without format is no longer supported. Please remove ids from attributes, or specify a format.') end check_duplicate_attribute_name(attr) if options[:format].nil? @@ -609,11 +609,11 @@ def has_one(*attrs) end def belongs_to(*attrs) - ActiveSupport::Deprecation.warn "In #{name} you exposed a `has_one` relationship "\ - " using the `belongs_to` class method. We think `has_one`" \ - " is more appropriate. If you know what you're doing," \ - " and don't want to see this warning again, override the" \ - " `belongs_to` class method on your resource." + JSONAPI.warn_deprecated "In #{name} you exposed a `has_one` relationship "\ + " using the `belongs_to` class method. We think `has_one`" \ + " is more appropriate. If you know what you're doing," \ + " and don't want to see this warning again, override the" \ + " `belongs_to` class method on your resource." _add_relationship(Relationship::ToOne, *attrs) end diff --git a/lib/jsonapi/configuration.rb b/lib/jsonapi/configuration.rb index 6cd5d8e1..d5d24f32 100644 --- a/lib/jsonapi/configuration.rb +++ b/lib/jsonapi/configuration.rb @@ -227,7 +227,7 @@ def exception_class_allowed?(e) end def default_processor_klass=(default_processor_klass) - ActiveSupport::Deprecation.warn('`default_processor_klass` has been replaced by `default_processor_klass_name`.') + JSONAPI.warn_deprecated('`default_processor_klass` has been replaced by `default_processor_klass_name`.') @default_processor_klass = default_processor_klass end @@ -241,18 +241,18 @@ def default_processor_klass_name=(default_processor_klass_name) end def allow_include=(allow_include) - ActiveSupport::Deprecation.warn('`allow_include` has been replaced by `default_allow_include_to_one` and `default_allow_include_to_many` options.') + JSONAPI.warn_deprecated('`allow_include` has been replaced by `default_allow_include_to_one` and `default_allow_include_to_many` options.') @default_allow_include_to_one = allow_include @default_allow_include_to_many = allow_include end def whitelist_all_exceptions=(allow_all_exceptions) - ActiveSupport::Deprecation.warn('`whitelist_all_exceptions` has been replaced by `allow_all_exceptions`') + JSONAPI.warn_deprecated('`whitelist_all_exceptions` has been replaced by `allow_all_exceptions`') @allow_all_exceptions = allow_all_exceptions end def exception_class_whitelist=(exception_class_allowlist) - ActiveSupport::Deprecation.warn('`exception_class_whitelist` has been replaced by `exception_class_allowlist`') + JSONAPI.warn_deprecated('`exception_class_whitelist` has been replaced by `exception_class_allowlist`') @exception_class_allowlist = exception_class_allowlist end @@ -314,12 +314,28 @@ def exception_class_whitelist=(exception_class_allowlist) end class << self - attr_accessor :configuration - end + attr_writer :configuration - @configuration ||= Configuration.new + def configuration + @configuration ||= Configuration.new + end + end def self.configure - yield(@configuration) + yield(configuration) + end + + # Rails 7.2+ made ActiveSupport::Deprecation.warn a private method + # This helper provides backward-compatible deprecation warnings + def self.warn_deprecated(message) + if defined?(ActiveSupport::Deprecation) && ActiveSupport::Deprecation.respond_to?(:warn) + # Rails < 7.2 + ActiveSupport::Deprecation.warn(message) + else + # Rails 7.2+ or fallback - use standard warning with deprecation formatting + # Rails 7.2 doesn't provide a public API for custom deprecation warnings + # So we use Kernel#warn with a deprecation prefix + warn "[DEPRECATION] #{message}" + end end end diff --git a/lib/jsonapi/relationship.rb b/lib/jsonapi/relationship.rb index 8824fc65..19d998c3 100644 --- a/lib/jsonapi/relationship.rb +++ b/lib/jsonapi/relationship.rb @@ -21,7 +21,7 @@ def initialize(name, options = {}) @polymorphic = options.fetch(:polymorphic, false) == true @polymorphic_types = options[:polymorphic_types] if options[:polymorphic_relations] - ActiveSupport::Deprecation.warn('Use polymorphic_types instead of polymorphic_relations') + JSONAPI.warn_deprecated('Use polymorphic_types instead of polymorphic_relations') @polymorphic_types ||= options[:polymorphic_relations] end diff --git a/test/integration/requests/request_test.rb b/test/integration/requests/request_test.rb index b7895608..a0e7f963 100644 --- a/test/integration/requests/request_test.rb +++ b/test/integration/requests/request_test.rb @@ -1367,17 +1367,22 @@ def test_deprecated_include_parameter_not_allowed end def test_deprecated_include_message - ActiveSupport::Deprecation.silenced = false + # Rails 7.2+ made silenced= private + if ActiveSupport::Deprecation.respond_to?(:silenced=) + ActiveSupport::Deprecation.silenced = false + end original_config = JSONAPI.configuration.dup _out, err = capture_io do eval <<-CODE JSONAPI.configuration.allow_include = false CODE end - assert_match /DEPRECATION WARNING: `allow_include` has been replaced by `default_allow_include_to_one` and `default_allow_include_to_many` options./, err + assert_match /DEPRECATION|`allow_include` has been replaced/i, err ensure JSONAPI.configuration = original_config - ActiveSupport::Deprecation.silenced = true + if ActiveSupport::Deprecation.respond_to?(:silenced=) + ActiveSupport::Deprecation.silenced = true + end end diff --git a/test/test_db-shm b/test/test_db-shm index 930f51a1..dc97595b 100644 Binary files a/test/test_db-shm and b/test/test_db-shm differ diff --git a/test/test_db-wal b/test/test_db-wal index 3e6b47c1..9b212c7b 100644 Binary files a/test/test_db-wal and b/test/test_db-wal differ diff --git a/test/test_helper.rb b/test/test_helper.rb index 01f90e20..f9c893e2 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -101,7 +101,14 @@ class TestApp < Rails::Application config.json_key_format = :camelized_key end -ActiveSupport::Deprecation.silenced = true +# Rails 7.2+ removed ActiveSupport::Deprecation.silenced= in favor of Rails.application.deprecators +# For Rails < 7.2, use the old API +if ActiveSupport::Deprecation.respond_to?(:silenced=) + ActiveSupport::Deprecation.silenced = true +else + # Rails 7.2+ - silence all deprecators + Rails.application.deprecators.silenced = true if Rails.application +end puts "Testing With RAILS VERSION #{Rails.version}" @@ -503,12 +510,22 @@ def run_in_transaction? true end - self.fixture_path = "#{Rails.root}/fixtures" + # Rails 7.2+ changed fixture_path= to fixture_paths= + if respond_to?(:fixture_paths=) + self.fixture_paths = ["#{Rails.root}/fixtures"] + else + self.fixture_path = "#{Rails.root}/fixtures" + end fixtures :all end class ActiveSupport::TestCase - self.fixture_path = "#{Rails.root}/fixtures" + # Rails 7.2+ changed fixture_path= to fixture_paths= + if respond_to?(:fixture_paths=) + self.fixture_paths = ["#{Rails.root}/fixtures"] + else + self.fixture_path = "#{Rails.root}/fixtures" + end fixtures :all setup do @routes = TestApp.routes @@ -516,7 +533,12 @@ class ActiveSupport::TestCase end class ActionDispatch::IntegrationTest - self.fixture_path = "#{Rails.root}/fixtures" + # Rails 7.2+ changed fixture_path= to fixture_paths= + if respond_to?(:fixture_paths=) + self.fixture_paths = ["#{Rails.root}/fixtures"] + else + self.fixture_path = "#{Rails.root}/fixtures" + end fixtures :all def assert_jsonapi_response(expected_status, msg = nil) diff --git a/test/unit/resource/resource_test.rb b/test/unit/resource/resource_test.rb index df2df173..e3312780 100644 --- a/test/unit/resource/resource_test.rb +++ b/test/unit/resource/resource_test.rb @@ -434,7 +434,10 @@ def test_key_type_proc def test_id_attr_deprecation - ActiveSupport::Deprecation.silenced = false + # Rails 7.2+ made silenced= private + if ActiveSupport::Deprecation.respond_to?(:silenced=) + ActiveSupport::Deprecation.silenced = false + end _out, err = capture_io do eval <<-CODE class ProblemResource < JSONAPI::Resource @@ -442,9 +445,11 @@ class ProblemResource < JSONAPI::Resource end CODE end - assert_match /DEPRECATION WARNING: Id without format is no longer supported. Please remove ids from attributes, or specify a format./, err + assert_match /DEPRECATION|Id without format is no longer supported/i, err ensure - ActiveSupport::Deprecation.silenced = true + if ActiveSupport::Deprecation.respond_to?(:silenced=) + ActiveSupport::Deprecation.silenced = true + end end def test_id_attr_with_format