Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove ChdirHelpers because https://bugs.ruby-lang.org/issues/15661 has been addressed #40936

Merged
merged 2 commits into from Dec 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 2 additions & 3 deletions railties/test/application/bin_setup_test.rb
@@ -1,11 +1,10 @@
# frozen_string_literal: true

require "isolation/abstract_unit"
require "chdir_helpers"

module ApplicationTests
class BinSetupTest < ActiveSupport::TestCase
include ActiveSupport::Testing::Isolation, ChdirHelpers
include ActiveSupport::Testing::Isolation

setup :build_app
teardown :teardown_app
Expand All @@ -29,7 +28,7 @@ def test_bin_setup
end

def test_bin_setup_output
chdir(app_path) do
Dir.chdir(app_path) do
# SQLite3 seems to auto-create the database on first checkout.
rails "db:system:change", "--to=postgresql"
rails "db:drop", allow_failure: true
Expand Down
37 changes: 18 additions & 19 deletions railties/test/application/rake/dbs_test.rb
@@ -1,13 +1,12 @@
# frozen_string_literal: true

require "isolation/abstract_unit"
require "chdir_helpers"
require "env_helpers"

module ApplicationTests
module RakeTests
class RakeDbsTest < ActiveSupport::TestCase
include ActiveSupport::Testing::Isolation, ChdirHelpers, EnvHelpers
include ActiveSupport::Testing::Isolation, EnvHelpers

def setup
build_app
Expand All @@ -29,7 +28,7 @@ def set_database_url
end

def db_create_and_drop(expected_database, environment_loaded: true)
chdir(app_path) do
Dir.chdir(app_path) do
output = rails("db:create")
assert_match(/Created database/, output)
assert File.exist?(expected_database)
Expand All @@ -42,7 +41,7 @@ def db_create_and_drop(expected_database, environment_loaded: true)
end

def db_create_with_warning(expected_database)
chdir(app_path) do
Dir.chdir(app_path) do
output = rails("db:create")
assert_match(/Rails couldn't infer whether you are using multiple databases/, output)
assert_match(/Created database/, output)
Expand Down Expand Up @@ -208,7 +207,7 @@ def db_create_with_warning(expected_database)
end

def with_database_existing
chdir(app_path) do
Dir.chdir(app_path) do
set_database_url
rails "db:create"
yield
Expand All @@ -224,7 +223,7 @@ def with_database_existing
end

def with_bad_permissions
chdir(app_path) do
Dir.chdir(app_path) do
skip "Can't avoid permissions as root" if Process.uid.zero?

set_database_url
Expand Down Expand Up @@ -272,7 +271,7 @@ def with_bad_permissions
end

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

test "db:truncate_all does not truncate any tables when environment is protected" do
with_rails_env "production" do
chdir(app_path) do
Dir.chdir(app_path) do
rails "generate", "model", "book", "title:string"
rails "db:migrate"
require "#{app_path}/config/environment"
Expand Down Expand Up @@ -345,7 +344,7 @@ def db_migrate_and_status(expected_database)
end

def db_schema_dump
chdir(app_path) do
Dir.chdir(app_path) do
args = ["generate", "model", "book", "title:string"]
rails args
rails "db:migrate", "db:schema:dump"
Expand All @@ -363,7 +362,7 @@ def db_schema_dump
end

def db_schema_cache_dump(filename = "db/schema_cache.yml")
chdir(app_path) do
Dir.chdir(app_path) do
rails "db:schema:cache:dump"

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

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

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

def db_fixtures_load(expected_database)
chdir(app_path) do
Dir.chdir(app_path) do
rails "generate", "model", "book", "title:string"
reload
rails "db:migrate", "db:fixtures:load"
Expand Down Expand Up @@ -473,7 +472,7 @@ def db_fixtures_load(expected_database)
end

def db_structure_dump_and_load(expected_database)
chdir(app_path) do
Dir.chdir(app_path) do
rails "generate", "model", "book", "title:string"
rails "db:migrate", "db:structure:dump"
structure_dump = File.read("db/structure.sql")
Expand Down Expand Up @@ -585,7 +584,7 @@ def db_structure_dump_and_load(expected_database)
end

def db_test_load_structure
chdir(app_path) do
Dir.chdir(app_path) do
rails "generate", "model", "book", "title:string"
rails "db:migrate", "db:structure:dump", "db:test:load_structure"
ActiveRecord::Base.configurations = Rails.application.config.database_configuration
Expand Down Expand Up @@ -675,7 +674,7 @@ def db_test_load_structure
end

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

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

test "db:prepare setup the database" do
chdir(app_path) do
Dir.chdir(app_path) do
rails "generate", "model", "book", "title:string"
output = rails("db:prepare")
assert_match(/CreateBooks: migrated/, output)
Expand All @@ -757,7 +756,7 @@ def db_test_load_structure
end

test "db:prepare does not touch schema when dumping is disabled" do
chdir(app_path) do
Dir.chdir(app_path) do
rails "generate", "model", "book", "title:string"
rails "db:create", "db:migrate"

Expand Down
5 changes: 2 additions & 3 deletions railties/test/application/rake/log_test.rb
@@ -1,12 +1,11 @@
# frozen_string_literal: true

require "isolation/abstract_unit"
require "chdir_helpers"

module ApplicationTests
module RakeTests
class LogTest < ActiveSupport::TestCase
include ActiveSupport::Testing::Isolation, ChdirHelpers
include ActiveSupport::Testing::Isolation

def setup
build_app
Expand All @@ -17,7 +16,7 @@ def teardown
end

test "log:clear clear all environments log files by default" do
chdir(app_path) do
Dir.chdir(app_path) do
File.open("config/environments/staging.rb", "w")

File.write("log/staging.log", "staging")
Expand Down
13 changes: 5 additions & 8 deletions railties/test/application/rake/migrations_test.rb
@@ -1,13 +1,10 @@
# frozen_string_literal: true

require "isolation/abstract_unit"
require "chdir_helpers"

module ApplicationTests
module RakeTests
class RakeMigrationsTest < ActiveSupport::TestCase
include ChdirHelpers

def setup
build_app
FileUtils.rm_rf("#{app_path}/config/environments")
Expand Down Expand Up @@ -268,7 +265,7 @@ class TwoMigration < ActiveRecord::Migration::Current
end

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

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

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

chdir(app_path) do
Dir.chdir(app_path) do
rails "generate", "model", "reviews", "book_id:integer"
rails "db:migrate"

Expand All @@ -435,7 +432,7 @@ class TwoMigration < ActiveRecord::Migration::Current
end

test "default schema generation after migration" do
chdir(app_path) do
Dir.chdir(app_path) do
rails "generate", "model", "book", "title:string"
rails "db:migrate"

Expand All @@ -445,7 +442,7 @@ class TwoMigration < ActiveRecord::Migration::Current
end

test "migration status migrated file is deleted" do
chdir(app_path) do
Dir.chdir(app_path) do
rails "generate", "model", "user", "username:string", "password:string"
rails "generate", "migration", "add_email_to_users", "email:string"
rails "db:migrate"
Expand Down