Skip to content

Commit

Permalink
Do not override Object#to_json with mimic_json if ActiveSupport is ex…
Browse files Browse the repository at this point in the history
…isted (#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
  • Loading branch information
Watson1978 authored Aug 18, 2024
1 parent f5e928a commit 2570138
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 2 deletions.
10 changes: 10 additions & 0 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
4 changes: 3 additions & 1 deletion ext/oj/mimic_json.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
11 changes: 11 additions & 0 deletions gemfiles/rails_7.1.gemfile
Original file line number Diff line number Diff line change
@@ -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 => '../'
11 changes: 11 additions & 0 deletions gemfiles/rails_7.2.gemfile
Original file line number Diff line number Diff line change
@@ -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 => '../'
5 changes: 4 additions & 1 deletion test/activesupport7/abstract_unit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 2570138

Please sign in to comment.