aboutsummaryrefslogtreecommitdiffstats
path: root/railties/test
diff options
context:
space:
mode:
Diffstat (limited to 'railties/test')
-rw-r--r--railties/test/application/assets_test.rb2
-rw-r--r--railties/test/application/configuration_test.rb4
-rw-r--r--railties/test/application/rake/multi_dbs_test.rb19
-rw-r--r--railties/test/application/zeitwerk_integration_test.rb29
-rw-r--r--railties/test/commands/credentials_test.rb9
-rw-r--r--railties/test/generators/app_generator_test.rb6
-rw-r--r--railties/test/generators/namespaced_generators_test.rb4
-rw-r--r--railties/test/railties/engine_test.rb2
8 files changed, 62 insertions, 13 deletions
diff --git a/railties/test/application/assets_test.rb b/railties/test/application/assets_test.rb
index a7dd233f3d..651897d8f3 100644
--- a/railties/test/application/assets_test.rb
+++ b/railties/test/application/assets_test.rb
@@ -311,7 +311,7 @@ module ApplicationTests
manifest = Dir["#{app_path}/public/assets/.sprockets-manifest-*.json"].first
assets = ActiveSupport::JSON.decode(File.read(manifest))
- assert asset_path = assets["assets"].find { |(k, _)| k && k =~ /.png/ }[1]
+ assert asset_path = assets["assets"].find { |(k, _)| /.png/.match?(k) }[1]
# Load app env
app "development"
diff --git a/railties/test/application/configuration_test.rb b/railties/test/application/configuration_test.rb
index 38dda20bec..b44edbc7d3 100644
--- a/railties/test/application/configuration_test.rb
+++ b/railties/test/application/configuration_test.rb
@@ -456,7 +456,7 @@ module ApplicationTests
test "filter_parameters should be able to set via config.filter_parameters" do
add_to_config <<-RUBY
config.filter_parameters += [ :foo, 'bar', lambda { |key, value|
- value = value.reverse if key =~ /baz/
+ value = value.reverse if /baz/.match?(key)
}]
RUBY
@@ -790,7 +790,7 @@ module ApplicationTests
end
get "/"
- assert last_response.body =~ /csrf\-param/
+ assert_match(/csrf\-param/, last_response.body)
end
test "default form builder specified as a string" do
diff --git a/railties/test/application/rake/multi_dbs_test.rb b/railties/test/application/rake/multi_dbs_test.rb
index 2606e64424..c5f8904f4e 100644
--- a/railties/test/application/rake/multi_dbs_test.rb
+++ b/railties/test/application/rake/multi_dbs_test.rb
@@ -349,6 +349,25 @@ module ApplicationTests
rails "db:drop" rescue nil
end
end
+
+ test "db:seed uses primary database connection" do
+ @old_rails_env = ENV["RAILS_ENV"]
+ @old_rack_env = ENV["RACK_ENV"]
+ ENV.delete "RAILS_ENV"
+ ENV.delete "RACK_ENV"
+
+ db_migrate_and_schema_dump_and_load "schema"
+
+ app_file "db/seeds.rb", <<-RUBY
+ print Book.connection.pool.spec.config[:database]
+ RUBY
+
+ output = rails("db:seed")
+ assert_equal output, "db/development.sqlite3"
+ ensure
+ ENV["RAILS_ENV"] = @old_rails_env
+ ENV["RACK_ENV"] = @old_rack_env
+ end
end
end
end
diff --git a/railties/test/application/zeitwerk_integration_test.rb b/railties/test/application/zeitwerk_integration_test.rb
index ff8c06b479..d03fa3d0c6 100644
--- a/railties/test/application/zeitwerk_integration_test.rb
+++ b/railties/test/application/zeitwerk_integration_test.rb
@@ -150,6 +150,35 @@ class ZeitwerkIntegrationTest < ActiveSupport::TestCase
assert_empty deps.autoloaded_constants
end
+ [true, false].each do |add_aps_to_lp|
+ test "require_dependency looks autoload paths up (#{add_aps_to_lp})" do
+ add_to_config "config.add_autoload_paths_to_load_path = #{add_aps_to_lp}"
+ app_file "app/models/user.rb", "class User; end"
+ boot
+
+ assert require_dependency("user")
+ end
+
+ test "require_dependency handles absolute paths correctly (#{add_aps_to_lp})" do
+ add_to_config "config.add_autoload_paths_to_load_path = #{add_aps_to_lp}"
+ app_file "app/models/user.rb", "class User; end"
+ boot
+
+ assert require_dependency("#{app_path}/app/models/user.rb")
+ end
+
+ test "require_dependency supports arguments that repond to to_path (#{add_aps_to_lp})" do
+ add_to_config "config.add_autoload_paths_to_load_path = #{add_aps_to_lp}"
+ app_file "app/models/user.rb", "class User; end"
+ boot
+
+ user = Object.new
+ def user.to_path; "user"; end
+
+ assert require_dependency(user)
+ end
+ end
+
test "eager loading loads the application code" do
$zeitwerk_integration_test_user = false
$zeitwerk_integration_test_post = false
diff --git a/railties/test/commands/credentials_test.rb b/railties/test/commands/credentials_test.rb
index 562e2ec382..3dec6fbe10 100644
--- a/railties/test/commands/credentials_test.rb
+++ b/railties/test/commands/credentials_test.rb
@@ -5,6 +5,7 @@ require "env_helpers"
require "rails/command"
require "rails/commands/credentials/credentials_command"
require "fileutils"
+require "tempfile"
class Rails::Command::CredentialsCommandTest < ActiveSupport::TestCase
include ActiveSupport::Testing::Isolation, EnvHelpers
@@ -110,7 +111,7 @@ class Rails::Command::CredentialsCommandTest < ActiveSupport::TestCase
end
test "edit ask the user to opt in to pretty credentials, user accepts" do
- file = File.open("foo", "w")
+ file = Tempfile.open("credentials_test")
file.write("y")
file.rewind
@@ -127,11 +128,11 @@ class Rails::Command::CredentialsCommandTest < ActiveSupport::TestCase
assert_equal("bin/rails credentials:show\n", `git config --get 'diff.rails_credentials.textconv'`)
end
ensure
- File.delete(file)
+ file.close!
end
test "edit ask the user to opt in to pretty credentials, user refuses" do
- file = File.open("foo", "w")
+ file = Tempfile.open("credentials_test")
file.write("n")
file.rewind
@@ -140,7 +141,7 @@ class Rails::Command::CredentialsCommandTest < ActiveSupport::TestCase
git_attributes = app_path(".gitattributes")
assert_not(File.exist?(git_attributes))
ensure
- File.delete(file)
+ file.close!
end
test "show credentials" do
diff --git a/railties/test/generators/app_generator_test.rb b/railties/test/generators/app_generator_test.rb
index 5b439fdcba..43461036f3 100644
--- a/railties/test/generators/app_generator_test.rb
+++ b/railties/test/generators/app_generator_test.rb
@@ -678,7 +678,7 @@ class AppGeneratorTest < Rails::Generators::TestCase
def test_inclusion_of_listen_related_configuration_by_default
run_generator
- if RbConfig::CONFIG["host_os"] =~ /darwin|linux/
+ if /darwin|linux/.match?(RbConfig::CONFIG["host_os"])
assert_listen_related_configuration
else
assert_no_listen_related_configuration
@@ -690,7 +690,7 @@ class AppGeneratorTest < Rails::Generators::TestCase
Object.const_set(:RUBY_ENGINE, "MyRuby")
run_generator
- if RbConfig::CONFIG["host_os"] =~ /darwin|linux/
+ if /darwin|linux/.match?(RbConfig::CONFIG["host_os"])
assert_listen_related_configuration
else
assert_no_listen_related_configuration
@@ -708,7 +708,7 @@ class AppGeneratorTest < Rails::Generators::TestCase
def test_evented_file_update_checker_config
run_generator
assert_file "config/environments/development.rb" do |content|
- if RbConfig::CONFIG["host_os"] =~ /darwin|linux/
+ if /darwin|linux/.match?(RbConfig::CONFIG["host_os"])
assert_match(/^\s*config\.file_watcher = ActiveSupport::EventedFileUpdateChecker/, content)
else
assert_match(/^\s*# config\.file_watcher = ActiveSupport::EventedFileUpdateChecker/, content)
diff --git a/railties/test/generators/namespaced_generators_test.rb b/railties/test/generators/namespaced_generators_test.rb
index 4b75a31f17..12ccbe6ff1 100644
--- a/railties/test/generators/namespaced_generators_test.rb
+++ b/railties/test/generators/namespaced_generators_test.rb
@@ -308,7 +308,7 @@ class NamespacedScaffoldGeneratorTest < NamespacedGeneratorTestCase
run_generator [ "admin/role" ], behavior: :revoke
# Model
- assert_file "app/models/test_app/admin.rb" # ( should not be remove )
+ assert_file "app/models/test_app/admin.rb" # ( should not be remove )
assert_no_file "app/models/test_app/admin/role.rb"
assert_no_file "test/models/test_app/admin/role_test.rb"
assert_no_file "test/fixtures/test_app/admin/roles.yml"
@@ -375,7 +375,7 @@ class NamespacedScaffoldGeneratorTest < NamespacedGeneratorTestCase
run_generator [ "admin/user/special/role" ], behavior: :revoke
# Model
- assert_file "app/models/test_app/admin/user/special.rb" # ( should not be remove )
+ assert_file "app/models/test_app/admin/user/special.rb" # ( should not be remove )
assert_no_file "app/models/test_app/admin/user/special/role.rb"
assert_no_file "test/models/test_app/admin/user/special/role_test.rb"
assert_no_file "test/fixtures/test_app/admin/user/special/roles.yml"
diff --git a/railties/test/railties/engine_test.rb b/railties/test/railties/engine_test.rb
index 7f05b9d9cf..06836844f0 100644
--- a/railties/test/railties/engine_test.rb
+++ b/railties/test/railties/engine_test.rb
@@ -110,7 +110,7 @@ module RailtiesTest
assert_no_match(/\d+_create_users/, output.join("\n"))
- bukkits_migration_order = output.index(output.detect { |o| /NOTE: Migration \d+_create_sessions\.rb from bukkits has been skipped/ =~ o })
+ bukkits_migration_order = output.index(output.detect { |o| /NOTE: Migration \d+_create_sessions\.rb from bukkits has been skipped/.match?(o) })
assert_not_nil bukkits_migration_order, "Expected migration to be skipped"
end
end