Skip to content

Commit 2570138

Browse files
authored
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 63df8d6. * Do not override Object#to_json with mimic_json if ActiveSupport is existed
1 parent f5e928a commit 2570138

File tree

5 files changed

+39
-2
lines changed

5 files changed

+39
-2
lines changed

.github/workflows/CI.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,13 @@ jobs:
3030
- no_rails
3131
- rails_6.1
3232
- rails_7
33+
- rails_7.1
34+
- rails_7.2
3335
exclude:
36+
- ruby: 2.7
37+
gemfile: rails_7.2
38+
- ruby: 3.0
39+
gemfile: rails_7.2
3440
- os: macos
3541
ruby: head
3642
- os: windows
@@ -39,6 +45,10 @@ jobs:
3945
gemfile: rails_6.1
4046
- os: windows
4147
gemfile: rails_7
48+
- os: windows
49+
gemfile: rails_7.1
50+
- os: windows
51+
gemfile: rails_7.2
4252
include:
4353
- ruby: '2.7'
4454
gemfile: rails_6 # End of life June 1, 2023

ext/oj/mimic_json.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -905,7 +905,9 @@ oj_define_mimic_json(int argc, VALUE *argv, VALUE self) {
905905
}
906906
oj_mimic_json_methods(json);
907907

908-
rb_define_method(rb_cObject, "to_json", mimic_object_to_json, -1);
908+
if (!rb_const_defined(rb_cObject, rb_intern("ActiveSupport"))) {
909+
rb_define_method(rb_cObject, "to_json", mimic_object_to_json, -1);
910+
}
909911

910912
rb_gv_set("$VERBOSE", verbose);
911913

gemfiles/rails_7.1.gemfile

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# frozen_string_literal: true
2+
3+
source 'https://rubygems.org'
4+
5+
gem 'rails', '~> 7.1.3'
6+
gem 'sqlite3'
7+
gem 'mutex_m'
8+
gem 'base64'
9+
gem 'drb'
10+
11+
gemspec :path => '../'

gemfiles/rails_7.2.gemfile

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# frozen_string_literal: true
2+
3+
source 'https://rubygems.org'
4+
5+
gem 'rails', '~> 7.2.0'
6+
gem 'sqlite3'
7+
gem 'mutex_m'
8+
gem 'base64'
9+
gem 'drb'
10+
11+
gemspec :path => '../'

test/activesupport7/abstract_unit.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@
1919
Thread.abort_on_exception = true
2020

2121
# Show backtraces for deprecated behavior for quicker cleanup.
22-
ActiveSupport::Deprecation.debug = true
22+
if ActiveSupport::Deprecation.respond_to?(:debug)
23+
# Rails 7.2 does not have ActiveSupport::Deprecation.debug
24+
ActiveSupport::Deprecation.debug = true
25+
end
2326

2427
# Default to old to_time behavior but allow running tests with new behavior
2528
ActiveSupport.to_time_preserves_timezone = ENV["PRESERVE_TIMEZONES"] == "1"

0 commit comments

Comments
 (0)