From 1ad129a9f23f3d6238a54319db427f70916b9000 Mon Sep 17 00:00:00 2001 From: Joel Lubrano Date: Tue, 29 Oct 2024 11:20:32 -0400 Subject: [PATCH 1/5] Wrap Polyamorous module in on_load(:active_record) --- lib/polyamorous/polyamorous.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/polyamorous/polyamorous.rb b/lib/polyamorous/polyamorous.rb index f1b759d2..0d361543 100644 --- a/lib/polyamorous/polyamorous.rb +++ b/lib/polyamorous/polyamorous.rb @@ -1,4 +1,4 @@ -if defined?(::ActiveRecord) +ActiveSupport.on_load(:active_record) do module Polyamorous InnerJoin = Arel::Nodes::InnerJoin OuterJoin = Arel::Nodes::OuterJoin From a26e25153f107d6d8832db17c09e43ff522ecae7 Mon Sep 17 00:00:00 2001 From: Joel Lubrano Date: Tue, 29 Oct 2024 12:56:54 -0400 Subject: [PATCH 2/5] Remove defined? ActiveRecord check from form builder --- lib/ransack/helpers/form_builder.rb | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/lib/ransack/helpers/form_builder.rb b/lib/ransack/helpers/form_builder.rb index 0f9d826f..54bbb275 100644 --- a/lib/ransack/helpers/form_builder.rb +++ b/lib/ransack/helpers/form_builder.rb @@ -6,13 +6,12 @@ module ActionView::Helpers::Tags # https://github.com/rails/rails/commit/c1a118a class Base private - if defined? ::ActiveRecord - def value - if @allow_method_names_outside_object - object.send @method_name if object && object.respond_to?(@method_name, true) - else - object.send @method_name if object - end + + def value + if @allow_method_names_outside_object + object.send @method_name if object && object.respond_to?(@method_name, true) + else + object.send @method_name if object end end end From e9f20f5199465f8271aca97dd319781c8817cf40 Mon Sep 17 00:00:00 2001 From: Joel Lubrano Date: Tue, 29 Oct 2024 12:57:24 -0400 Subject: [PATCH 3/5] Require ActiveSupport.on_load explicitly --- lib/ransack.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/ransack.rb b/lib/ransack.rb index 1a88b646..c12080b1 100644 --- a/lib/ransack.rb +++ b/lib/ransack.rb @@ -1,3 +1,4 @@ +require 'active_support/dependencies/autoload' require 'active_support/core_ext' require 'ransack/configuration' require 'polyamorous/polyamorous' From 4ece2c4f994c7fb5efd47bcb959ab0ef8464bffd Mon Sep 17 00:00:00 2001 From: Joel Lubrano Date: Tue, 29 Oct 2024 12:57:42 -0400 Subject: [PATCH 4/5] Load ransack first in specs to expose load order issues --- spec/spec_helper.rb | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 0c4bf109..18facc43 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,13 +1,12 @@ -require 'machinist/active_record' -require 'polyamorous/polyamorous' +require 'ransack' require 'sham' require 'faker' -require 'ransack' require 'action_controller' require 'ransack/helpers' require 'pry' require 'simplecov' require 'byebug' +require 'machinist/active_record' SimpleCov.start I18n.enforce_available_locales = false From 046bae772b22cda678e4c9f7ae0d498c3728bd6f Mon Sep 17 00:00:00 2001 From: Joel Lubrano Date: Sun, 3 Nov 2024 12:09:21 -0500 Subject: [PATCH 5/5] 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. --- lib/ransack.rb | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib/ransack.rb b/lib/ransack.rb index c12080b1..1b72af5e 100644 --- a/lib/ransack.rb +++ b/lib/ransack.rb @@ -1,4 +1,11 @@ require 'active_support/dependencies/autoload' +require 'active_support/deprecation' +require 'active_support/version' + +if ::ActiveSupport.version >= ::Gem::Version.new("7.1") + require 'active_support/deprecator' +end + require 'active_support/core_ext' require 'ransack/configuration' require 'polyamorous/polyamorous'