Skip to content

Commit fb9bfa7

Browse files
authored
Merge pull request rails#40936 from yahonda/follow_up_ruby_3990
Remove ChdirHelpers because https://bugs.ruby-lang.org/issues/15661 has been addressed
2 parents 1ed0ece + fd057e1 commit fb9bfa7

File tree

8 files changed

+51
-72
lines changed

8 files changed

+51
-72
lines changed

railties/test/application/bin_setup_test.rb

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
# frozen_string_literal: true
22

33
require "isolation/abstract_unit"
4-
require "chdir_helpers"
54

65
module ApplicationTests
76
class BinSetupTest < ActiveSupport::TestCase
8-
include ActiveSupport::Testing::Isolation, ChdirHelpers
7+
include ActiveSupport::Testing::Isolation
98

109
setup :build_app
1110
teardown :teardown_app
@@ -29,7 +28,7 @@ def test_bin_setup
2928
end
3029

3130
def test_bin_setup_output
32-
chdir(app_path) do
31+
Dir.chdir(app_path) do
3332
# SQLite3 seems to auto-create the database on first checkout.
3433
rails "db:system:change", "--to=postgresql"
3534
rails "db:drop", allow_failure: true

railties/test/application/rake/dbs_test.rb

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
# frozen_string_literal: true
22

33
require "isolation/abstract_unit"
4-
require "chdir_helpers"
54
require "env_helpers"
65

76
module ApplicationTests
87
module RakeTests
98
class RakeDbsTest < ActiveSupport::TestCase
10-
include ActiveSupport::Testing::Isolation, ChdirHelpers, EnvHelpers
9+
include ActiveSupport::Testing::Isolation, EnvHelpers
1110

1211
def setup
1312
build_app
@@ -29,7 +28,7 @@ def set_database_url
2928
end
3029

3130
def db_create_and_drop(expected_database, environment_loaded: true)
32-
chdir(app_path) do
31+
Dir.chdir(app_path) do
3332
output = rails("db:create")
3433
assert_match(/Created database/, output)
3534
assert File.exist?(expected_database)
@@ -42,7 +41,7 @@ def db_create_and_drop(expected_database, environment_loaded: true)
4241
end
4342

