@@ -141,6 +141,79 @@ def test_query_cache_is_applied_to_all_connections
141
141
clean_up_connection_handler
142
142
end
143
143
144
+ def test_cache_is_not_applied_when_config_is_false
145
+ ActiveRecord ::Base . connected_to ( role : :reading ) do
146
+ db_config = ActiveRecord ::Base . configurations . configs_for ( env_name : "arunit" , name : "primary" )
147
+ ActiveRecord ::Base . establish_connection ( db_config . configuration_hash . merge ( query_cache : false ) )
148
+ end
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 )
154
+ end
155
+ }
156
+
157
+ mw . call ( { } )
158
+ ensure
159
+ clean_up_connection_handler
160
+ end
161
+
162
+ def test_cache_is_applied_when_config_is_string
163
+ ActiveRecord ::Base . connected_to ( role : :reading ) do
164
+ db_config = ActiveRecord ::Base . configurations . configs_for ( env_name : "arunit" , name : "primary" )
165
+ ActiveRecord ::Base . establish_connection ( db_config . configuration_hash . merge ( query_cache : "unlimited" ) )
166
+ end
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 )
172
+ end
173
+ }
174
+
175
+ mw . call ( { } )
176
+ ensure
177
+ clean_up_connection_handler
178
+ end
179
+
180
+ def test_cache_is_applied_when_config_is_integer
181
+ ActiveRecord ::Base . connected_to ( role : :reading ) do
182
+ db_config = ActiveRecord ::Base . configurations . configs_for ( env_name : "arunit" , name : "primary" )
183
+ ActiveRecord ::Base . establish_connection ( db_config . configuration_hash . merge ( query_cache : 42 ) )
184
+ end
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 )
190
+ end
191
+ }
192
+
193
+ mw . call ( { } )
194
+ ensure
195
+ clean_up_connection_handler
196
+ end
197
+
198
+ def test_cache_is_applied_when_config_is_nil
199
+ ActiveRecord ::Base . connected_to ( role : :reading ) do
200
+ db_config = ActiveRecord ::Base . configurations . configs_for ( env_name : "arunit" , name : "primary" )
201
+ ActiveRecord ::Base . establish_connection ( db_config . configuration_hash . merge ( query_cache : nil ) )
202
+ end
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
207
+ end
208
+ }
209
+
210
+ mw . call ( { } )
211
+ ensure
212
+ clean_up_connection_handler
213
+ end
214
+
215
+
216
+
144
217
if Process . respond_to? ( :fork ) && !in_memory_db?
145
218
def test_query_cache_with_forked_processes
146
219
ActiveRecord ::Base . connected_to ( role : :reading ) do
0 commit comments