@@ -510,6 +510,45 @@ def generate_models_for_animals
510
510
end
511
511
end
512
512
513
+ test "db:schema:load:name doesn't purge the test database. The test schema is maintained when running tests" do
514
+ require "#{ app_path } /config/environment"
515
+ Dir . chdir ( app_path ) do
516
+ generate_models_for_animals
517
+
518
+ File . open ( "test/models/dog_test.rb" , "w" ) do |file |
519
+ file . write ( <<~EOS )
520
+ require "test_helper"
521
+
522
+ class DogTest < ActiveSupport::TestCase
523
+ test "Dog name type" do
524
+ puts Dog.type_for_attribute(:name).type
525
+ end
526
+ end
527
+ EOS
528
+ end
529
+
530
+ rails ( "db:migrate:primary" , "db:migrate:animals" )
531
+
532
+ development_runner_output = rails ( "runner" , "puts Dog.type_for_attribute(:name).type" )
533
+ assert_match ( /string/ , development_runner_output )
534
+
535
+ test_output = rails ( "test" , "test/models/dog_test.rb" )
536
+ assert_match ( /string/ , test_output )
537
+
538
+ # Simulate a schema change
539
+ content = File . read ( "db/animals_schema.rb" )
540
+ content . gsub! ( /t\. string "name"/ , "t.text \" name\" " )
541
+ File . write ( "db/animals_schema.rb" , content )
542
+
543
+ rails ( "db:schema:load:animals" )
544
+ development_runner_output = rails ( "runner" , "puts Dog.type_for_attribute(:name).type" )
545
+ assert_match ( /text/ , development_runner_output )
546
+
547
+ test_output = rails ( "test" , "test/models/dog_test.rb" )
548
+ assert_match ( /text/ , test_output )
549
+ end
550
+ end
551
+
513
552
test "db:migrate respects timestamp ordering across databases" do
514
553
require "#{ app_path } /config/environment"
515
554
app_file "db/migrate/01_one_migration.rb" , <<-MIGRATION
0 commit comments