Make action_on_strict_loading_violation
a module instance variable
Followup: https://github.com/rails/rails/pull/42442
This commit is contained in:
parent
a50ff734cb
commit
e65042707e
@ -197,6 +197,13 @@ module Tasks
|
||||
singleton_class.attr_accessor :application_record_class
|
||||
self.application_record_class = nil
|
||||
|
||||
##
|
||||
# :singleton-method:
|
||||
# Set the application to log or raise when an association violates strict loading.
|
||||
# Defaults to :raise.
|
||||
singleton_class.attr_accessor :action_on_strict_loading_violation
|
||||
self.action_on_strict_loading_violation = :raise
|
||||
|
||||
def self.eager_load!
|
||||
super
|
||||
ActiveRecord::Locking.eager_load!
|
||||
|
@ -127,12 +127,6 @@ def self.configurations
|
||||
|
||||
class_attribute :belongs_to_required_by_default, instance_accessor: false
|
||||
|
||||
##
|
||||
# :singleton-method:
|
||||
# Set the application to log or raise when an association violates strict loading.
|
||||
# Defaults to :raise.
|
||||
mattr_accessor :action_on_strict_loading_violation, instance_accessor: false, default: :raise
|
||||
|
||||
class_attribute :strict_loading_by_default, instance_accessor: false, default: false
|
||||
class_attribute :strict_loading_mode, instance_accessor: true, default: :all
|
||||
|
||||
@ -345,7 +339,7 @@ def self.allow_unsafe_raw_sql=(value) # :nodoc:
|
||||
self.default_shard = :default
|
||||
|
||||
def self.strict_loading_violation!(owner:, reflection:) # :nodoc:
|
||||
case action_on_strict_loading_violation
|
||||
case ActiveRecord.action_on_strict_loading_violation
|
||||
when :raise
|
||||
message = "`#{owner}` is marked for strict_loading. The `#{reflection.klass}` association named `:#{reflection.name}` cannot be lazily loaded."
|
||||
raise ActiveRecord::StrictLoadingViolationError.new(message)
|
||||
|
@ -548,7 +548,7 @@ def test_does_not_raise_on_eager_loading_a_habtm_relation_if_strict_loading_by_d
|
||||
end
|
||||
|
||||
def test_strict_loading_violation_raises_by_default
|
||||
assert_equal :raise, ActiveRecord::Base.action_on_strict_loading_violation
|
||||
assert_equal :raise, ActiveRecord.action_on_strict_loading_violation
|
||||
|
||||
developer = Developer.first
|
||||
assert_not_predicate developer, :strict_loading?
|
||||
@ -562,9 +562,9 @@ def test_strict_loading_violation_raises_by_default
|
||||
end
|
||||
|
||||
def test_strict_loading_violation_can_log_instead_of_raise
|
||||
old_value = ActiveRecord::Base.action_on_strict_loading_violation
|
||||
ActiveRecord::Base.action_on_strict_loading_violation = :log
|
||||
assert_equal :log, ActiveRecord::Base.action_on_strict_loading_violation
|
||||
old_value = ActiveRecord.action_on_strict_loading_violation
|
||||
ActiveRecord.action_on_strict_loading_violation = :log
|
||||
assert_equal :log, ActiveRecord.action_on_strict_loading_violation
|
||||
|
||||
developer = Developer.first
|
||||
assert_not_predicate developer, :strict_loading?
|
||||
@ -576,7 +576,7 @@ def test_strict_loading_violation_can_log_instead_of_raise
|
||||
developer.audit_logs.to_a
|
||||
end
|
||||
ensure
|
||||
ActiveRecord::Base.action_on_strict_loading_violation = old_value
|
||||
ActiveRecord.action_on_strict_loading_violation = old_value
|
||||
end
|
||||
|
||||
private
|
||||
|
Loading…
Reference in New Issue
Block a user