From 25701384fd1ef44557899bd8279fa846559b4d27 Mon Sep 17 00:00:00 2001 From: Watson Date: Sun, 18 Aug 2024 23:53:24 +0900 Subject: [PATCH] Do not override Object#to_json with mimic_json if ActiveSupport is existed (#936) * Do not override Object#to_json with mimic_json * Add gemfile for Rails 7.1 / 7.2 * Add workaround for Rails 7.2 * Rails 7.2 supports Ruby 3.1 or later * Remove Rails 7.1 and 7.2 from windows lane * Revert "Do not override Object#to_json with mimic_json" This reverts commit 63df8d6f2c1181b329cd3fd4541434fea2b36036. * Do not override Object#to_json with mimic_json if ActiveSupport is existed --- .github/workflows/CI.yml | 10 ++++++++++ ext/oj/mimic_json.c | 4 +++- gemfiles/rails_7.1.gemfile | 11 +++++++++++ gemfiles/rails_7.2.gemfile | 11 +++++++++++ test/activesupport7/abstract_unit.rb | 5 ++++- 5 files changed, 39 insertions(+), 2 deletions(-) create mode 100644 gemfiles/rails_7.1.gemfile create mode 100644 gemfiles/rails_7.2.gemfile diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 46e219f3..e59d8e7b 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -30,7 +30,13 @@ jobs: - no_rails - rails_6.1 - rails_7 + - rails_7.1 + - rails_7.2 exclude: + - ruby: 2.7 + gemfile: rails_7.2 + - ruby: 3.0 + gemfile: rails_7.2 - os: macos ruby: head - os: windows @@ -39,6 +45,10 @@ jobs: gemfile: rails_6.1 - os: windows gemfile: rails_7 + - os: windows + gemfile: rails_7.1 + - os: windows + gemfile: rails_7.2 include: - ruby: '2.7' gemfile: rails_6 # End of life June 1, 2023 diff --git a/ext/oj/mimic_json.c b/ext/oj/mimic_json.c index 35ad0896..cef9d506 100644 --- a/ext/oj/mimic_json.c +++ b/ext/oj/mimic_json.c @@ -905,7 +905,9 @@ oj_define_mimic_json(int argc, VALUE *argv, VALUE self) { } oj_mimic_json_methods(json); - rb_define_method(rb_cObject, "to_json", mimic_object_to_json, -1); + if (!rb_const_defined(rb_cObject, rb_intern("ActiveSupport"))) { + rb_define_method(rb_cObject, "to_json", mimic_object_to_json, -1); + } rb_gv_set("$VERBOSE", verbose); diff --git a/gemfiles/rails_7.1.gemfile b/gemfiles/rails_7.1.gemfile new file mode 100644 index 00000000..1a4d987c --- /dev/null +++ b/gemfiles/rails_7.1.gemfile @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +source 'https://rubygems.org' + +gem 'rails', '~> 7.1.3' +gem 'sqlite3' +gem 'mutex_m' +gem 'base64' +gem 'drb' + +gemspec :path => '../' diff --git a/gemfiles/rails_7.2.gemfile b/gemfiles/rails_7.2.gemfile new file mode 100644 index 00000000..61e1aa56 --- /dev/null +++ b/gemfiles/rails_7.2.gemfile @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +source 'https://rubygems.org' + +gem 'rails', '~> 7.2.0' +gem 'sqlite3' +gem 'mutex_m' +gem 'base64' +gem 'drb' + +gemspec :path => '../' diff --git a/test/activesupport7/abstract_unit.rb b/test/activesupport7/abstract_unit.rb index 10ff6db8..bd8259cf 100644 --- a/test/activesupport7/abstract_unit.rb +++ b/test/activesupport7/abstract_unit.rb @@ -19,7 +19,10 @@ Thread.abort_on_exception = true # Show backtraces for deprecated behavior for quicker cleanup. -ActiveSupport::Deprecation.debug = true +if ActiveSupport::Deprecation.respond_to?(:debug) + # Rails 7.2 does not have ActiveSupport::Deprecation.debug + ActiveSupport::Deprecation.debug = true +end # Default to old to_time behavior but allow running tests with new behavior ActiveSupport.to_time_preserves_timezone = ENV["PRESERVE_TIMEZONES"] == "1"