From 58643ed2ef6f11d8d0bf45dbbbd96f93f97d2423 Mon Sep 17 00:00:00 2001 From: Kasper Timm Hansen Date: Fri, 13 Dec 2024 22:44:46 +0100 Subject: [PATCH] Fix ActiveJob::Performs not being automatically extended `ActiveSupport.on_load :active_job` may not fire after the application has loaded (since it happens when Active Job is first mentioned and then it's loaded), which means any Associated Objects loaded would not have `performs` defined and we'd raise. The short curcuit was to only inject performs if users were using Active Job, but it's too clever. We're now being less clever and letting bundler load every gem first via deferring our extension to the others in `config.after_initialize`. --- lib/active_record/associated_object/railtie.rb | 9 ++------- test/test_helper.rb | 6 ++++-- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/lib/active_record/associated_object/railtie.rb b/lib/active_record/associated_object/railtie.rb index e206488..d9bb9f6 100644 --- a/lib/active_record/associated_object/railtie.rb +++ b/lib/active_record/associated_object/railtie.rb @@ -3,17 +3,12 @@ class ActiveRecord::AssociatedObject::Railtie < Rails::Railtie config.after_initialize do ActiveRecord::AssociatedObject.include Kredis::Attributes if defined?(Kredis) ActiveRecord::AssociatedObject.include GlobalID::Identification if defined?(GlobalID) + + ActiveRecord::AssociatedObject.extend ActiveJob::Performs if defined?(ActiveJob::Performs) end end initializer "object_association.setup" do - ActiveSupport.on_load :active_job do - require "active_job/performs" - ActiveRecord::AssociatedObject.extend ActiveJob::Performs - rescue LoadError - # We haven't bundled active_job-performs, so we're continuing without it. - end - ActiveSupport.on_load :active_record do require "active_record/associated_object/object_association" include ActiveRecord::AssociatedObject::ObjectAssociation diff --git a/test/test_helper.rb b/test/test_helper.rb index 0739c4d..a380f67 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -4,14 +4,16 @@ require "rails/railtie" require "kredis" -require "active_job" -require "global_id" require "debug" require "logger" require "active_record" require "active_record/associated_object" +require "global_id" +require "active_job" +require "active_job/performs" + require "minitest/autorun" # Simulate Rails app boot and run the railtie initializers manually.