Skip to content

Commit d48cefe

Browse files
authored
Merge pull request #2 from evilmartians/bug/issue-1
Test Rails 7.0 and 7.2 separately
2 parents d592c83 + 6ff1a94 commit d48cefe

File tree

8 files changed

+38
-11
lines changed

8 files changed

+38
-11
lines changed

.github/workflows/rspec.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,10 @@ jobs:
2121
gemfile: ["gemfiles/rails8.gemfile"]
2222
include:
2323
- ruby: "3.2"
24-
gemfile: "gemfiles/rails7.gemfile"
25-
- ruby: "3.3"
24+
gemfile: "gemfiles/rails70.gemfile"
25+
- ruby: "3.2"
26+
gemfile: "gemfiles/rails72.gemfile"
27+
- ruby: "3.4"
2628
gemfile: "gemfiles/rails8.gemfile"
2729
- ruby: "3.4"
2830
gemfile: "gemfiles/railsmaster.gemfile"

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Change log
22

3+
## Unreleased
4+
5+
- Proper support for Rails 7.0 and its lack of `normalizes` (https://github.com/evilmartians/callback_hell/issues/1) ([@yaroslav][])
6+
37
## 0.2.0
48

59
- Initial public release. ([@yaroslav][])

gemfiles/rails70.gemfile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
source "https://rubygems.org"
2+
3+
gem "rails", "~> 7.0.0"
4+
gem "concurrent-ruby", "1.3.4"
5+
gem "sqlite3", "~> 1.4.0"
6+
7+
gemspec path: ".."
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
source "https://rubygems.org"
22

3-
gem "rails", "~> 7.0"
3+
gem "rails", "~> 7.2.0"
44

55
gemspec path: ".."

lib/callback_hell/analyzers/callback_analyzer.rb

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,13 @@ class CallbackAnalyzer
1010
].freeze
1111

1212
RAILS_ATTRIBUTE_OWNERS = [
13-
defined?(ActiveRecord::Normalization) ? ActiveRecord::Normalization : ActiveModel::Attributes::Normalization,
14-
ActiveRecord::Encryption::EncryptableRecord
15-
].freeze
13+
defined?(ActiveRecord::Normalization) &&
14+
ActiveRecord::Normalization,
15+
defined?(ActiveModel::Attributes::Normalization) &&
16+
ActiveModel::Attributes::Normalization,
17+
defined?(ActiveRecord::Encryption::EncryptableRecord) &&
18+
ActiveRecord::Encryption::EncryptableRecord
19+
].compact.freeze
1620

1721
def initialize(callback, model, defining_class)
1822
@callback = callback

spec/internal/app/models/foo.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class Foo < ApplicationRecord
1414
after_create :noop
1515
around_create :noop, if: :createable?
1616

17-
normalizes :name, with: -> { _1.strip }
17+
normalizes :name, with: -> { _1.strip } if respond_to?(:normalizes)
1818

1919
def noop = true
2020

spec/modelscope/integration/attribute_generated_spec.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
# frozen_string_literal: true
22

33
RSpec.describe CallbackHell, "with attribute-generated callbacks and validations" do
4+
def normalization_supported?
5+
ActiveRecord::Base.respond_to?(:normalizes)
6+
end
47
subject(:foo) { CallbackHell::Collector.new(Foo, mode: :full).collect }
58
subject(:bar) { CallbackHell::Collector.new(Bar, mode: :full).collect }
69

710
it "correctly marks the callbacks generated by attributes" do
11+
skip "Normalization not supported in this Rails version" unless normalization_supported?
812
expect(foo).to have_callback(
913
callback_name: :before_validate,
1014
method_name: :cant_modify_encrypted_attributes_when_frozen,

spec/modelscope/integration/empty_activerecord_spec.rb

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
# frozen_string_literal: true
22

33
RSpec.describe CallbackHell, "with an empty ActiveRecord" do
4+
def normalization_supported?
5+
ActiveRecord::Base.respond_to?(:normalizes)
6+
end
7+
48
let(:options) { {} }
59
subject(:ar) { CallbackHell::Collector.new(ApplicationRecord, **options).collect }
610

@@ -18,10 +22,12 @@
1822
method_name: :cant_modify_encrypted_attributes_when_frozen,
1923
origin: :rails, inherited: false
2024
)
21-
expect(ar).to have_callback(
22-
method_name: :normalize_changed_in_place_attributes,
23-
origin: :rails, inherited: false
24-
)
25+
if normalization_supported?
26+
expect(ar).to have_callback(
27+
method_name: :normalize_changed_in_place_attributes,
28+
origin: :rails, inherited: false
29+
)
30+
end
2531
end
2632
end
2733
end

0 commit comments

Comments
 (0)