Skip to content

Commit 2ea77d6

Browse files
Ensure globals reset after Active Storage tests
This ensures `ActiveRecord::Base.strict_loading_by_default` and `ActiveStorage.track_variants` are reset to their original values even when an error (e.g. an assertion failure) is raised inside `with_strict_loading_by_default` and `without_variant_tracking` blocks.
1 parent 4cc1de7 commit 2ea77d6

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

activestorage/test/test_helper.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,13 +105,15 @@ def with_strict_loading_by_default(&block)
105105
strict_loading_was = ActiveRecord::Base.strict_loading_by_default
106106
ActiveRecord::Base.strict_loading_by_default = true
107107
yield
108+
ensure
108109
ActiveRecord::Base.strict_loading_by_default = strict_loading_was
109110
end
110111

111112
def without_variant_tracking(&block)
112113
variant_tracking_was = ActiveStorage.track_variants
113114
ActiveStorage.track_variants = false
114115
yield
116+
ensure
115117
ActiveStorage.track_variants = variant_tracking_was
116118
end
117119

0 commit comments

Comments
 (0)