Skip to content

Commit

Permalink
Ensure globals reset after Active Storage tests
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jonathanhefner committed Nov 13, 2023
1 parent 4cc1de7 commit 2ea77d6
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions activestorage/test/test_helper.rb
Expand Up @@ -105,13 +105,15 @@ def with_strict_loading_by_default(&block)
strict_loading_was = ActiveRecord::Base.strict_loading_by_default
ActiveRecord::Base.strict_loading_by_default = true
yield
ensure
ActiveRecord::Base.strict_loading_by_default = strict_loading_was
end

def without_variant_tracking(&block)
variant_tracking_was = ActiveStorage.track_variants
ActiveStorage.track_variants = false
yield
ensure
ActiveStorage.track_variants = variant_tracking_was
end

Expand Down

0 comments on commit 2ea77d6

Please sign in to comment.