4443
def db_create_with_warning(expected_database)
45-
chdir(app_path) do
44+
Dir.chdir(app_path) do
4645
output = rails("db:create")
4746
assert_match(/Rails couldn't infer whether you are using multiple databases/, output)
4847
assert_match(/Created database/, output)
@@ -208,7 +207,7 @@ def db_create_with_warning(expected_database)
208207
end
209208

210209
def with_database_existing
211-
chdir(app_path) do
210+
Dir.chdir(app_path) do
212211
set_database_url
213212
rails "db:create"
214213
yield
@@ -224,7 +223,7 @@ def with_database_existing
224223
end
225224

226225
def with_bad_permissions
227-
chdir(app_path) do
226+
Dir.chdir(app_path) do
228227
skip "Can't avoid permissions as root" if Process.uid.zero?
229228

230229
set_database_url
@@ -272,7 +271,7 @@ def with_bad_permissions
272271
end
273272

274273
test "db:truncate_all truncates all non-internal tables" do
275-
chdir(app_path) do
274+
Dir.chdir(app_path) do
276275
rails "generate", "model", "book", "title:string"
277276
rails "db:migrate"
278277
require "#{app_path}/config/environment"
@@ -297,7 +296,7 @@ def with_bad_permissions
297296

298297
test "db:truncate_all does not truncate any tables when environment is protected" do
299298
with_rails_env "production" do
300-
chdir(app_path) do
299+
Dir.chdir(app_path) do
301300
rails "generate", "model", "book", "title:string"
302301
rails "db:migrate"
303302
require "#{app_path}/config/environment"
@@ -345,7 +344,7 @@ def db_migrate_and_status(expected_database)
345344
end
346345

347346
def db_schema_dump
348-
chdir(app_path) do
347+
Dir.chdir(app_path) do
349348
args = ["generate", "model", "book", "title:string"]
350349
rails args
351350
rails "db:migrate", "db:schema:dump"
@@ -363,7 +362,7 @@ def db_schema_dump
363362
end
364363

365364
def db_schema_cache_dump(filename = "db/schema_cache.yml")
366-
chdir(app_path) do
365+
Dir.chdir(app_path) do
367366
rails "db:schema:cache:dump"
368367

369368
cache_size = lambda { rails("runner", "p ActiveRecord::Base.connection.schema_cache.size").strip }
@@ -381,7 +380,7 @@ def db_schema_cache_dump(filename = "db/schema_cache.yml")
381380
end
382381

383382
test "db:schema:cache:dump with custom filename" do
384-
chdir(app_path) do
383+
Dir.chdir(app_path) do
385384
File.open("#{app_path}/config/database.yml", "w") do |f|
386385
f.puts <<-YAML
387386
default: &default
@@ -414,7 +413,7 @@ def db_schema_cache_dump(filename = "db/schema_cache.yml")
414413
end
415414

416415
test "db:schema:cache:dump first config wins" do
417-
chdir(app_path) do
416+
Dir.chdir(app_path) do
418417
File.open("#{app_path}/config/database.yml", "w") do |f|
419418
f.puts <<-YAML
420419
default: &default
@@ -440,7 +439,7 @@ def db_schema_cache_dump(filename = "db/schema_cache.yml")
440439
end
441440

442441
def db_fixtures_load(expected_database)
443-
chdir(app_path) do
442+
Dir.chdir(app_path) do
444443
rails "generate", "model", "book", "title:string"
445444
reload
446445
rails "db:migrate", "db:fixtures:load"
@@ -473,7 +472,7 @@ def db_fixtures_load(expected_database)
473472
end
474473

475474
def db_structure_dump_and_load(expected_database)
476-
chdir(app_path) do
475+
Dir.chdir(app_path) do
477476
rails "generate", "model", "book", "title:string"
478477
rails "db:migrate", "db:structure:dump"
479478
structure_dump = File.read("db/structure.sql")
@@ -585,7 +584,7 @@ def db_structure_dump_and_load(expected_database)
585584
end
586585

587586
def db_test_load_structure
588-
chdir(app_path) do
587+
Dir.chdir(app_path) do
589588
rails "generate", "model", "book", "title:string"
590589
rails "db:migrate", "db:structure:dump", "db:test:load_structure"
591590
ActiveRecord::Base.configurations = Rails.application.config.database_configuration
@@ -675,7 +674,7 @@ def db_test_load_structure
675674
end
676675

677676
test "db:seed:replant truncates all non-internal tables and loads the seeds" do
678-
chdir(app_path) do
677+
Dir.chdir(app_path) do
679678
rails "generate", "model", "book", "title:string"
680679
rails "db:migrate"
681680
require "#{app_path}/config/environment"
@@ -708,7 +707,7 @@ def db_test_load_structure
708707

709708
test "db:seed:replant does not truncate any tables and does not load the seeds when environment is protected" do
710709
with_rails_env "production" do
711-
chdir(app_path) do
710+
Dir.chdir(app_path) do
712711
rails "generate", "model", "book", "title:string"
713712
rails "db:migrate"
714713
require "#{app_path}/config/environment"
@@ -741,7 +740,7 @@ def db_test_load_structure
741740
end
742741

743742
test "db:prepare setup the database" do
744-
chdir(app_path) do
743+
Dir.chdir(app_path) do
745744
rails "generate", "model", "book", "title:string"
746745
output = rails("db:prepare")
747746
assert_match(/CreateBooks: migrated/, output)
@@ -757,7 +756,7 @@ def db_test_load_structure
757756
end
758757

759758
test "db:prepare does not touch schema when dumping is disabled" do
760-
chdir(app_path) do
759+
Dir.chdir(app_path) do
761760
rails "generate", "model", "book", "title:string"
762761
rails "db:create", "db:migrate"
763762

railties/test/application/rake/log_test.rb

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
# frozen_string_literal: true
22

33
require "isolation/abstract_unit"
4-
require "chdir_helpers"
54

65
module ApplicationTests
76
module RakeTests
87
class LogTest < ActiveSupport::TestCase
9-
include ActiveSupport::Testing::Isolation, ChdirHelpers
8+
include ActiveSupport::Testing::Isolation
109

1110
def setup
1211
build_app
@@ -17,7 +16,7 @@ def teardown
1716
end
1817

1918
test "log:clear clear all environments log files by default" do
20-
chdir(app_path) do
19+
Dir.chdir(app_path) do
2120
File.open("config/environments/staging.rb", "w")
2221

2322
File.write("log/staging.log", "staging")

railties/test/application/rake/migrations_test.rb

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
# frozen_string_literal: true
22

33
require "isolation/abstract_unit"
4-
require "chdir_helpers"
54

65
module ApplicationTests
76
module RakeTests
87
class RakeMigrationsTest < ActiveSupport::TestCase
9-
include ChdirHelpers
10-
118
def setup
129
build_app
1310
FileUtils.rm_rf("#{app_path}/config/environments")
@@ -268,7 +265,7 @@ class TwoMigration < ActiveRecord::Migration::Current
268265
end
269266

270267
test "raise error on any move when current migration does not exist" do
271-
chdir(app_path) do
268+
Dir.chdir(app_path) do
272269
rails "generate", "model", "user", "username:string", "password:string"
273270
rails "generate", "migration", "add_email_to_users", "email:string"
274271
rails "db:migrate"
@@ -414,7 +411,7 @@ class TwoMigration < ActiveRecord::Migration::Current
414411
test "schema generation when dump_schema_after_migration is set" do
415412
add_to_config("config.active_record.dump_schema_after_migration = false")
416413

417-
chdir(app_path) do
414+
Dir.chdir(app_path) do
418415
rails "generate", "model", "book", "title:string"
419416
output = rails("generate", "model", "author", "name:string")
420417
version = output =~ %r{[^/]+db/migrate/(\d+)_create_authors\.rb} && $1
@@ -425,7 +422,7 @@ class TwoMigration < ActiveRecord::Migration::Current
425422

426423
add_to_config("config.active_record.dump_schema_after_migration = true")
427424

428-
chdir(app_path) do
425+
Dir.chdir(app_path) do
429426
rails "generate", "model", "reviews", "book_id:integer"
430427
rails "db:migrate"
431428

@@ -435,7 +432,7 @@ class TwoMigration < ActiveRecord::Migration::Current
435432
end
436433

437434
test "default schema generation after migration" do
438-
chdir(app_path) do
435+
Dir.chdir(app_path) do
439436
rails "generate", "model", "book", "title:string"
440437
rails "db:migrate"
441438

@@ -445,7 +442,7 @@ class TwoMigration < ActiveRecord::Migration::Current
445442
end
446443

447444
test "migration status migrated file is deleted" do
448-
chdir(app_path) do
445+
Dir.chdir(app_path) do
449446
rails "generate", "model", "user", "username:string", "password:string"
450447
rails "generate", "migration", "add_email_to_users", "email:string"
451448
rails "db:migrate"

0 commit comments

Comments
 (0)