Skip to content

Commit bd400b4

Browse files
authored
Merge pull request rails#43546 from Shopify/as-test-case-executor-wrap
Call Executor#wrap around each test
2 parents de1a831 + 265c1e9 commit bd400b4

File tree

8 files changed

+31
-40
lines changed

8 files changed

+31
-40
lines changed

activerecord/lib/active_record/query_logs/test_helper.rb

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

activerecord/lib/active_record/railtie.rb

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -380,11 +380,6 @@ 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
388383
end
389384
end
390385
end

activerecord/test/cases/query_logs_test.rb

Lines changed: 7 additions & 4 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"
65

76
class QueryLogsTest < ActiveRecord::TestCase
8-
# Automatically included in Rails apps via railtie but that don't run here.
9-
include ActiveRecord::QueryLogs::TestHelper
10-
117
fixtures :dashboards
128

139
ActiveRecord::QueryLogs.taggings[:application] = -> {
1410
"active_record"
1511
}
1612

1713
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,6 +28,9 @@ 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
3134
end
3235

3336
def test_escaping_good_comment

activesupport/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
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+
17
* Fix the `Digest::UUID.uuid_from_hash` behavior for namespace IDs that are different from the ones defined on `Digest::UUID`.
28

39
The new behavior will be enabled by setting the

activesupport/lib/active_support/current_attributes/test_helper.rb

Lines changed: 0 additions & 13 deletions
This file was deleted.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# frozen_string_literal: true
2+
3+
module ActiveSupport::Executor::TestHelper # :nodoc:
4+
def run(...)
5+
Rails.application.executor.wrap { super }
6+
end
7+
end

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/current_attributes/test_helper"
37-
include ActiveSupport::CurrentAttributes::TestHelper
36+
require "active_support/executor/test_helper"
37+
include ActiveSupport::Executor::TestHelper
3838
end
3939
end
4040

activesupport/test/current_attributes_test.rb

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

33
require_relative "abstract_unit"
4-
require "active_support/current_attributes/test_helper"
54

65
class CurrentAttributesTest < ActiveSupport::TestCase
7-
# Automatically included in Rails apps via railtie but that don't run here.
8-
include ActiveSupport::CurrentAttributes::TestHelper
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
915

1016
Person = Struct.new(:id, :name, :time_zone)
1117

0 commit comments

Comments
 (0)