@@ -147,12 +147,12 @@ def test_cache_is_not_applied_when_config_is_false
147
147
ActiveRecord ::Base . establish_connection ( db_config . configuration_hash . merge ( query_cache : false ) )
148
148
end
149
149
150
- mw = middleware { |env |
151
- ActiveRecord ::Base . connection_handler . connection_pool_list ( : reading) . each do | pool |
152
- assert_not_predicate pool . lease_connection , :query_cache_enabled
153
- assert_nil pool . query_cache . instance_variable_get ( :@max_size )
150
+ mw = middleware do |env |
151
+ ActiveRecord ::Base . connected_to ( role : : reading) do
152
+ assert_cache :off
153
+ assert_nil ActiveRecord :: Base . lease_connection . pool . query_cache . instance_variable_get ( :@max_size )
154
154
end
155
- }
155
+ end
156
156
157
157
mw . call ( { } )
158
158
ensure
@@ -165,12 +165,12 @@ def test_cache_is_applied_when_config_is_string
165
165
ActiveRecord ::Base . establish_connection ( db_config . configuration_hash . merge ( query_cache : "unlimited" ) )
166
166
end
167
167
168
- mw = middleware { |env |
169
- ActiveRecord ::Base . connection_handler . connection_pool_list ( : reading) . each do | pool |
170
- assert_predicate pool . lease_connection , :query_cache_enabled
171
- assert_nil pool . query_cache . instance_variable_get ( :@max_size )
168
+ mw = middleware do |env |
169
+ ActiveRecord ::Base . connected_to ( role : : reading) do
170
+ assert_cache :clean
171
+ assert_nil ActiveRecord :: Base . lease_connection . pool . query_cache . instance_variable_get ( :@max_size )
172
172
end
173
- }
173
+ end
174
174
175
175
mw . call ( { } )
176
176
ensure
@@ -183,12 +183,12 @@ def test_cache_is_applied_when_config_is_integer
183
183
ActiveRecord ::Base . establish_connection ( db_config . configuration_hash . merge ( query_cache : 42 ) )
184
184
end
185
185
186
- mw = middleware { |env |
187
- ActiveRecord ::Base . connection_handler . connection_pool_list ( : reading) . each do | pool |
188
- assert_predicate pool . lease_connection , :query_cache_enabled
189
- assert_equal 42 , pool . query_cache . instance_variable_get ( :@max_size )
186
+ mw = middleware do |env |
187
+ ActiveRecord ::Base . connected_to ( role : : reading) do
188
+ assert_cache :clean
189
+ assert_equal 42 , ActiveRecord :: Base . lease_connection . pool . query_cache . instance_variable_get ( :@max_size )
190
190
end
191
- }
191
+ end
192
192
193
193
mw . call ( { } )
194
194
ensure
@@ -201,19 +201,18 @@ def test_cache_is_applied_when_config_is_nil
201
201
ActiveRecord ::Base . establish_connection ( db_config . configuration_hash . merge ( query_cache : nil ) )
202
202
end
203
203
204
- mw = middleware { |env |
205
- ActiveRecord ::Base . connection_handler . connection_pool_list ( :reading ) . each do |pool |
206
- assert_predicate pool . lease_connection , :query_cache_enabled
204
+ mw = middleware do |env |
205
+ ActiveRecord ::Base . connected_to ( role : :reading ) do
206
+ assert_cache :clean
207
+ assert_equal ActiveRecord ::ConnectionAdapters ::QueryCache ::DEFAULT_SIZE , ActiveRecord ::Base . lease_connection . pool . query_cache . instance_variable_get ( :@max_size )
207
208
end
208
- }
209
+ end
209
210
210
211
mw . call ( { } )
211
212
ensure
212
213
clean_up_connection_handler
213
214
end
214
215
215
-
216
-
217
216
if Process . respond_to? ( :fork ) && !in_memory_db?
218
217
def test_query_cache_with_forked_processes
219
218
ActiveRecord ::Base . connected_to ( role : :reading ) do
0 commit comments