@@ -315,8 +315,24 @@ def test_cache_dump_default_filename
315
315
old_path = ENV [ "SCHEMA_CACHE" ]
316
316
ENV . delete ( "SCHEMA_CACHE" )
317
317
318
+ config = DatabaseConfigurations ::HashConfig . new ( "development" , "primary" , { } )
319
+
318
320
ActiveRecord ::Tasks ::DatabaseTasks . stub ( :db_dir , "db" ) do
319
- path = ActiveRecord ::Tasks ::DatabaseTasks . cache_dump_filename ( "primary" )
321
+ path = ActiveRecord ::Tasks ::DatabaseTasks . cache_dump_filename ( config )
322
+ assert_equal "db/schema_cache.yml" , path
323
+ end
324
+ ensure
325
+ ENV [ "SCHEMA_CACHE" ] = old_path
326
+ end
327
+
328
+ def test_deprecated_cache_dump_default_filename
329
+ old_path = ENV [ "SCHEMA_CACHE" ]
330
+ ENV . delete ( "SCHEMA_CACHE" )
331
+
332
+ ActiveRecord ::Tasks ::DatabaseTasks . stub ( :db_dir , "db" ) do
333
+ path = assert_deprecated ( ActiveRecord . deprecator ) do
334
+ ActiveRecord ::Tasks ::DatabaseTasks . cache_dump_filename ( "primary" )
335
+ end
320
336
assert_equal "db/schema_cache.yml" , path
321
337
end
322
338
ensure
@@ -327,8 +343,24 @@ def test_cache_dump_alternate_filename
327
343
old_path = ENV [ "SCHEMA_CACHE" ]
328
344
ENV . delete ( "SCHEMA_CACHE" )
329
345
346
+ config = DatabaseConfigurations ::HashConfig . new ( "development" , "alternate" , { } )
347
+
348
+ ActiveRecord ::Tasks ::DatabaseTasks . stub ( :db_dir , "db" ) do
349
+ path = ActiveRecord ::Tasks ::DatabaseTasks . cache_dump_filename ( config )
350
+ assert_equal "db/alternate_schema_cache.yml" , path
351
+ end
352
+ ensure
353
+ ENV [ "SCHEMA_CACHE" ] = old_path
354
+ end
355
+
356
+ def test_deprecated_cache_dump_alternate_filename
357
+ old_path = ENV [ "SCHEMA_CACHE" ]
358
+ ENV . delete ( "SCHEMA_CACHE" )
359
+
330
360
ActiveRecord ::Tasks ::DatabaseTasks . stub ( :db_dir , "db" ) do
331
- path = ActiveRecord ::Tasks ::DatabaseTasks . cache_dump_filename ( "alternate" )
361
+ path = assert_deprecated ( ActiveRecord . deprecator ) do
362
+ ActiveRecord ::Tasks ::DatabaseTasks . cache_dump_filename ( "alternate" )
363
+ end
332
364
assert_equal "db/alternate_schema_cache.yml" , path
333
365
end
334
366
ensure
@@ -339,8 +371,24 @@ def test_cache_dump_filename_with_env_override
339
371
old_path = ENV [ "SCHEMA_CACHE" ]
340
372
ENV [ "SCHEMA_CACHE" ] = "tmp/something.yml"
341
373
374
+ config = DatabaseConfigurations ::HashConfig . new ( "development" , "primary" , { } )
375
+
342
376
ActiveRecord ::Tasks ::DatabaseTasks . stub ( :db_dir , "db" ) do
343
- path = ActiveRecord ::Tasks ::DatabaseTasks . cache_dump_filename ( "primary" )
377
+ path = ActiveRecord ::Tasks ::DatabaseTasks . cache_dump_filename ( config )
378
+ assert_equal "tmp/something.yml" , path
379
+ end
380
+ ensure
381
+ ENV [ "SCHEMA_CACHE" ] = old_path
382
+ end
383
+
384
+ def test_deprecated_cache_dump_filename_with_env_override
385
+ old_path = ENV [ "SCHEMA_CACHE" ]
386
+ ENV [ "SCHEMA_CACHE" ] = "tmp/something.yml"
387
+
388
+ ActiveRecord ::Tasks ::DatabaseTasks . stub ( :db_dir , "db" ) do
389
+ path = assert_deprecated ( ActiveRecord . deprecator ) do
390
+ ActiveRecord ::Tasks ::DatabaseTasks . cache_dump_filename ( "primary" )
391
+ end
344
392
assert_equal "tmp/something.yml" , path
345
393
end
346
394
ensure
@@ -351,8 +399,39 @@ def test_cache_dump_filename_with_path_from_db_config
351
399
old_path = ENV [ "SCHEMA_CACHE" ]
352
400
ENV . delete ( "SCHEMA_CACHE" )
353
401
402
+ config = DatabaseConfigurations ::HashConfig . new ( "development" , "primary" , { schema_cache_path : "tmp/something.yml" } )
403
+
354
404
ActiveRecord ::Tasks ::DatabaseTasks . stub ( :db_dir , "db" ) do
355
- path = ActiveRecord ::Tasks ::DatabaseTasks . cache_dump_filename ( "primary" , schema_cache_path : "tmp/something.yml" )
405
+ path = ActiveRecord ::Tasks ::DatabaseTasks . cache_dump_filename ( config )
406
+ assert_equal "tmp/something.yml" , path
407
+ end
408
+ ensure
409
+ ENV [ "SCHEMA_CACHE" ] = old_path
410
+ end
411
+
412
+
413
+ def test_cache_dump_filename_with_path_from_the_argument_has_precedence
414
+ old_path = ENV [ "SCHEMA_CACHE" ]
415
+ ENV . delete ( "SCHEMA_CACHE" )
416
+
417
+ config = DatabaseConfigurations ::HashConfig . new ( "development" , "primary" , { schema_cache_path : "tmp/something.yml" } )
418
+
419
+ ActiveRecord ::Tasks ::DatabaseTasks . stub ( :db_dir , "db" ) do
420
+ path = ActiveRecord ::Tasks ::DatabaseTasks . cache_dump_filename ( config , schema_cache_path : "tmp/another.yml" )
421
+ assert_equal "tmp/another.yml" , path
422
+ end
423
+ ensure
424
+ ENV [ "SCHEMA_CACHE" ] = old_path
425
+ end
426
+
427
+ def test_deprecated_cache_dump_filename_with_path_from_the_argument
428
+ old_path = ENV [ "SCHEMA_CACHE" ]
429
+ ENV . delete ( "SCHEMA_CACHE" )
430
+
431
+ ActiveRecord ::Tasks ::DatabaseTasks . stub ( :db_dir , "db" ) do
432
+ path = assert_deprecated ( ActiveRecord . deprecator ) do
433
+ ActiveRecord ::Tasks ::DatabaseTasks . cache_dump_filename ( "primary" , schema_cache_path : "tmp/something.yml" )
434
+ end
356
435
assert_equal "tmp/something.yml" , path
357
436
end
358
437
ensure
0 commit comments