File tree Expand file tree Collapse file tree 4 files changed +30
-0
lines changed Expand file tree Collapse file tree 4 files changed +30
-0
lines changed Original file line number Diff line number Diff line change @@ -96,6 +96,10 @@ def set_context(**options)
96
96
end
97
97
end
98
98
99
+ def clear_context # :nodoc:
100
+ context . clear
101
+ end
102
+
99
103
def call ( sql ) # :nodoc:
100
104
if prepend_comment
101
105
"#{ self . comment } #{ sql } "
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change @@ -376,6 +376,15 @@ class Railtie < Rails::Railtie # :nodoc:
376
376
if app . config . active_record . cache_query_log_tags
377
377
ActiveRecord ::QueryLogs . cache_query_log_tags = true
378
378
end
379
+
380
+ app . reloader . before_class_unload { ActiveRecord ::QueryLogs . clear_context }
381
+ app . executor . to_run { ActiveRecord ::QueryLogs . clear_context }
382
+ 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
379
388
end
380
389
end
381
390
end
Original file line number Diff line number Diff line change 2
2
3
3
require "cases/helper"
4
4
require "models/dashboard"
5
+ require "active_record/query_logs/test_helper"
5
6
6
7
class QueryLogsTest < ActiveRecord ::TestCase
8
+ # Automatically included in Rails apps via railtie but that don't run here.
9
+ include ActiveRecord ::QueryLogs ::TestHelper
10
+
7
11
fixtures :dashboards
8
12
9
13
ActiveRecord ::QueryLogs . taggings [ :application ] = -> {
You can’t perform that action at this time.
0 commit comments