Skip to content

Commit 9c66f49

Browse files
jdlubranoscarroll32gregmolnar
authored
Fix rails 7.2 loading (#1534)
* Wrap Polyamorous module in on_load(:active_record) * Remove defined? ActiveRecord check from form builder * Require ActiveSupport.on_load explicitly * Load ransack first in specs to expose load order issues * Requiring more pieces of ActiveSupport I am not sure whether going down this path is the best approach. I feel that perhaps ActiveSupport could require everything within active_support/core_ext to ensure that active_support/core_ext can load itself. Still, there's no changing old versions of Rails, so I suppose this solution works? I am also not sure what the Rails team would recommend when it comes to requiring specific pieces of ActiveSupport (to leverage things like mattr_accessor). In any case, I was able to reproduce the CI failures locally and these changes make everything pass for me locally. --------- Co-authored-by: Sean <[email protected]> Co-authored-by: Greg Molnar <[email protected]>
1 parent ea4d0c8 commit 9c66f49

File tree

4 files changed

+17
-11
lines changed

4 files changed

+17
-11
lines changed

lib/polyamorous/polyamorous.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
if defined?(::ActiveRecord)
1+
ActiveSupport.on_load(:active_record) do
22
module Polyamorous
33
InnerJoin = Arel::Nodes::InnerJoin
44
OuterJoin = Arel::Nodes::OuterJoin

lib/ransack.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
require 'active_support/dependencies/autoload'
2+
require 'active_support/deprecation'
3+
require 'active_support/version'
4+
5+
if ::ActiveSupport.version >= ::Gem::Version.new("7.1")
6+
require 'active_support/deprecator'
7+
end
8+
19
require 'active_support/core_ext'
210
require 'ransack/configuration'
311
require 'polyamorous/polyamorous'

lib/ransack/helpers/form_builder.rb

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,12 @@ module ActionView::Helpers::Tags
66
# https://github.com/rails/rails/commit/c1a118a
77
class Base
88
private
9-
if defined? ::ActiveRecord
10-
def value
11-
if @allow_method_names_outside_object
12-
object.send @method_name if object && object.respond_to?(@method_name, true)
13-
else
14-
object.send @method_name if object
15-
end
9+
10+
def value
11+
if @allow_method_names_outside_object
12+
object.send @method_name if object && object.respond_to?(@method_name, true)
13+
else
14+
object.send @method_name if object
1615
end
1716
end
1817
end

spec/spec_helper.rb

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
1-
require 'machinist/active_record'
2-
require 'polyamorous/polyamorous'
1+
require 'ransack'
32
require 'sham'
43
require 'faker'
5-
require 'ransack'
64
require 'action_controller'
75
require 'ransack/helpers'
86
require 'pry'
97
require 'simplecov'
108
require 'byebug'
9+
require 'machinist/active_record'
1110

1211
SimpleCov.start
1312
I18n.enforce_available_locales = false

0 commit comments

Comments
 (0)