Skip to content

Commit 63ff0d7

Browse files
authored
Merge pull request rails#43553 from rails/revert-43546-as-test-case-executor-wrap
Revert "Call Executor#wrap around each test"
2 parents 18922cc + d273411 commit 63ff0d7

File tree

8 files changed

+40
-31
lines changed

8 files changed

+40
-31
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# frozen_string_literal: true
2+
3+
module ActiveRecord::QueryLogs::TestHelper # :nodoc:
4+
def before_setup
5+
ActiveRecord::QueryLogs.clear_context
6+
super
7+
end
8+
9+
def after_teardown
10+
super
11+
ActiveRecord::QueryLogs.clear_context
12+
end
13+
end

activerecord/lib/active_record/railtie.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,11 @@ class Railtie < Rails::Railtie # :nodoc:
380380
app.reloader.before_class_unload { ActiveRecord::QueryLogs.clear_context }
381381
app.executor.to_run { ActiveRecord::QueryLogs.clear_context }
382382
app.executor.to_complete { ActiveRecord::QueryLogs.clear_context }
383+
384+
ActiveSupport.on_load(:active_support_test_case) do
385+
require "active_record/query_logs/test_helper"
386+
include ActiveRecord::QueryLogs::TestHelper
387+
end
383388
end
384389
end
385390
end

activerecord/test/cases/query_logs_test.rb

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,19 @@
22

33
require "cases/helper"
44
require "models/dashboard"
5+
require "active_record/query_logs/test_helper"
56

67
class QueryLogsTest < ActiveRecord::TestCase
8+
# Automatically included in Rails apps via railtie but that don't run here.
9+
include ActiveRecord::QueryLogs::TestHelper
10+
711
fixtures :dashboards
812

913
ActiveRecord::QueryLogs.taggings[:application] = -> {
1014
"active_record"
1115
}
1216

1317
def setup
14-
# QueryLogs context is automatically reset in Rails app via an executor hooks set in railtie
15-
# But not in Active Record's own test suite.
16-
ActiveRecord::QueryLogs.clear_context
17-
1818
# Enable the query tags logging
1919
@original_transformers = ActiveRecord.query_transformers
2020
@original_prepend = ActiveRecord::QueryLogs.prepend_comment
@@ -28,9 +28,6 @@ def teardown
2828
ActiveRecord.query_transformers = @original_transformers
2929
ActiveRecord::QueryLogs.prepend_comment = @original_prepend
3030
ActiveRecord::QueryLogs.tags = []
31-
# QueryLogs context is automatically reset in Rails app via an executor hooks set in railtie
32-
# But not in Active Record's own test suite.
33-
ActiveRecord::QueryLogs.clear_context
3431
end
3532

3633
def test_escaping_good_comment

activesupport/CHANGELOG.md

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,3 @@
1-
* `Rails.application.executor` hooks are now called around every tests.
2-
3-
This helps to better simulate request or job local state being reset.
4-
5-
*Jean Boussier*
6-
71
* Fix the `Digest::UUID.uuid_from_hash` behavior for namespace IDs that are different from the ones defined on `Digest::UUID`.
82

93
The new behavior will be enabled by setting the
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# frozen_string_literal: true
2+
3+
module ActiveSupport::CurrentAttributes::TestHelper # :nodoc:
4+
def before_setup
5+
ActiveSupport::CurrentAttributes.reset_all
6+
super
7+
end
8+
9+
def after_teardown
10+
super
11+
ActiveSupport::CurrentAttributes.reset_all
12+
end
13+
end

activesupport/lib/active_support/executor/test_helper.rb

Lines changed: 0 additions & 7 deletions
This file was deleted.

activesupport/lib/active_support/railtie.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ class Railtie < Rails::Railtie # :nodoc:
3333
app.executor.to_complete { ActiveSupport::CurrentAttributes.reset_all }
3434

3535
ActiveSupport.on_load(:active_support_test_case) do
36-
require "active_support/executor/test_helper"
37-
include ActiveSupport::Executor::TestHelper
36+
require "active_support/current_attributes/test_helper"
37+
include ActiveSupport::CurrentAttributes::TestHelper
3838
end
3939
end
4040

activesupport/test/current_attributes_test.rb

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,11 @@
11
# frozen_string_literal: true
22

33
require_relative "abstract_unit"
4+
require "active_support/current_attributes/test_helper"
45

56
class CurrentAttributesTest < ActiveSupport::TestCase
6-
# CurrentAttributes is automatically reset in Rails app via executor hooks set in railtie
7-
# But not in Active Support's own test suite.
8-
setup do
9-
ActiveSupport::CurrentAttributes.reset_all
10-
end
11-
12-
teardown do
13-
ActiveSupport::CurrentAttributes.reset_all
14-
end
7+
# Automatically included in Rails apps via railtie but that don't run here.
8+
include ActiveSupport::CurrentAttributes::TestHelper
159

1610
Person = Struct.new(:id, :name, :time_zone)
1711

0 commit comments

Comments
 (0)