@@ -473,21 +473,21 @@ def test_do_not_dump_foreign_keys_when_bypassed_by_config
473
473
end
474
474
end
475
475
476
- class CreateDogMigration < ActiveRecord ::Migration ::Current
476
+ class CreateCatMigration < ActiveRecord ::Migration ::Current
477
477
def up
478
- create_table ( "dog_owners " ) do |t |
478
+ create_table ( "cat_owners " ) do |t |
479
479
end
480
480
481
- create_table ( "dogs " ) do |t |
481
+ create_table ( "cats " ) do |t |
482
482
t . column :name , :string
483
483
t . references :owner
484
484
t . index [ :name ]
485
- t . foreign_key :dog_owners , column : "owner_id"
485
+ t . foreign_key :cat_owners , column : "owner_id"
486
486
end
487
487
end
488
488
def down
489
- drop_table ( "dogs " )
490
- drop_table ( "dog_owners " )
489
+ drop_table ( "cats " )
490
+ drop_table ( "cat_owners " )
491
491
end
492
492
end
493
493
@@ -497,16 +497,21 @@ def test_schema_dump_with_table_name_prefix_and_suffix
497
497
ActiveRecord ::Base . table_name_prefix = "foo_"
498
498
ActiveRecord ::Base . table_name_suffix = "_bar"
499
499
500
- migration = CreateDogMigration . new
500
+ migration = CreateCatMigration . new
501
501
migration . migrate ( :up )
502
502
503
- output = dump_table_schema ( "dog_owners" , "dogs" )
503
+ output = dump_table_schema ( "foo_cat_owners_bar" , "foo_cats_bar" )
504
+
505
+ assert_match %r{create_table "cat_owners"} , output
506
+ assert_match %r{create_table "cats"} , output
507
+ assert_match %r{t\. index \[ "name"\] , name: "index_foo_cats_bar_on_name"} , output
504
508
assert_no_match %r{create_table "foo_.+_bar"} , output
505
509
assert_no_match %r{add_index "foo_.+_bar"} , output
506
510
assert_no_match %r{create_table "schema_migrations"} , output
507
511
assert_no_match %r{create_table "ar_internal_metadata"} , output
508
512
509
513
if ActiveRecord ::Base . lease_connection . supports_foreign_keys?
514
+ assert_match %r{add_foreign_key "cats", "cat_owners", column: "owner_id"} , output
510
515
assert_no_match %r{add_foreign_key "foo_.+_bar"} , output
511
516
assert_no_match %r{add_foreign_key "[^"]+", "foo_.+_bar"} , output
512
517
end
@@ -524,16 +529,21 @@ def test_schema_dump_with_table_name_prefix_and_suffix_regexp_escape
524
529
ActiveRecord ::Base . table_name_prefix = "foo$"
525
530
ActiveRecord ::Base . table_name_suffix = "$bar"
526
531
527
- migration = CreateDogMigration . new
532
+ migration = CreateCatMigration . new
528
533
migration . migrate ( :up )
529
534
530
- output = dump_table_schema ( "dog_owners" , "dog" )
535
+ output = dump_table_schema ( "foo$cat_owners$bar" , "foo$cat$bar" )
536
+
537
+ assert_match %r{create_table "cat_owners"} , output
538
+ assert_match %r{create_table "cats"} , output
539
+ assert_match %r{t\. index \[ "name"\] , name: "index_foo\$ cats\$ bar_on_name"} , output
531
540
assert_no_match %r{create_table "foo\$ .+\$ bar"} , output
532
541
assert_no_match %r{add_index "foo\$ .+\$ bar"} , output
533
542
assert_no_match %r{create_table "schema_migrations"} , output
534
543
assert_no_match %r{create_table "ar_internal_metadata"} , output
535
544
536
545
if ActiveRecord ::Base . lease_connection . supports_foreign_keys?
546
+ assert_match %r{add_foreign_key "cats", "cat_owners", column: "owner_id"} , output
537
547
assert_no_match %r{add_foreign_key "foo\$ .+\$ bar"} , output
538
548
assert_no_match %r{add_foreign_key "[^"]+", "foo\$ .+\$ bar"} , output
539
549
end
0 commit comments