Skip to content

Commit

Permalink
Allow setting some active support settings via initializers
Browse files Browse the repository at this point in the history
  • Loading branch information
ghiculescu authored and byroot committed May 3, 2022
1 parent 36340b5 commit a1fbc46
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 5 deletions.
10 changes: 5 additions & 5 deletions activesupport/lib/active_support/railtie.rb
Expand Up @@ -11,8 +11,10 @@ class Railtie < Rails::Railtie # :nodoc:
config.eager_load_namespaces << ActiveSupport

initializer "active_support.isolation_level" do |app|
if level = app.config.active_support.delete(:isolation_level)
ActiveSupport::IsolatedExecutionState.isolation_level = level
config.after_initialize do
if level = app.config.active_support.delete(:isolation_level)
ActiveSupport::IsolatedExecutionState.isolation_level = level
end
end
end

Expand Down Expand Up @@ -41,14 +43,12 @@ class Railtie < Rails::Railtie # :nodoc:
end

initializer "active_support.reset_all_current_attributes_instances" do |app|
executor_around_test_case = app.config.active_support.executor_around_test_case

app.reloader.before_class_unload { ActiveSupport::CurrentAttributes.clear_all }
app.executor.to_run { ActiveSupport::CurrentAttributes.reset_all }
app.executor.to_complete { ActiveSupport::CurrentAttributes.reset_all }

ActiveSupport.on_load(:active_support_test_case) do
if executor_around_test_case
if app.config.active_support.executor_around_test_case
require "active_support/executor/test_helper"
include ActiveSupport::Executor::TestHelper
else
Expand Down
47 changes: 47 additions & 0 deletions railties/test/application/configuration_test.rb
Expand Up @@ -3573,6 +3573,53 @@ def new(app); self; end
end
end

test "ActionController::Base.raise_on_missing_callback_actions is false by default for production" do
app "production"

assert_equal false, ActionController::Base.raise_on_missing_callback_actions
end

test "ActionController::Base.raise_on_missing_callback_actions is false by default for upgraded apps" do
remove_from_config '.*config\.load_defaults.*\n'

app "development"

assert_equal false, ActionController::Base.raise_on_missing_callback_actions
end

test "ActionController::Base.raise_on_missing_callback_actions can be configured in the new framework defaults" do
remove_from_config '.*config\.load_defaults.*\n'

app_file "config/initializers/new_framework_defaults_6_2.rb", <<-RUBY
Rails.application.config.action_controller.raise_on_missing_callback_actions = true
RUBY

app "production"

assert_equal true, ActionController::Base.raise_on_missing_callback_actions
end

test "isolation_level is :thread by default" do
app "development"
assert_equal :thread, ActiveSupport::IsolatedExecutionState.isolation_level
end

test "isolation_level can be set in app config" do
add_to_config "config.active_support.isolation_level = :fiber"

app "development"
assert_equal :fiber, ActiveSupport::IsolatedExecutionState.isolation_level
end

test "isolation_level can be set in initializer" do
app_file "config/initializers/new_framework_defaults_7_0.rb", <<-RUBY
Rails.application.config.active_support.isolation_level = :fiber
RUBY

app "development"
assert_equal :fiber, ActiveSupport::IsolatedExecutionState.isolation_level
end

private
def set_custom_config(contents, config_source = "custom".inspect)
app_file "config/custom.yml", contents
Expand Down

0 comments on commit a1fbc46

Please sign in to comment.