From 2bfaad88f81cbb045abca4d080e0e8bb06d720e0 Mon Sep 17 00:00:00 2001 From: Mohd Khairi Mohd Adnan Date: Tue, 22 Aug 2023 18:01:24 +0800 Subject: [PATCH] Add support for Rails 7 - Fixed constantize method to make compatible with rails 7 - Drop support for ruby 2.5 --- .github/workflows/rspec.yml | 39 ++++++++---------- Appraisals | 16 ++++++-- Gemfile.lock | 62 ++++++++++++++++------------ gemfiles/rails_5.2.gemfile | 2 +- gemfiles/rails_5.2.gemfile.lock | 52 +++++++++++------------ gemfiles/rails_6.0.gemfile | 2 +- gemfiles/rails_6.0.gemfile.lock | 54 ++++++++++++------------ gemfiles/rails_6.1.gemfile | 2 +- gemfiles/rails_6.1.gemfile.lock | 54 ++++++++++++------------ gemfiles/rails_7.0.gemfile | 7 ++++ gemfiles/rails_7.0.gemfile.lock | 56 +++++++++++++++++++++++++ gemfiles/rails_7.1.gemfile | 7 ++++ gemfiles/rails_7.1.gemfile.lock | 68 +++++++++++++++++++++++++++++++ lib/nested_record.rb | 1 + lib/nested_record/base.rb | 6 +-- lib/nested_record/lookup_const.rb | 24 +++++++++-- lib/nested_record/version.rb | 2 +- nested_record.gemspec | 2 +- spec/support/model.rb | 18 +++++++- 19 files changed, 331 insertions(+), 143 deletions(-) create mode 100644 gemfiles/rails_7.0.gemfile create mode 100644 gemfiles/rails_7.0.gemfile.lock create mode 100644 gemfiles/rails_7.1.gemfile create mode 100644 gemfiles/rails_7.1.gemfile.lock diff --git a/.github/workflows/rspec.yml b/.github/workflows/rspec.yml index 379b83c..870f4d5 100644 --- a/.github/workflows/rspec.yml +++ b/.github/workflows/rspec.yml @@ -12,17 +12,28 @@ jobs: strategy: matrix: ruby: - - 2.5.x - - 2.6.x - - 2.7.x - - 3.0.x + - "2.6" + - "2.7" + - "3.0" + - "3.1" + - "3.2" gemfile: - gemfiles/rails_5.2.gemfile - gemfiles/rails_6.0.gemfile - gemfiles/rails_6.1.gemfile + - gemfiles/rails_7.0.gemfile + - gemfiles/rails_7.1.gemfile exclude: - gemfile: gemfiles/rails_5.2.gemfile - ruby: 3.0.x + ruby: "3.0" + - gemfile: gemfiles/rails_5.2.gemfile + ruby: "3.1" + - gemfile: gemfiles/rails_5.2.gemfile + ruby: "3.2" + - gemfile: gemfiles/rails_7.0.gemfile + ruby: "2.6" + - gemfile: gemfiles/rails_7.1.gemfile + ruby: "2.6" env: BUNDLE_GEMFILE: ${{ format('{0}/{1}', github.workspace, matrix.gemfile) }} BUNDLE_PATH: ${{ format('{0}/vendor/bundle', github.workspace) }} @@ -31,23 +42,9 @@ jobs: - name: Checkout uses: actions/checkout@v1 - name: Setup ruby - uses: actions/setup-ruby@v1 + uses: ruby/setup-ruby@v1 with: ruby-version: ${{ matrix.ruby }} - - name: Install Bundler - run: gem install bundler:2.2.14 - - name: Cache Bundler - uses: actions/cache@v1 - id: cache-bundler - with: - path: vendor/bundle - key: ${{ runner.os }}-gem-${{ matrix.ruby }}-${{ hashFiles(format('{0}/{1}.lock', github.workspace, matrix.gemfile)) }} - restore-keys: | - ${{ runner.os }}-gem-${{ matrix.ruby }}- - - name: Install Bundler dependencies - if: steps.cache-bundler.outputs.cache-hit != 'true' - run: bundle install --jobs=4 - - name: Check Bunlder dependencies - run: bundle check + bundler-cache: true - name: RSpec run: bundle exec rspec diff --git a/Appraisals b/Appraisals index 956aa5b..3adc306 100644 --- a/Appraisals +++ b/Appraisals @@ -1,11 +1,21 @@ +# frozen_string_literal: true + appraise "rails-5.2" do - gem 'activemodel', '~> 5.2.4' + gem 'activemodel', '~> 5.2.8.1' end appraise "rails-6.0" do - gem 'activemodel', '~> 6.0.3' + gem 'activemodel', '~> 6.0.6.1' end appraise "rails-6.1" do - gem 'activemodel', '~> 6.1.3' + gem 'activemodel', '~> 6.1.7.6' +end + +appraise "rails-7.0" do + gem 'activemodel', '~> 7.0.8' +end + +appraise "rails-7.1" do + gem 'activemodel', '~> 7.1.1' end diff --git a/Gemfile.lock b/Gemfile.lock index 007d5f7..cc2014d 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,47 +1,57 @@ PATH remote: . specs: - nested_record (1.1.0) - activemodel (>= 4.2, < 6.2) + nested_record (1.1.1) + activemodel (> 5.2, < 7.2) GEM remote: https://rubygems.org/ specs: - activemodel (6.1.3) - activesupport (= 6.1.3) - activesupport (6.1.3) + activemodel (7.1.1) + activesupport (= 7.1.1) + activesupport (7.1.1) + base64 + bigdecimal concurrent-ruby (~> 1.0, >= 1.0.2) + connection_pool (>= 2.2.5) + drb i18n (>= 1.6, < 2) minitest (>= 5.1) + mutex_m tzinfo (~> 2.0) - zeitwerk (~> 2.3) - appraisal (2.4.0) + appraisal (2.5.0) bundler rake thor (>= 0.14.0) - concurrent-ruby (1.1.8) - diff-lcs (1.4.4) - i18n (1.8.9) + base64 (0.1.1) + bigdecimal (3.1.4) + concurrent-ruby (1.2.2) + connection_pool (2.4.1) + diff-lcs (1.5.0) + drb (2.1.1) + ruby2_keywords + i18n (1.14.1) concurrent-ruby (~> 1.0) - minitest (5.14.4) - rake (13.0.3) - rspec (3.10.0) - rspec-core (~> 3.10.0) - rspec-expectations (~> 3.10.0) - rspec-mocks (~> 3.10.0) - rspec-core (3.10.1) - rspec-support (~> 3.10.0) - rspec-expectations (3.10.1) + minitest (5.20.0) + mutex_m (0.1.2) + rake (13.0.6) + rspec (3.12.0) + rspec-core (~> 3.12.0) + rspec-expectations (~> 3.12.0) + rspec-mocks (~> 3.12.0) + rspec-core (3.12.2) + rspec-support (~> 3.12.0) + rspec-expectations (3.12.3) diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.10.0) - rspec-mocks (3.10.2) + rspec-support (~> 3.12.0) + rspec-mocks (3.12.6) diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.10.0) - rspec-support (3.10.2) - thor (1.1.0) - tzinfo (2.0.4) + rspec-support (~> 3.12.0) + rspec-support (3.12.1) + ruby2_keywords (0.0.5) + thor (1.2.2) + tzinfo (2.0.6) concurrent-ruby (~> 1.0) - zeitwerk (2.4.2) PLATFORMS ruby diff --git a/gemfiles/rails_5.2.gemfile b/gemfiles/rails_5.2.gemfile index c6a5928..60ef567 100644 --- a/gemfiles/rails_5.2.gemfile +++ b/gemfiles/rails_5.2.gemfile @@ -2,6 +2,6 @@ source "https://rubygems.org" -gem "activemodel", "~> 5.2.4" +gem "activemodel", "~> 5.2.8.1" gemspec path: "../" diff --git a/gemfiles/rails_5.2.gemfile.lock b/gemfiles/rails_5.2.gemfile.lock index 1616095..0f77e9e 100644 --- a/gemfiles/rails_5.2.gemfile.lock +++ b/gemfiles/rails_5.2.gemfile.lock @@ -1,52 +1,52 @@ PATH remote: .. specs: - nested_record (1.1.0) - activemodel (>= 4.2, < 6.2) + nested_record (1.1.1) + activemodel (> 5.2, < 7.2) GEM remote: https://rubygems.org/ specs: - activemodel (5.2.6) - activesupport (= 5.2.6) - activesupport (5.2.6) + activemodel (5.2.8.1) + activesupport (= 5.2.8.1) + activesupport (5.2.8.1) concurrent-ruby (~> 1.0, >= 1.0.2) i18n (>= 0.7, < 2) minitest (~> 5.1) tzinfo (~> 1.1) - appraisal (2.4.0) + appraisal (2.5.0) bundler rake thor (>= 0.14.0) - concurrent-ruby (1.1.9) - diff-lcs (1.4.4) - i18n (1.8.10) + concurrent-ruby (1.2.2) + diff-lcs (1.5.0) + i18n (1.14.1) concurrent-ruby (~> 1.0) - minitest (5.14.4) - rake (13.0.3) - rspec (3.10.0) - rspec-core (~> 3.10.0) - rspec-expectations (~> 3.10.0) - rspec-mocks (~> 3.10.0) - rspec-core (3.10.1) - rspec-support (~> 3.10.0) - rspec-expectations (3.10.1) + minitest (5.20.0) + rake (13.0.6) + rspec (3.12.0) + rspec-core (~> 3.12.0) + rspec-expectations (~> 3.12.0) + rspec-mocks (~> 3.12.0) + rspec-core (3.12.2) + rspec-support (~> 3.12.0) + rspec-expectations (3.12.3) diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.10.0) - rspec-mocks (3.10.2) + rspec-support (~> 3.12.0) + rspec-mocks (3.12.6) diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.10.0) - rspec-support (3.10.2) - thor (1.1.0) + rspec-support (~> 3.12.0) + rspec-support (3.12.1) + thor (1.3.0) thread_safe (0.3.6) - tzinfo (1.2.9) + tzinfo (1.2.11) thread_safe (~> 0.1) PLATFORMS ruby DEPENDENCIES - activemodel (~> 5.2.4) + activemodel (~> 5.2.8.1) appraisal bundler (>= 2) nested_record! @@ -54,4 +54,4 @@ DEPENDENCIES rspec (~> 3.0) BUNDLED WITH - 2.2.22 + 2.3.22 diff --git a/gemfiles/rails_6.0.gemfile b/gemfiles/rails_6.0.gemfile index 69f1cbb..3073b40 100644 --- a/gemfiles/rails_6.0.gemfile +++ b/gemfiles/rails_6.0.gemfile @@ -2,6 +2,6 @@ source "https://rubygems.org" -gem "activemodel", "~> 6.0.3" +gem "activemodel", "~> 6.0.6.1" gemspec path: "../" diff --git a/gemfiles/rails_6.0.gemfile.lock b/gemfiles/rails_6.0.gemfile.lock index f449933..63f2bb0 100644 --- a/gemfiles/rails_6.0.gemfile.lock +++ b/gemfiles/rails_6.0.gemfile.lock @@ -1,54 +1,54 @@ PATH remote: .. specs: - nested_record (1.1.0) - activemodel (>= 4.2, < 6.2) + nested_record (1.1.1) + activemodel (> 5.2, < 7.2) GEM remote: https://rubygems.org/ specs: - activemodel (6.0.4.1) - activesupport (= 6.0.4.1) - activesupport (6.0.4.1) + activemodel (6.0.6.1) + activesupport (= 6.0.6.1) + activesupport (6.0.6.1) concurrent-ruby (~> 1.0, >= 1.0.2) i18n (>= 0.7, < 2) minitest (~> 5.1) tzinfo (~> 1.1) zeitwerk (~> 2.2, >= 2.2.2) - appraisal (2.4.0) + appraisal (2.5.0) bundler rake thor (>= 0.14.0) - concurrent-ruby (1.1.9) - diff-lcs (1.4.4) - i18n (1.8.10) + concurrent-ruby (1.2.2) + diff-lcs (1.5.0) + i18n (1.14.1) concurrent-ruby (~> 1.0) - minitest (5.14.4) - rake (13.0.3) - rspec (3.10.0) - rspec-core (~> 3.10.0) - rspec-expectations (~> 3.10.0) - rspec-mocks (~> 3.10.0) - rspec-core (3.10.1) - rspec-support (~> 3.10.0) - rspec-expectations (3.10.1) + minitest (5.20.0) + rake (13.0.6) + rspec (3.12.0) + rspec-core (~> 3.12.0) + rspec-expectations (~> 3.12.0) + rspec-mocks (~> 3.12.0) + rspec-core (3.12.2) + rspec-support (~> 3.12.0) + rspec-expectations (3.12.3) diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.10.0) - rspec-mocks (3.10.2) + rspec-support (~> 3.12.0) + rspec-mocks (3.12.6) diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.10.0) - rspec-support (3.10.2) - thor (1.1.0) + rspec-support (~> 3.12.0) + rspec-support (3.12.1) + thor (1.3.0) thread_safe (0.3.6) - tzinfo (1.2.9) + tzinfo (1.2.11) thread_safe (~> 0.1) - zeitwerk (2.5.1) + zeitwerk (2.6.12) PLATFORMS ruby DEPENDENCIES - activemodel (~> 6.0.3) + activemodel (~> 6.0.6.1) appraisal bundler (>= 2) nested_record! @@ -56,4 +56,4 @@ DEPENDENCIES rspec (~> 3.0) BUNDLED WITH - 2.2.22 + 2.4.20 diff --git a/gemfiles/rails_6.1.gemfile b/gemfiles/rails_6.1.gemfile index 9fece02..64b942d 100644 --- a/gemfiles/rails_6.1.gemfile +++ b/gemfiles/rails_6.1.gemfile @@ -2,6 +2,6 @@ source "https://rubygems.org" -gem "activemodel", "~> 6.1.3" +gem "activemodel", "~> 6.1.7.6" gemspec path: "../" diff --git a/gemfiles/rails_6.1.gemfile.lock b/gemfiles/rails_6.1.gemfile.lock index 60e48b4..f757170 100644 --- a/gemfiles/rails_6.1.gemfile.lock +++ b/gemfiles/rails_6.1.gemfile.lock @@ -1,53 +1,53 @@ PATH remote: .. specs: - nested_record (1.1.0) - activemodel (>= 4.2, < 6.2) + nested_record (1.1.1) + activemodel (> 5.2, < 7.2) GEM remote: https://rubygems.org/ specs: - activemodel (6.1.4.1) - activesupport (= 6.1.4.1) - activesupport (6.1.4.1) + activemodel (6.1.7.6) + activesupport (= 6.1.7.6) + activesupport (6.1.7.6) concurrent-ruby (~> 1.0, >= 1.0.2) i18n (>= 1.6, < 2) minitest (>= 5.1) tzinfo (~> 2.0) zeitwerk (~> 2.3) - appraisal (2.4.0) + appraisal (2.5.0) bundler rake thor (>= 0.14.0) - concurrent-ruby (1.1.9) - diff-lcs (1.4.4) - i18n (1.8.10) + concurrent-ruby (1.2.2) + diff-lcs (1.5.0) + i18n (1.14.1) concurrent-ruby (~> 1.0) - minitest (5.14.4) - rake (13.0.3) - rspec (3.10.0) - rspec-core (~> 3.10.0) - rspec-expectations (~> 3.10.0) - rspec-mocks (~> 3.10.0) - rspec-core (3.10.1) - rspec-support (~> 3.10.0) - rspec-expectations (3.10.1) + minitest (5.20.0) + rake (13.0.6) + rspec (3.12.0) + rspec-core (~> 3.12.0) + rspec-expectations (~> 3.12.0) + rspec-mocks (~> 3.12.0) + rspec-core (3.12.2) + rspec-support (~> 3.12.0) + rspec-expectations (3.12.3) diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.10.0) - rspec-mocks (3.10.2) + rspec-support (~> 3.12.0) + rspec-mocks (3.12.6) diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.10.0) - rspec-support (3.10.2) - thor (1.1.0) - tzinfo (2.0.4) + rspec-support (~> 3.12.0) + rspec-support (3.12.1) + thor (1.3.0) + tzinfo (2.0.6) concurrent-ruby (~> 1.0) - zeitwerk (2.5.1) + zeitwerk (2.6.12) PLATFORMS ruby DEPENDENCIES - activemodel (~> 6.1.3) + activemodel (~> 6.1.7.6) appraisal bundler (>= 2) nested_record! @@ -55,4 +55,4 @@ DEPENDENCIES rspec (~> 3.0) BUNDLED WITH - 2.2.22 + 2.4.20 diff --git a/gemfiles/rails_7.0.gemfile b/gemfiles/rails_7.0.gemfile new file mode 100644 index 0000000..96c12d3 --- /dev/null +++ b/gemfiles/rails_7.0.gemfile @@ -0,0 +1,7 @@ +# This file was generated by Appraisal + +source "https://rubygems.org" + +gem "activemodel", "~> 7.0.8" + +gemspec path: "../" diff --git a/gemfiles/rails_7.0.gemfile.lock b/gemfiles/rails_7.0.gemfile.lock new file mode 100644 index 0000000..c87ff95 --- /dev/null +++ b/gemfiles/rails_7.0.gemfile.lock @@ -0,0 +1,56 @@ +PATH + remote: .. + specs: + nested_record (1.1.1) + activemodel (> 5.2, < 7.2) + +GEM + remote: https://rubygems.org/ + specs: + activemodel (7.0.8) + activesupport (= 7.0.8) + activesupport (7.0.8) + concurrent-ruby (~> 1.0, >= 1.0.2) + i18n (>= 1.6, < 2) + minitest (>= 5.1) + tzinfo (~> 2.0) + appraisal (2.5.0) + bundler + rake + thor (>= 0.14.0) + concurrent-ruby (1.2.2) + diff-lcs (1.5.0) + i18n (1.14.1) + concurrent-ruby (~> 1.0) + minitest (5.20.0) + rake (13.0.6) + rspec (3.12.0) + rspec-core (~> 3.12.0) + rspec-expectations (~> 3.12.0) + rspec-mocks (~> 3.12.0) + rspec-core (3.12.2) + rspec-support (~> 3.12.0) + rspec-expectations (3.12.3) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.12.0) + rspec-mocks (3.12.6) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.12.0) + rspec-support (3.12.1) + thor (1.3.0) + tzinfo (2.0.6) + concurrent-ruby (~> 1.0) + +PLATFORMS + ruby + +DEPENDENCIES + activemodel (~> 7.0.8) + appraisal + bundler (>= 2) + nested_record! + rake (~> 13.0) + rspec (~> 3.0) + +BUNDLED WITH + 2.4.20 diff --git a/gemfiles/rails_7.1.gemfile b/gemfiles/rails_7.1.gemfile new file mode 100644 index 0000000..17dbc1a --- /dev/null +++ b/gemfiles/rails_7.1.gemfile @@ -0,0 +1,7 @@ +# This file was generated by Appraisal + +source "https://rubygems.org" + +gem "activemodel", "~> 7.1.1" + +gemspec path: "../" diff --git a/gemfiles/rails_7.1.gemfile.lock b/gemfiles/rails_7.1.gemfile.lock new file mode 100644 index 0000000..98e737c --- /dev/null +++ b/gemfiles/rails_7.1.gemfile.lock @@ -0,0 +1,68 @@ +PATH + remote: .. + specs: + nested_record (1.1.1) + activemodel (> 5.2, < 7.2) + +GEM + remote: https://rubygems.org/ + specs: + activemodel (7.1.1) + activesupport (= 7.1.1) + activesupport (7.1.1) + base64 + bigdecimal + concurrent-ruby (~> 1.0, >= 1.0.2) + connection_pool (>= 2.2.5) + drb + i18n (>= 1.6, < 2) + minitest (>= 5.1) + mutex_m + tzinfo (~> 2.0) + appraisal (2.5.0) + bundler + rake + thor (>= 0.14.0) + base64 (0.1.1) + bigdecimal (3.1.4) + concurrent-ruby (1.2.2) + connection_pool (2.4.1) + diff-lcs (1.5.0) + drb (2.1.1) + ruby2_keywords + i18n (1.14.1) + concurrent-ruby (~> 1.0) + minitest (5.20.0) + mutex_m (0.1.2) + rake (13.0.6) + rspec (3.12.0) + rspec-core (~> 3.12.0) + rspec-expectations (~> 3.12.0) + rspec-mocks (~> 3.12.0) + rspec-core (3.12.2) + rspec-support (~> 3.12.0) + rspec-expectations (3.12.3) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.12.0) + rspec-mocks (3.12.6) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.12.0) + rspec-support (3.12.1) + ruby2_keywords (0.0.5) + thor (1.3.0) + tzinfo (2.0.6) + concurrent-ruby (~> 1.0) + +PLATFORMS + ruby + +DEPENDENCIES + activemodel (~> 7.1.1) + appraisal + bundler (>= 2) + nested_record! + rake (~> 13.0) + rspec (~> 3.0) + +BUNDLED WITH + 2.4.20 diff --git a/lib/nested_record.rb b/lib/nested_record.rb index 805bd0a..e6bbe54 100644 --- a/lib/nested_record.rb +++ b/lib/nested_record.rb @@ -5,6 +5,7 @@ module NestedRecord require 'active_model' require 'active_support/dependencies' + require 'active_support/inflector' require 'active_support/concern' require 'active_support/json' diff --git a/lib/nested_record/base.rb b/lib/nested_record/base.rb index de95e67..070be27 100644 --- a/lib/nested_record/base.rb +++ b/lib/nested_record/base.rb @@ -143,11 +143,11 @@ def find_subtype(type_name) subclass ||= begin if type_name.start_with?('::') - ActiveSupport::Dependencies.constantize(type_name) + NestedRecord.constantize(type_name) elsif subtypes_store_full? - ActiveSupport::Dependencies.constantize(type_name) + NestedRecord.constantize(type_name) elsif subtypes_namespace - ActiveSupport::Dependencies.safe_constantize("#{subtypes_namespace}::#{type_name}") || ActiveSupport::Dependencies.constantize(type_name) + NestedRecord.safe_constantize("#{subtypes_namespace}::#{type_name}") || NestedRecord.constantize(type_name) else NestedRecord.lookup_const(self, type_name) end diff --git a/lib/nested_record/lookup_const.rb b/lib/nested_record/lookup_const.rb index 9654f05..fef3a7b 100644 --- a/lib/nested_record/lookup_const.rb +++ b/lib/nested_record/lookup_const.rb @@ -1,18 +1,36 @@ # frozen_string_literal: true module NestedRecord - # Derived from Rails source: https://github.com/rails/rails/blob/98a57aa5f610bc66af31af409c72173cdeeb3c9e/activerecord/lib/active_record/inheritance.rb#L181-L207 + # TODO: Remove this when we drop support for Rails < 7.0 + if ActiveSupport::VERSION::MAJOR < 7 + def self.constantize(type_name) + ActiveSupport::Dependencies.constantize(type_name) + end + + def self.safe_constantize(type_name) + ActiveSupport::Dependencies.safe_constantize(type_name) + end + else + def self.constantize(type_name) + type_name.constantize + end + def self.safe_constantize(type_name) + type_name.safe_constantize + end + end + + # Derived from Rails source: https://github.com/rails/rails/blob/98a57aa5f610bc66af31af409c72173cdeeb3c9e/activerecord/lib/active_record/inheritance.rb#L181-L207 def self.lookup_const(owner, type_name) if type_name.start_with?('::') - ActiveSupport::Dependencies.constantize(type_name) + NestedRecord.constantize(type_name) else candidates = [] owner.name.scan(/::|$/) { candidates.unshift "#{$`}::#{type_name}" } candidates << type_name candidates.each do |candidate| - constant = ActiveSupport::Dependencies.safe_constantize(candidate) + constant = NestedRecord.safe_constantize(candidate) return constant if candidate == constant.to_s end diff --git a/lib/nested_record/version.rb b/lib/nested_record/version.rb index 1ff4cc1..16ce093 100644 --- a/lib/nested_record/version.rb +++ b/lib/nested_record/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module NestedRecord - VERSION = '1.1.0' + VERSION = '1.1.1' end diff --git a/nested_record.gemspec b/nested_record.gemspec index 1a00aec..5dce119 100644 --- a/nested_record.gemspec +++ b/nested_record.gemspec @@ -27,5 +27,5 @@ Gem::Specification.new do |spec| spec.add_development_dependency "rspec", "~> 3.0" spec.add_development_dependency "appraisal" - spec.add_dependency "activemodel", ">= 4.2", "< 6.2" + spec.add_dependency "activemodel", "> 5.2", "< 7.2" end diff --git a/spec/support/model.rb b/spec/support/model.rb index 84ae009..46e77f9 100644 --- a/spec/support/model.rb +++ b/spec/support/model.rb @@ -64,9 +64,19 @@ def read_attribute(attr) module Erase def erase_test_consts Array(@test_consts).reverse_each do |klass| - ActiveSupport::Dependencies.remove_constant(klass.name) + remove_constant(klass.name) + end + ActiveSupport::Dependencies.clear unless zeitwerk? + end + + def remove_constant(klass_name) + if ActiveSupport::Dependencies.respond_to?(:remove_constant) + ActiveSupport::Dependencies.remove_constant(klass_name) + else + base, _, object = klass_name.to_s.rpartition('::') + base = base.empty? ? Object : NestedRecord.constantize(base) + base.send :remove_const, object end - ActiveSupport::Dependencies.clear end def test_const_dig_name!(name) @@ -85,5 +95,9 @@ def test_const_dig_name!(name) end [namespace, name] end + + def zeitwerk? + ActiveSupport::VERSION::MAJOR >= 7 + end end end