Merge pull request #41839 from abhaynikam/fix-return-type-for-strict-loading

ActiveRecord#strict_loading! should return boolean instead of current mode set.
This commit is contained in:
Eileen M. Uchitelle 2021-04-15 08:49:33 -04:00 committed by GitHub
commit 80a23227ea
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 3 deletions

View File

@ -765,8 +765,8 @@ module ActiveRecord
raise ArgumentError, "The :mode option must be one of [:all, :n_plus_one_only]."
end
@strict_loading = value
@strict_loading_mode = mode
@strict_loading = value
end
# Returns +true+ if the record uses strict_loading with +:n_plus_one_only+ mode enabled.

View File

@ -19,19 +19,22 @@ class StrictLoadingTest < ActiveRecord::TestCase
developer = Developer.first
assert_not_predicate developer, :strict_loading?
developer.strict_loading!
assert developer.strict_loading!
assert_predicate developer, :strict_loading?
assert_raises ActiveRecord::StrictLoadingViolationError do
developer.audit_logs.to_a
end
developer.strict_loading!(false)
assert_not developer.strict_loading!(false)
assert_not_predicate developer, :strict_loading?
assert_nothing_raised do
developer.audit_logs.to_a
end
assert developer.strict_loading!(mode: :n_plus_one_only)
assert developer.strict_loading_n_plus_one_only?
end
def test_strict_loading_n_plus_one_only_mode