From 8f3e145e368cc725bb2bf3cfbeb1ff8b3f4dfcb1 Mon Sep 17 00:00:00 2001 From: Yaroslav Markin Date: Wed, 27 Aug 2025 23:33:53 +0300 Subject: [PATCH 1/7] Test Rails 7.0 and 7.2 separately --- .github/workflows/rspec.yml | 6 ++++-- gemfiles/{rails7.gemfile => rails70.gemfile} | 2 +- gemfiles/rails72.gemfile | 5 +++++ 3 files changed, 10 insertions(+), 3 deletions(-) rename gemfiles/{rails7.gemfile => rails70.gemfile} (68%) create mode 100644 gemfiles/rails72.gemfile diff --git a/.github/workflows/rspec.yml b/.github/workflows/rspec.yml index 5b1279b..ee9f677 100644 --- a/.github/workflows/rspec.yml +++ b/.github/workflows/rspec.yml @@ -21,8 +21,10 @@ jobs: gemfile: ["gemfiles/rails8.gemfile"] include: - ruby: "3.2" - gemfile: "gemfiles/rails7.gemfile" - - ruby: "3.3" + gemfile: "gemfiles/rails70.gemfile" + - ruby: "3.2" + gemfile: "gemfiles/rails72.gemfile" + - ruby: "3.4" gemfile: "gemfiles/rails8.gemfile" - ruby: "3.4" gemfile: "gemfiles/railsmaster.gemfile" diff --git a/gemfiles/rails7.gemfile b/gemfiles/rails70.gemfile similarity index 68% rename from gemfiles/rails7.gemfile rename to gemfiles/rails70.gemfile index 8aebf01..4749aec 100644 --- a/gemfiles/rails7.gemfile +++ b/gemfiles/rails70.gemfile @@ -1,5 +1,5 @@ source "https://rubygems.org" -gem "rails", "~> 7.0" +gem "rails", "~> 7.0.0" gemspec path: ".." diff --git a/gemfiles/rails72.gemfile b/gemfiles/rails72.gemfile new file mode 100644 index 0000000..fc6f6ea --- /dev/null +++ b/gemfiles/rails72.gemfile @@ -0,0 +1,5 @@ +source "https://rubygems.org" + +gem "rails", "~> 7.2.0" + +gemspec path: ".." From 644b82181d4b1066492ec2c0091df1988759529b Mon Sep 17 00:00:00 2001 From: Yaroslav Markin Date: Fri, 29 Aug 2025 13:15:10 +0300 Subject: [PATCH 2/7] Try to fix the logger/concurrent-ruby/Rails 7 error --- gemfiles/rails70.gemfile | 1 + 1 file changed, 1 insertion(+) diff --git a/gemfiles/rails70.gemfile b/gemfiles/rails70.gemfile index 4749aec..6e84251 100644 --- a/gemfiles/rails70.gemfile +++ b/gemfiles/rails70.gemfile @@ -1,5 +1,6 @@ source "https://rubygems.org" gem "rails", "~> 7.0.0" +gem "concurrent-ruby", "1.3.4" gemspec path: ".." From 3516fd16c6be22bc1d9fcb8335a1adb25a092848 Mon Sep 17 00:00:00 2001 From: Yaroslav Markin Date: Fri, 29 Aug 2025 13:22:54 +0300 Subject: [PATCH 3/7] Try to fix the logger/concurrent-ruby/Rails 7 error, take 2 --- gemfiles/rails70.gemfile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/gemfiles/rails70.gemfile b/gemfiles/rails70.gemfile index 6e84251..f2e46bb 100644 --- a/gemfiles/rails70.gemfile +++ b/gemfiles/rails70.gemfile @@ -1,6 +1,7 @@ source "https://rubygems.org" gem "rails", "~> 7.0.0" -gem "concurrent-ruby", "1.3.4" +gem "logger" +gem "sqlite3", "~> 1.4.0" gemspec path: ".." From f35c67b9f1426476d9268102ca37f22d0a347802 Mon Sep 17 00:00:00 2001 From: Yaroslav Markin Date: Fri, 29 Aug 2025 13:50:37 +0300 Subject: [PATCH 4/7] Try to fix the logger/concurrent-ruby/Rails 7 error, take 3 --- gemfiles/rails70.gemfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gemfiles/rails70.gemfile b/gemfiles/rails70.gemfile index f2e46bb..b36c640 100644 --- a/gemfiles/rails70.gemfile +++ b/gemfiles/rails70.gemfile @@ -1,7 +1,7 @@ source "https://rubygems.org" gem "rails", "~> 7.0.0" -gem "logger" +gem "concurrent-ruby", "1.3.4" gem "sqlite3", "~> 1.4.0" gemspec path: ".." From 5e2fe343bd4ec24f44e0229f668b5c14fade512f Mon Sep 17 00:00:00 2001 From: Yaroslav Markin Date: Fri, 29 Aug 2025 21:52:19 +0300 Subject: [PATCH 5/7] Fixing normalization specs for Rails 7.0 and 7.2 --- lib/callback_hell/analyzers/callback_analyzer.rb | 10 +++++++--- spec/internal/app/models/foo.rb | 2 +- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/lib/callback_hell/analyzers/callback_analyzer.rb b/lib/callback_hell/analyzers/callback_analyzer.rb index bd15b22..2043792 100644 --- a/lib/callback_hell/analyzers/callback_analyzer.rb +++ b/lib/callback_hell/analyzers/callback_analyzer.rb @@ -10,9 +10,13 @@ class CallbackAnalyzer ].freeze RAILS_ATTRIBUTE_OWNERS = [ - defined?(ActiveRecord::Normalization) ? ActiveRecord::Normalization : ActiveModel::Attributes::Normalization, - ActiveRecord::Encryption::EncryptableRecord - ].freeze + defined?(ActiveRecord::Normalization) && + ActiveRecord::Normalization, + defined?(ActiveModel::Attributes::Normalization) && + ActiveModel::Attributes::Normalization, + defined?(ActiveRecord::Encryption::EncryptableRecord) && + ActiveRecord::Encryption::EncryptableRecord + ].compact.freeze def initialize(callback, model, defining_class) @callback = callback diff --git a/spec/internal/app/models/foo.rb b/spec/internal/app/models/foo.rb index 94885ac..0b9c2d2 100644 --- a/spec/internal/app/models/foo.rb +++ b/spec/internal/app/models/foo.rb @@ -14,7 +14,7 @@ class Foo < ApplicationRecord after_create :noop around_create :noop, if: :createable? - normalizes :name, with: -> { _1.strip } + normalizes :name, with: -> { _1.strip } if respond_to?(:normalizes) def noop = true From 6e85aec4beca0e91fbdd871bcd422e1e9ff32016 Mon Sep 17 00:00:00 2001 From: Yaroslav Markin Date: Fri, 29 Aug 2025 21:59:26 +0300 Subject: [PATCH 6/7] Fix the remaining specs that include normalization --- .../integration/attribute_generated_spec.rb | 4 ++++ .../integration/empty_activerecord_spec.rb | 14 ++++++++++---- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/spec/modelscope/integration/attribute_generated_spec.rb b/spec/modelscope/integration/attribute_generated_spec.rb index 7a74abf..3f6d655 100644 --- a/spec/modelscope/integration/attribute_generated_spec.rb +++ b/spec/modelscope/integration/attribute_generated_spec.rb @@ -1,10 +1,14 @@ # frozen_string_literal: true RSpec.describe CallbackHell, "with attribute-generated callbacks and validations" do + def normalization_supported? + ActiveRecord::Base.respond_to?(:normalizes) + end subject(:foo) { CallbackHell::Collector.new(Foo, mode: :full).collect } subject(:bar) { CallbackHell::Collector.new(Bar, mode: :full).collect } it "correctly marks the callbacks generated by attributes" do + skip "Normalization not supported in this Rails version" unless normalization_supported? expect(foo).to have_callback( callback_name: :before_validate, method_name: :cant_modify_encrypted_attributes_when_frozen, diff --git a/spec/modelscope/integration/empty_activerecord_spec.rb b/spec/modelscope/integration/empty_activerecord_spec.rb index 16eaf95..343e135 100644 --- a/spec/modelscope/integration/empty_activerecord_spec.rb +++ b/spec/modelscope/integration/empty_activerecord_spec.rb @@ -1,6 +1,10 @@ # frozen_string_literal: true RSpec.describe CallbackHell, "with an empty ActiveRecord" do + def normalization_supported? + ActiveRecord::Base.respond_to?(:normalizes) + end + let(:options) { {} } subject(:ar) { CallbackHell::Collector.new(ApplicationRecord, **options).collect } @@ -18,10 +22,12 @@ method_name: :cant_modify_encrypted_attributes_when_frozen, origin: :rails, inherited: false ) - expect(ar).to have_callback( - method_name: :normalize_changed_in_place_attributes, - origin: :rails, inherited: false - ) + if normalization_supported? + expect(ar).to have_callback( + method_name: :normalize_changed_in_place_attributes, + origin: :rails, inherited: false + ) + end end end end From 6ff1a94ed472cbf0587d9d4debc75d3e106c6071 Mon Sep 17 00:00:00 2001 From: Yaroslav Markin Date: Wed, 3 Sep 2025 12:20:54 +0300 Subject: [PATCH 7/7] Update CHANGELOG [ci skip] --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 30589ab..894351e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Change log +## Unreleased + +- Proper support for Rails 7.0 and its lack of `normalizes` (https://github.com/evilmartians/callback_hell/issues/1) ([@yaroslav][]) + ## 0.2.0 - Initial public release. ([@yaroslav][])