@@ -232,30 +232,15 @@ def show
232
232
config.eager_load = true
233
233
RUBY
234
234
235
- app ( "development" )
235
+ Dir . chdir ( app_path ) do
236
+ app ( "development" )
236
237
237
- assert ActiveRecord ::Base . connection . schema_cache . data_sources ( "posts" )
238
+ assert ActiveRecord ::Base . connection . schema_cache . data_sources ( "posts" )
239
+ end
238
240
ensure
239
241
ActiveRecord ::Base . connection . drop_table ( "posts" , if_exists : true ) # force drop posts table for test.
240
242
end
241
243
242
- test "skips checking for schema cache dump when all databases skipping database tasks" do
243
- app_file "config/database.yml" , <<-YAML
244
- development:
245
- database: storage/default.sqlite3
246
- adapter: sqlite3
247
- database_tasks: false
248
- YAML
249
-
250
- add_to_config <<-RUBY
251
- config.eager_load = true
252
- RUBY
253
-
254
- assert_nothing_raised do
255
- app ( "development" )
256
- end
257
- end
258
-
259
244
test "expire schema cache dump" do
260
245
rails %w( generate model post title:string )
261
246
rails %w( db:migrate db:schema:cache:dump db:rollback )
@@ -264,10 +249,15 @@ def show
264
249
config.eager_load = true
265
250
RUBY
266
251
267
- silence_warnings do
252
+ Dir . chdir ( app_path ) do
268
253
app ( "development" )
254
+
255
+ _ , error = capture_io do
256
+ assert_not ActiveRecord ::Base . connection . schema_cache . data_sources ( "posts" )
257
+ end
258
+
259
+ assert_match ( /Ignoring db\/ schema_cache\. yml because it has expired/ , error )
269
260
end
270
- assert_not ActiveRecord ::Base . connection . schema_cache . data_sources ( "posts" )
271
261
end
272
262
273
263
test "expire schema cache dump if the version can't be checked because the database is unhealthy" do
@@ -279,18 +269,20 @@ def show
279
269
RUBY
280
270
281
271
with_unhealthy_database do
282
- silence_warnings do
272
+ Dir . chdir ( app_path ) do
283
273
app ( "development" )
284
- end
285
274
286
- assert_not_nil ActiveRecord ::Base . connection_pool . schema_reflection . instance_variable_get ( :@cache )
275
+ assert_raises ActiveRecord ::ConnectionNotEstablished do
276
+ ActiveRecord ::Base . connection . execute ( "SELECT 1" )
277
+ end
287
278
288
- assert_raises ActiveRecord ::ConnectionNotEstablished do
289
- ActiveRecord ::Base . connection . execute ( "SELECT 1" )
290
- end
279
+ _ , error = capture_io do
280
+ assert_raises ActiveRecord ::ConnectionNotEstablished do
281
+ ActiveRecord ::Base . connection . schema_cache . columns ( "posts" )
282
+ end
283
+ end
291
284
292
- assert_raises ActiveRecord ::ConnectionNotEstablished do
293
- ActiveRecord ::Base . connection . schema_cache . columns ( "posts" )
285
+ assert_match ( /Failed to validate the schema cache because of ActiveRecord::ConnectionNotEstablished/ , error )
294
286
end
295
287
end
296
288
end
@@ -304,8 +296,11 @@ def show
304
296
config.active_record.check_schema_cache_dump_version = false
305
297
RUBY
306
298
307
- app ( "development" )
308
- assert ActiveRecord ::Base . connection_pool . schema_reflection . data_sources ( :__unused__ , "posts" )
299
+ Dir . chdir ( app_path ) do
300
+ app ( "development" )
301
+
302
+ assert ActiveRecord ::Base . connection_pool . schema_reflection . data_sources ( :__unused__ , "posts" )
303
+ end
309
304
end
310
305
311
306
test "does not expire schema cache dump if check_schema_cache_dump_version is false and the database unhealthy" do
@@ -318,11 +313,13 @@ def show
318
313
RUBY
319
314
320
315
with_unhealthy_database do
321
- app ( "development" )
316
+ Dir . chdir ( app_path ) do
317
+ app ( "development" )
322
318
323
- assert ActiveRecord ::Base . connection_pool . schema_reflection . data_sources ( :__unused__ , "posts" )
324
- assert_raises ActiveRecord ::ConnectionNotEstablished do
325
- ActiveRecord ::Base . connection . execute ( "SELECT 1" )
319
+ assert ActiveRecord ::Base . connection_pool . schema_reflection . data_sources ( :__unused__ , "posts" )
320
+ assert_raises ActiveRecord ::ConnectionNotEstablished do
321
+ ActiveRecord ::Base . connection . execute ( "SELECT 1" )
322
+ end
326
323
end
327
324
end
328
325
end
0 commit comments