aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGeorge Claghorn <george.claghorn@gmail.com>2018-02-24 20:48:43 -0500
committerGitHub <noreply@github.com>2018-02-24 20:48:43 -0500
commit042c1e076a4ee3172c9ce95864d1e773b7ef38f8 (patch)
tree3f4afdb6d546825aea1e853cbb08a0cb410700d2
parentefd3338b193da5ae5f0d42c4ad792d65e744428c (diff)
parenteb834811dc029faa059595e72294d418fb74d0a1 (diff)
downloadrails-042c1e076a4ee3172c9ce95864d1e773b7ef38f8.tar.gz
rails-042c1e076a4ee3172c9ce95864d1e773b7ef38f8.tar.bz2
rails-042c1e076a4ee3172c9ce95864d1e773b7ef38f8.zip
Merge pull request #32100 from eugeneius/active_storage_lazy_load_hook
Use lazy load hook to configure ActiveStorage::Blob
-rw-r--r--activestorage/app/models/active_storage/blob.rb2
-rw-r--r--activestorage/lib/active_storage/engine.rb2
-rw-r--r--railties/test/application/loading_test.rb12
3 files changed, 15 insertions, 1 deletions
diff --git a/activestorage/app/models/active_storage/blob.rb b/activestorage/app/models/active_storage/blob.rb
index 31fbc66965..0cd4ad8128 100644
--- a/activestorage/app/models/active_storage/blob.rb
+++ b/activestorage/app/models/active_storage/blob.rb
@@ -202,4 +202,6 @@ class ActiveStorage::Blob < ActiveRecord::Base
def forcibly_serve_as_binary?
ActiveStorage.content_types_to_serve_as_binary.include?(content_type)
end
+
+ ActiveSupport.run_load_hooks(:active_storage_blob, self)
end
diff --git a/activestorage/lib/active_storage/engine.rb b/activestorage/lib/active_storage/engine.rb
index 9430dde028..1e223f9f17 100644
--- a/activestorage/lib/active_storage/engine.rb
+++ b/activestorage/lib/active_storage/engine.rb
@@ -68,7 +68,7 @@ module ActiveStorage
end
initializer "active_storage.services" do
- config.to_prepare do
+ ActiveSupport.on_load(:active_storage_blob) do
if config_choice = Rails.configuration.active_storage.service
configs = Rails.configuration.active_storage.service_configurations ||= begin
config_file = Pathname.new(Rails.root.join("config/storage.yml"))
diff --git a/railties/test/application/loading_test.rb b/railties/test/application/loading_test.rb
index 2632dd7cde..889ad16fb8 100644
--- a/railties/test/application/loading_test.rb
+++ b/railties/test/application/loading_test.rb
@@ -359,6 +359,18 @@ class LoadingTest < ActiveSupport::TestCase
assert_predicate Rails.application, :initialized?
end
+ test "frameworks aren't loaded during initialization" do
+ app_file "config/initializers/raise_when_frameworks_load.rb", <<-RUBY
+ %i(action_controller action_mailer active_job active_record).each do |framework|
+ ActiveSupport.on_load(framework) { raise "\#{framework} loaded!" }
+ end
+ RUBY
+
+ assert_nothing_raised do
+ require "#{app_path}/config/environment"
+ end
+ end
+
private
def setup_ar!