From 0400be279b46069715d43a61862f75eb91bc1418 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89tienne=20Barri=C3=A9?= Date: Mon, 9 Nov 2020 15:15:42 -0500 Subject: [PATCH] Allow access to CurrentAttributes in test teardown --- .../lib/active_support/current_attributes/test_helper.rb | 4 ++-- activesupport/test/current_attributes_test.rb | 8 ++++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/activesupport/lib/active_support/current_attributes/test_helper.rb b/activesupport/lib/active_support/current_attributes/test_helper.rb index 31da9ed2a1..2016384a80 100644 --- a/activesupport/lib/active_support/current_attributes/test_helper.rb +++ b/activesupport/lib/active_support/current_attributes/test_helper.rb @@ -6,8 +6,8 @@ module ActiveSupport::CurrentAttributes::TestHelper # :nodoc: super end - def before_teardown - ActiveSupport::CurrentAttributes.reset_all + def after_teardown super + ActiveSupport::CurrentAttributes.reset_all end end diff --git a/activesupport/test/current_attributes_test.rb b/activesupport/test/current_attributes_test.rb index f8119c160e..49e38d5f1d 100644 --- a/activesupport/test/current_attributes_test.rb +++ b/activesupport/test/current_attributes_test.rb @@ -126,6 +126,14 @@ class CurrentAttributesTest < ActiveSupport::TestCase assert_equal "account/1", Current.account end + setup { @testing_teardown = false } + teardown { assert_equal 42, Session.current if @testing_teardown } + + test "accessing attributes in teardown" do + Session.current = 42 + @testing_teardown = true + end + test "delegation" do Current.person = Person.new(42, "David", "Central Time (US & Canada)") assert_equal "Central Time (US & Canada)", Current.time_zone