File tree Expand file tree Collapse file tree 8 files changed +38
-11
lines changed
lib/callback_hell/analyzers Expand file tree Collapse file tree 8 files changed +38
-11
lines changed Original file line number Diff line number Diff line change 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"
Original file line number Diff line number Diff line change 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 ] [ ] )
Original file line number Diff line number Diff line change 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: ".."
Original file line number Diff line number Diff line change 11source "https://rubygems.org"
22
3- gem "rails", "~> 7.0"
3+ gem "rails", "~> 7.2. 0"
44
55gemspec path: ".."
Original file line number Diff line number Diff 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
Original file line number Diff line number Diff 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
Original file line number Diff line number Diff line change 11# frozen_string_literal: true
22
33RSpec . 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 ,
Original file line number Diff line number Diff line change 11# frozen_string_literal: true
22
33RSpec . 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
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
2733end
You can’t perform that action at this time.
0 commit comments