From 33e7fde77dd83d3426d32e8dcb05be184c3c0cc7 Mon Sep 17 00:00:00 2001 From: adrian-gomez Date: Thu, 5 Sep 2024 15:47:12 -0300 Subject: [PATCH 1/4] Use a custom deprecator instead of ActiveSupport::Deprecation directly --- lib/active_resource.rb | 8 ++++++++ lib/active_resource/railtie.rb | 4 ++++ lib/active_resource/validations.rb | 4 ++-- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/lib/active_resource.rb b/lib/active_resource.rb index b78617d5f3..4171c114e8 100644 --- a/lib/active_resource.rb +++ b/lib/active_resource.rb @@ -46,6 +46,14 @@ module ActiveResource autoload :InheritingHash autoload :Validations autoload :Collection + + def self.deprecator + @deprecator ||= if ActiveSupport::VERSION::STRING >= '7.2' + ActiveSupport::Deprecation.new(VERSION::STRING, 'ActiveResource') + else + ActiveSupport::Deprecation + end + end end require "active_resource/railtie" if defined?(Rails.application) diff --git a/lib/active_resource/railtie.rb b/lib/active_resource/railtie.rb index 8733e5516a..0a0492de58 100644 --- a/lib/active_resource/railtie.rb +++ b/lib/active_resource/railtie.rb @@ -21,5 +21,9 @@ class Railtie < Rails::Railtie app.config.active_job.custom_serializers << ActiveResource::ActiveJobSerializer end end + + initializer "active_resource.deprecator" do |app| + app.deprecators[:active_resource] = ActiveResource.deprecator + end end end diff --git a/lib/active_resource/validations.rb b/lib/active_resource/validations.rb index 929631ffaa..b06925b918 100644 --- a/lib/active_resource/validations.rb +++ b/lib/active_resource/validations.rb @@ -57,7 +57,7 @@ def from_json(json, save_cache = false) errors = decoded["errors"] || {} if errors.kind_of?(Array) # 3.2.1-style with array of strings - ActiveSupport::Deprecation.warn("Returning errors as an array of strings is deprecated.") + ActiveResource.deprecator.warn("Returning errors as an array of strings is deprecated.") from_array errors, save_cache else # 3.2.2+ style @@ -65,7 +65,7 @@ def from_json(json, save_cache = false) end else # <3.2-style respond_with - lacks 'errors' key - ActiveSupport::Deprecation.warn('Returning errors as a hash without a root "errors" key is deprecated.') + ActiveResource.deprecator.warn('Returning errors as a hash without a root "errors" key is deprecated.') from_hash decoded, save_cache end end From 4dfcd0d8742e5be3185fc3050683bb10760f432a Mon Sep 17 00:00:00 2001 From: adrian-gomez Date: Thu, 5 Sep 2024 15:50:01 -0300 Subject: [PATCH 2/4] Use double quotes for strings --- lib/active_resource.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/active_resource.rb b/lib/active_resource.rb index 4171c114e8..be1e00604c 100644 --- a/lib/active_resource.rb +++ b/lib/active_resource.rb @@ -48,8 +48,8 @@ module ActiveResource autoload :Collection def self.deprecator - @deprecator ||= if ActiveSupport::VERSION::STRING >= '7.2' - ActiveSupport::Deprecation.new(VERSION::STRING, 'ActiveResource') + @deprecator ||= if ActiveSupport::VERSION::STRING >= "7.2" + ActiveSupport::Deprecation.new(VERSION::STRING, "ActiveResource") else ActiveSupport::Deprecation end From b273d1f430c0ba46bf3e00bc64ae4372551b2a75 Mon Sep 17 00:00:00 2001 From: adrian-gomez Date: Wed, 25 Sep 2024 08:35:35 -0300 Subject: [PATCH 3/4] Update test to new deprecation logic --- test/cases/base_errors_test.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/cases/base_errors_test.rb b/test/cases/base_errors_test.rb index d0a3164124..96bedd69ca 100644 --- a/test/cases/base_errors_test.rb +++ b/test/cases/base_errors_test.rb @@ -116,7 +116,7 @@ def test_should_parse_json_string_errors_with_an_errors_key mock.post "/people.json", {}, %q({"errors":["Age can't be blank", "Name can't be blank", "Name must start with a letter", "Person quota full for today.", "Phone work can't be blank", "Phone is not valid"]}), 422, "Content-Type" => "application/json; charset=utf-8" end - assert_deprecated(/as an array/) do + assert_deprecated(/as an array/, ActiveResource.deprecator) do invalid_user_using_format(:json) do assert @person.errors[:name].any? assert_equal ["can't be blank"], @person.errors[:age] @@ -133,7 +133,7 @@ def test_should_parse_3_1_style_json_errors mock.post "/people.json", {}, %q({"age":["can't be blank"],"name":["can't be blank", "must start with a letter"],"person":["quota full for today."],"phone_work":["can't be blank"],"phone":["is not valid"]}), 422, "Content-Type" => "application/json; charset=utf-8" end - assert_deprecated(/without a root/) do + assert_deprecated(/without a root/, ActiveResource.deprecator) do invalid_user_using_format(:json) do assert @person.errors[:name].any? assert_equal ["can't be blank"], @person.errors[:age] From 1063d6a5f72a59d783296a4f017d7ccab873e2ce Mon Sep 17 00:00:00 2001 From: adrian-gomez Date: Wed, 25 Sep 2024 08:42:02 -0300 Subject: [PATCH 4/4] Test with Rails 7.2 and Ruby 3.3 --- .github/workflows/ci.yml | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d1b3712d4f..37b73d33c8 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -63,6 +63,17 @@ jobs: - ruby: "3.3" env: BRANCH: 7-1-stable + - ruby: "3.1" + env: + BRANCH: 7-2-stable + experimental: false + - ruby: "3.2" + env: + BRANCH: 7-2-stable + experimental: false + - ruby: "3.3" + env: + BRANCH: 7-2-stable - ruby: "3.1" env: BRANCH: main