railties 5.2.0 → 6.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +293 -89
- data/MIT-LICENSE +1 -1
- data/RDOC_MAIN.rdoc +39 -33
- data/README.rdoc +3 -3
- data/lib/minitest/rails_plugin.rb +24 -13
- data/lib/rails/all.rb +4 -0
- data/lib/rails/api/generator.rb +2 -1
- data/lib/rails/api/task.rb +17 -0
- data/lib/rails/app_loader.rb +2 -2
- data/lib/rails/app_updater.rb +4 -1
- data/lib/rails/application/bootstrap.rb +9 -17
- data/lib/rails/application/configuration.rb +177 -27
- data/lib/rails/application/default_middleware_stack.rb +7 -3
- data/lib/rails/application/dummy_erb_compiler.rb +18 -0
- data/lib/rails/application/finisher.rb +69 -2
- data/lib/rails/application/routes_reloader.rb +9 -19
- data/lib/rails/application.rb +96 -66
- data/lib/rails/application_controller.rb +0 -1
- data/lib/rails/autoloaders.rb +48 -0
- data/lib/rails/backtrace_cleaner.rb +14 -21
- data/lib/rails/code_statistics.rb +8 -6
- data/lib/rails/code_statistics_calculator.rb +6 -6
- data/lib/rails/command/actions.rb +10 -0
- data/lib/rails/command/base.rb +17 -5
- data/lib/rails/command/behavior.rb +8 -49
- data/lib/rails/command/environment_argument.rb +9 -16
- data/lib/rails/command/spellchecker.rb +57 -0
- data/lib/rails/command.rb +18 -11
- data/lib/rails/commands/console/console_command.rb +6 -0
- data/lib/rails/commands/credentials/USAGE +33 -0
- data/lib/rails/commands/credentials/credentials_command/diffing.rb +41 -0
- data/lib/rails/commands/credentials/credentials_command.rb +78 -21
- data/lib/rails/commands/db/system/change/change_command.rb +25 -0
- data/lib/rails/commands/dbconsole/dbconsole_command.rb +66 -51
- data/lib/rails/commands/dev/dev_command.rb +19 -0
- data/lib/rails/commands/encrypted/USAGE +28 -0
- data/lib/rails/commands/encrypted/encrypted_command.rb +5 -4
- data/lib/rails/commands/generate/generate_command.rb +1 -1
- data/lib/rails/commands/help/help_command.rb +1 -1
- data/lib/rails/commands/initializers/initializers_command.rb +23 -0
- data/lib/rails/commands/new/new_command.rb +2 -2
- data/lib/rails/commands/notes/notes_command.rb +29 -0
- data/lib/rails/commands/plugin/plugin_command.rb +1 -1
- data/lib/rails/commands/rake/rake_command.rb +9 -8
- data/lib/rails/commands/routes/routes_command.rb +37 -0
- data/lib/rails/commands/runner/runner_command.rb +13 -9
- data/lib/rails/commands/secrets/USAGE +6 -0
- data/lib/rails/commands/secrets/secrets_command.rb +3 -3
- data/lib/rails/commands/server/server_command.rb +92 -56
- data/lib/rails/commands/test/test_command.rb +2 -2
- data/lib/rails/configuration.rb +48 -19
- data/lib/rails/engine/configuration.rb +6 -2
- data/lib/rails/engine/updater.rb +1 -1
- data/lib/rails/engine.rb +63 -35
- data/lib/rails/gem_version.rb +2 -2
- data/lib/rails/generators/actions/create_migration.rb +5 -1
- data/lib/rails/generators/actions.rb +89 -56
- data/lib/rails/generators/app_base.rb +80 -108
- data/lib/rails/generators/app_name.rb +50 -0
- data/lib/rails/generators/base.rb +19 -12
- data/lib/rails/generators/database.rb +57 -0
- data/lib/rails/generators/erb/mailer/mailer_generator.rb +1 -2
- data/lib/rails/generators/erb/scaffold/scaffold_generator.rb +0 -1
- data/lib/rails/generators/erb/scaffold/templates/_form.html.erb.tt +7 -4
- data/lib/rails/generators/erb/scaffold/templates/index.html.erb.tt +1 -1
- data/lib/rails/generators/erb/scaffold/templates/show.html.erb.tt +9 -1
- data/lib/rails/generators/erb.rb +0 -1
- data/lib/rails/generators/generated_attribute.rb +50 -31
- data/lib/rails/generators/migration.rb +3 -3
- data/lib/rails/generators/model_helpers.rb +33 -2
- data/lib/rails/generators/named_base.rb +3 -7
- data/lib/rails/generators/rails/app/USAGE +2 -1
- data/lib/rails/generators/rails/app/app_generator.rb +127 -84
- data/lib/rails/generators/rails/app/templates/Gemfile.tt +18 -21
- data/lib/rails/generators/rails/app/templates/Rakefile.tt +1 -1
- data/lib/rails/generators/rails/app/templates/app/assets/config/manifest.js.tt +0 -3
- data/lib/rails/generators/rails/app/templates/app/javascript/channels/consumer.js +6 -0
- data/lib/rails/generators/rails/app/templates/app/javascript/channels/index.js +5 -0
- data/lib/rails/generators/rails/app/templates/app/javascript/packs/application.js.tt +23 -0
- data/lib/rails/generators/rails/app/templates/app/jobs/application_job.rb.tt +5 -0
- data/lib/rails/generators/rails/app/templates/app/views/layouts/application.html.erb.tt +6 -5
- data/lib/rails/generators/rails/app/templates/bin/rails.tt +5 -2
- data/lib/rails/generators/rails/app/templates/bin/rake.tt +5 -2
- data/lib/rails/generators/rails/app/templates/bin/setup.tt +9 -9
- data/lib/rails/generators/rails/app/templates/bin/spring.tt +9 -0
- data/lib/rails/generators/rails/app/templates/bin/yarn.tt +11 -3
- data/lib/rails/generators/rails/app/templates/config/application.rb.tt +16 -7
- data/lib/rails/generators/rails/app/templates/config/boot.rb.tt +2 -2
- data/lib/rails/generators/rails/app/templates/config/cable.yml.tt +1 -1
- data/lib/rails/generators/rails/app/templates/config/databases/jdbc.yml.tt +4 -5
- data/lib/rails/generators/rails/app/templates/config/databases/jdbcmysql.yml.tt +12 -11
- data/lib/rails/generators/rails/app/templates/config/databases/jdbcpostgresql.yml.tt +13 -12
- data/lib/rails/generators/rails/app/templates/config/databases/jdbcsqlite3.yml.tt +1 -1
- data/lib/rails/generators/rails/app/templates/config/databases/mysql.yml.tt +13 -12
- data/lib/rails/generators/rails/app/templates/config/databases/oracle.yml.tt +12 -11
- data/lib/rails/generators/rails/app/templates/config/databases/postgresql.yml.tt +16 -15
- data/lib/rails/generators/rails/app/templates/config/databases/sqlite3.yml.tt +1 -1
- data/lib/rails/generators/rails/app/templates/config/databases/sqlserver.yml.tt +11 -10
- data/lib/rails/generators/rails/app/templates/config/environment.rb.tt +1 -1
- data/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt +22 -5
- data/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt +43 -17
- data/lib/rails/generators/rails/app/templates/config/environments/test.rb.tt +26 -7
- data/lib/rails/generators/rails/app/templates/config/initializers/assets.rb.tt +1 -1
- data/lib/rails/generators/rails/app/templates/config/initializers/backtrace_silencers.rb.tt +4 -3
- data/lib/rails/generators/rails/app/templates/config/initializers/content_security_policy.rb.tt +7 -0
- data/lib/rails/generators/rails/app/templates/config/initializers/filter_parameter_logging.rb.tt +3 -1
- data/lib/rails/generators/rails/app/templates/config/initializers/new_framework_defaults_6_1.rb.tt +63 -0
- data/lib/rails/generators/rails/app/templates/config/initializers/permissions_policy.rb.tt +11 -0
- data/lib/rails/generators/rails/app/templates/config/locales/en.yml +1 -1
- data/lib/rails/generators/rails/app/templates/config/puma.rb.tt +13 -4
- data/lib/rails/generators/rails/app/templates/config/routes.rb.tt +1 -1
- data/lib/rails/generators/rails/app/templates/config/spring.rb.tt +6 -6
- data/lib/rails/generators/rails/app/templates/config.ru.tt +2 -1
- data/lib/rails/generators/rails/app/templates/db/seeds.rb.tt +1 -1
- data/lib/rails/generators/rails/app/templates/gitattributes.tt +14 -0
- data/lib/rails/generators/rails/app/templates/gitignore.tt +10 -7
- data/lib/rails/generators/rails/app/templates/package.json.tt +8 -2
- data/lib/rails/generators/rails/app/templates/public/robots.txt +1 -1
- data/lib/rails/generators/rails/app/templates/ruby-version.tt +1 -1
- data/lib/rails/generators/rails/app/templates/test/channels/application_cable/connection_test.rb.tt +11 -0
- data/lib/rails/generators/rails/app/templates/test/test_helper.rb.tt +9 -2
- data/lib/rails/generators/rails/assets/USAGE +3 -7
- data/lib/rails/generators/rails/assets/assets_generator.rb +0 -1
- data/lib/rails/generators/rails/benchmark/USAGE +19 -0
- data/lib/rails/generators/rails/benchmark/benchmark_generator.rb +29 -0
- data/lib/rails/generators/rails/benchmark/templates/benchmark.rb.tt +15 -0
- data/lib/rails/generators/rails/controller/USAGE +2 -2
- data/lib/rails/generators/rails/controller/controller_generator.rb +10 -39
- data/lib/rails/generators/rails/credentials/credentials_generator.rb +6 -7
- data/lib/rails/generators/rails/db/system/change/change_generator.rb +65 -0
- data/lib/rails/generators/rails/encrypted_file/encrypted_file_generator.rb +10 -7
- data/lib/rails/generators/rails/encryption_key_file/encryption_key_file_generator.rb +1 -0
- data/lib/rails/generators/rails/generator/USAGE +2 -2
- data/lib/rails/generators/rails/generator/generator_generator.rb +0 -1
- data/lib/rails/generators/rails/generator/templates/USAGE.tt +1 -1
- data/lib/rails/generators/rails/helper/USAGE +2 -3
- data/lib/rails/generators/rails/helper/helper_generator.rb +5 -0
- data/lib/rails/generators/rails/integration_test/USAGE +2 -2
- data/lib/rails/generators/rails/migration/USAGE +4 -4
- data/lib/rails/generators/rails/model/USAGE +15 -16
- data/lib/rails/generators/rails/plugin/plugin_generator.rb +32 -56
- data/lib/rails/generators/rails/plugin/templates/%name%.gemspec.tt +18 -18
- data/lib/rails/generators/rails/plugin/templates/Gemfile.tt +3 -10
- data/lib/rails/generators/rails/plugin/templates/Rakefile.tt +4 -18
- data/lib/rails/generators/rails/plugin/templates/app/controllers/%namespaced_name%/application_controller.rb.tt +1 -2
- data/lib/rails/generators/rails/plugin/templates/app/helpers/%namespaced_name%/application_helper.rb.tt +1 -1
- data/lib/rails/generators/rails/plugin/templates/app/jobs/%namespaced_name%/application_job.rb.tt +1 -1
- data/lib/rails/generators/rails/plugin/templates/app/mailers/%namespaced_name%/application_mailer.rb.tt +1 -1
- data/lib/rails/generators/rails/plugin/templates/app/models/%namespaced_name%/application_record.rb.tt +1 -1
- data/lib/rails/generators/rails/plugin/templates/bin/rails.tt +3 -3
- data/lib/rails/generators/rails/plugin/templates/gitignore.tt +14 -11
- data/lib/rails/generators/rails/plugin/templates/lib/%namespaced_name%/engine.rb.tt +1 -1
- data/lib/rails/generators/rails/plugin/templates/lib/%namespaced_name%/railtie.rb.tt +1 -1
- data/lib/rails/generators/rails/plugin/templates/lib/%namespaced_name%.rb.tt +1 -0
- data/lib/rails/generators/rails/plugin/templates/rails/boot.rb.tt +1 -1
- data/lib/rails/generators/rails/plugin/templates/test/%namespaced_name%_test.rb.tt +4 -4
- data/lib/rails/generators/rails/plugin/templates/test/integration/navigation_test.rb.tt +1 -1
- data/lib/rails/generators/rails/plugin/templates/test/test_helper.rb.tt +0 -4
- data/lib/rails/generators/rails/resource/USAGE +4 -4
- data/lib/rails/generators/rails/resource_route/resource_route_generator.rb +2 -27
- data/lib/rails/generators/rails/scaffold/USAGE +5 -5
- data/lib/rails/generators/rails/scaffold_controller/USAGE +2 -2
- data/lib/rails/generators/rails/scaffold_controller/scaffold_controller_generator.rb +19 -0
- data/lib/rails/generators/rails/scaffold_controller/templates/api_controller.rb.tt +2 -2
- data/lib/rails/generators/rails/scaffold_controller/templates/controller.rb.tt +2 -2
- data/lib/rails/generators/rails/system_test/USAGE +2 -2
- data/lib/rails/generators/rails/task/USAGE +3 -3
- data/lib/rails/generators/resource_helpers.rb +1 -6
- data/lib/rails/generators/test_case.rb +1 -1
- data/lib/rails/generators/test_unit/controller/controller_generator.rb +2 -0
- data/lib/rails/generators/test_unit/controller/templates/functional_test.rb.tt +3 -3
- data/lib/rails/generators/test_unit/generator/generator_generator.rb +0 -1
- data/lib/rails/generators/test_unit/generator/templates/generator_test.rb.tt +2 -2
- data/lib/rails/generators/test_unit/integration/integration_generator.rb +5 -0
- data/lib/rails/generators/test_unit/integration/templates/integration_test.rb.tt +1 -1
- data/lib/rails/generators/test_unit/job/job_generator.rb +5 -0
- data/lib/rails/generators/test_unit/job/templates/unit_test.rb.tt +1 -1
- data/lib/rails/generators/test_unit/mailer/mailer_generator.rb +1 -1
- data/lib/rails/generators/test_unit/mailer/templates/functional_test.rb.tt +1 -1
- data/lib/rails/generators/test_unit/model/templates/fixtures.yml.tt +3 -3
- data/lib/rails/generators/test_unit/model/templates/unit_test.rb.tt +1 -1
- data/lib/rails/generators/test_unit/plugin/templates/%file_name%_test.rb.tt +1 -1
- data/lib/rails/generators/test_unit/plugin/templates/test_helper.rb +2 -2
- data/lib/rails/generators/test_unit/scaffold/scaffold_generator.rb +12 -3
- data/lib/rails/generators/test_unit/scaffold/templates/api_functional_test.rb.tt +1 -1
- data/lib/rails/generators/test_unit/scaffold/templates/functional_test.rb.tt +1 -1
- data/lib/rails/generators/test_unit/scaffold/templates/system_test.rb.tt +10 -2
- data/lib/rails/generators/test_unit/system/system_generator.rb +5 -0
- data/lib/rails/generators/testing/assertions.rb +2 -2
- data/lib/rails/generators/testing/behaviour.rb +4 -2
- data/lib/rails/generators.rb +38 -24
- data/lib/rails/info.rb +4 -4
- data/lib/rails/info_controller.rb +2 -3
- data/lib/rails/mailers_controller.rb +10 -4
- data/lib/rails/paths.rb +26 -10
- data/lib/rails/rack/logger.rb +5 -6
- data/lib/rails/railtie/configurable.rb +0 -1
- data/lib/rails/railtie/configuration.rb +3 -3
- data/lib/rails/railtie.rb +33 -13
- data/lib/rails/ruby_version_check.rb +3 -3
- data/lib/rails/secrets.rb +0 -1
- data/lib/rails/source_annotation_extractor.rb +124 -117
- data/lib/rails/tasks/engine.rake +1 -4
- data/lib/rails/tasks/framework.rake +13 -3
- data/lib/rails/tasks/log.rake +0 -1
- data/lib/rails/tasks/misc.rake +1 -1
- data/lib/rails/tasks/statistics.rake +5 -1
- data/lib/rails/tasks/yarn.rake +14 -1
- data/lib/rails/tasks/zeitwerk.rake +69 -0
- data/lib/rails/tasks.rb +1 -4
- data/lib/rails/templates/rails/mailers/email.html.erb +11 -7
- data/lib/rails/templates/rails/welcome/index.html.erb +3 -3
- data/lib/rails/test_help.rb +11 -9
- data/lib/rails/test_unit/reporter.rb +3 -2
- data/lib/rails/test_unit/runner.rb +25 -8
- data/lib/rails/test_unit/testing.rake +7 -1
- data/lib/rails.rb +10 -8
- metadata +45 -39
- data/lib/rails/generators/js/assets/assets_generator.rb +0 -15
- data/lib/rails/generators/js/assets/templates/javascript.js +0 -2
- data/lib/rails/generators/rails/app/templates/app/assets/javascripts/application.js.tt +0 -22
- data/lib/rails/generators/rails/app/templates/app/assets/javascripts/cable.js.tt +0 -13
- data/lib/rails/generators/rails/app/templates/bin/bundle.tt +0 -2
- data/lib/rails/generators/rails/app/templates/bin/update.tt +0 -34
- data/lib/rails/generators/rails/app/templates/config/databases/frontbase.yml.tt +0 -50
- data/lib/rails/generators/rails/app/templates/config/databases/ibm_db.yml.tt +0 -86
- data/lib/rails/generators/rails/app/templates/config/initializers/new_framework_defaults_5_2.rb.tt +0 -35
- data/lib/rails/generators/rails/assets/templates/javascript.js +0 -2
- data/lib/rails/generators/rails/plugin/templates/rails/application.rb.tt +0 -23
- data/lib/rails/tasks/annotations.rake +0 -22
- data/lib/rails/tasks/dev.rake +0 -10
- data/lib/rails/tasks/initializers.rake +0 -8
- data/lib/rails/tasks/routes.rake +0 -31
@@ -5,6 +5,19 @@ require "rails/test_unit/reporter"
|
|
5
5
|
require "rails/test_unit/runner"
|
6
6
|
|
7
7
|
module Minitest
|
8
|
+
class BacktraceFilterWithFallback
|
9
|
+
def initialize(preferred, fallback)
|
10
|
+
@preferred = preferred
|
11
|
+
@fallback = fallback
|
12
|
+
end
|
13
|
+
|
14
|
+
def filter(backtrace)
|
15
|
+
filtered = @preferred.filter(backtrace)
|
16
|
+
filtered = @fallback.filter(backtrace) if filtered.empty?
|
17
|
+
filtered
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
8
21
|
class SuppressedSummaryReporter < SummaryReporter
|
9
22
|
# Disable extra failure output after a run if output is inline.
|
10
23
|
def aggregated_results(*)
|
@@ -13,7 +26,7 @@ module Minitest
|
|
13
26
|
end
|
14
27
|
|
15
28
|
def self.plugin_rails_options(opts, options)
|
16
|
-
Rails::TestUnit::Runner.attach_before_load_options(opts)
|
29
|
+
::Rails::TestUnit::Runner.attach_before_load_options(opts)
|
17
30
|
|
18
31
|
opts.on("-b", "--backtrace", "Show the complete backtrace") do
|
19
32
|
options[:full_backtrace] = true
|
@@ -40,24 +53,22 @@ module Minitest
|
|
40
53
|
def self.plugin_rails_init(options)
|
41
54
|
unless options[:full_backtrace] || ENV["BACKTRACE"]
|
42
55
|
# Plugin can run without Rails loaded, check before filtering.
|
43
|
-
|
56
|
+
if ::Rails.respond_to?(:backtrace_cleaner)
|
57
|
+
Minitest.backtrace_filter = BacktraceFilterWithFallback.new(::Rails.backtrace_cleaner, Minitest.backtrace_filter)
|
58
|
+
end
|
44
59
|
end
|
45
60
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
return unless minitest_reporter.kind_of?(Minitest::CompositeReporter)
|
61
|
+
# Suppress summary reports when outputting inline rerun snippets.
|
62
|
+
if reporter.reporters.reject! { |reporter| reporter.kind_of?(SummaryReporter) }
|
63
|
+
reporter << SuppressedSummaryReporter.new(options[:io], options)
|
64
|
+
end
|
51
65
|
|
52
66
|
# Replace progress reporter for colors.
|
53
|
-
if
|
54
|
-
|
55
|
-
end
|
56
|
-
if minitest_reporter.reporters.reject! { |reporter| reporter.kind_of?(ProgressReporter) } != nil
|
57
|
-
minitest_reporter << ::Rails::TestUnitReporter.new(options[:io], options)
|
67
|
+
if reporter.reporters.reject! { |reporter| reporter.kind_of?(ProgressReporter) }
|
68
|
+
reporter << ::Rails::TestUnitReporter.new(options[:io], options)
|
58
69
|
end
|
59
70
|
end
|
60
71
|
|
61
|
-
#
|
72
|
+
# Backwards compatibility with Rails 5.0 generated plugin test scripts
|
62
73
|
mattr_reader :run_via, default: {}
|
63
74
|
end
|
data/lib/rails/all.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
# rubocop:disable Style/RedundantBegin
|
4
|
+
|
3
5
|
require "rails"
|
4
6
|
|
5
7
|
%w(
|
@@ -10,6 +12,8 @@ require "rails"
|
|
10
12
|
action_mailer/railtie
|
11
13
|
active_job/railtie
|
12
14
|
action_cable/engine
|
15
|
+
action_mailbox/engine
|
16
|
+
action_text/engine
|
13
17
|
rails/test_unit/railtie
|
14
18
|
sprockets/railtie
|
15
19
|
).each do |railtie|
|
data/lib/rails/api/generator.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require "sdoc"
|
4
|
+
require "active_support/core_ext/array/extract"
|
4
5
|
|
5
6
|
class RDoc::Generator::API < RDoc::Generator::SDoc # :nodoc:
|
6
7
|
RDoc::RDoc.add_generator self
|
@@ -11,7 +12,7 @@ class RDoc::Generator::API < RDoc::Generator::SDoc # :nodoc:
|
|
11
12
|
# since they aren't nested under a definition of the `ActiveStorage` module.
|
12
13
|
if visited.empty?
|
13
14
|
classes = classes.reject { |klass| active_storage?(klass) }
|
14
|
-
core_exts
|
15
|
+
core_exts = classes.extract! { |klass| core_extension?(klass) }
|
15
16
|
|
16
17
|
super.unshift([ "Core extensions", "", "", build_core_ext_subtree(core_exts, visited) ])
|
17
18
|
else
|
data/lib/rails/api/task.rb
CHANGED
@@ -18,6 +18,7 @@ module Rails
|
|
18
18
|
include: %w(
|
19
19
|
README.rdoc
|
20
20
|
lib/active_record/**/*.rb
|
21
|
+
lib/arel.rb
|
21
22
|
)
|
22
23
|
},
|
23
24
|
|
@@ -74,6 +75,22 @@ module Rails
|
|
74
75
|
)
|
75
76
|
},
|
76
77
|
|
78
|
+
"actionmailbox" => {
|
79
|
+
include: %w(
|
80
|
+
README.md
|
81
|
+
app/**/action_mailbox/**/*.rb
|
82
|
+
lib/action_mailbox/**/*.rb
|
83
|
+
)
|
84
|
+
},
|
85
|
+
|
86
|
+
"actiontext" => {
|
87
|
+
include: %w(
|
88
|
+
README.md
|
89
|
+
app/**/action_text/**/*.rb
|
90
|
+
lib/action_text/**/*.rb
|
91
|
+
)
|
92
|
+
},
|
93
|
+
|
77
94
|
"railties" => {
|
78
95
|
include: %w(
|
79
96
|
README.rdoc
|
data/lib/rails/app_loader.rb
CHANGED
@@ -23,7 +23,7 @@ control:
|
|
23
23
|
# too that you may or may not want (like yarn)
|
24
24
|
|
25
25
|
If you already have Rails binstubs in source control, you might be
|
26
|
-
|
26
|
+
inadvertently overwriting them during deployment by using bundle install
|
27
27
|
with the --binstubs option.
|
28
28
|
|
29
29
|
If your application was created prior to Rails 4, here's how to upgrade:
|
@@ -49,7 +49,7 @@ EOS
|
|
49
49
|
if exe = find_executable
|
50
50
|
contents = File.read(exe)
|
51
51
|
|
52
|
-
if
|
52
|
+
if /(APP|ENGINE)_PATH/.match?(contents)
|
53
53
|
exec RUBY, exe, *ARGV
|
54
54
|
break # non reachable, hack to be able to stub exec in the test suite
|
55
55
|
elsif exe.end_with?("bin/rails") && contents.include?("This file was generated by Bundler")
|
data/lib/rails/app_updater.rb
CHANGED
@@ -21,12 +21,15 @@ module Rails
|
|
21
21
|
private
|
22
22
|
def generator_options
|
23
23
|
options = { api: !!Rails.application.config.api_only, update: true }
|
24
|
+
options[:skip_javascript] = !File.exist?(Rails.root.join("bin", "yarn"))
|
24
25
|
options[:skip_active_record] = !defined?(ActiveRecord::Railtie)
|
25
|
-
options[:skip_active_storage] = !defined?(ActiveRecord::Railtie)
|
26
|
+
options[:skip_active_storage] = !defined?(ActiveStorage::Engine) || !defined?(ActiveRecord::Railtie)
|
26
27
|
options[:skip_action_mailer] = !defined?(ActionMailer::Railtie)
|
27
28
|
options[:skip_action_cable] = !defined?(ActionCable::Engine)
|
28
29
|
options[:skip_sprockets] = !defined?(Sprockets::Railtie)
|
29
30
|
options[:skip_puma] = !defined?(Puma)
|
31
|
+
options[:skip_bootsnap] = !defined?(Bootsnap)
|
32
|
+
options[:skip_spring] = !defined?(Spring)
|
30
33
|
options
|
31
34
|
end
|
32
35
|
end
|
@@ -19,14 +19,14 @@ module Rails
|
|
19
19
|
|
20
20
|
initializer :set_eager_load, group: :all do
|
21
21
|
if config.eager_load.nil?
|
22
|
-
warn
|
23
|
-
config.eager_load is set to nil. Please update your config/environments/*.rb files accordingly:
|
22
|
+
warn <<~INFO
|
23
|
+
config.eager_load is set to nil. Please update your config/environments/*.rb files accordingly:
|
24
24
|
|
25
|
-
|
26
|
-
|
27
|
-
|
25
|
+
* development - set it to false
|
26
|
+
* test - set it to false (unless you use a tool that preloads your test environment)
|
27
|
+
* production - set it to true
|
28
28
|
|
29
|
-
INFO
|
29
|
+
INFO
|
30
30
|
config.eager_load = config.cache_classes
|
31
31
|
end
|
32
32
|
end
|
@@ -34,20 +34,12 @@ INFO
|
|
34
34
|
# Initialize the logger early in the stack in case we need to log some deprecation.
|
35
35
|
initializer :initialize_logger, group: :all do
|
36
36
|
Rails.logger ||= config.logger || begin
|
37
|
-
|
38
|
-
unless File.exist? File.dirname path
|
39
|
-
FileUtils.mkdir_p File.dirname path
|
40
|
-
end
|
41
|
-
|
42
|
-
f = File.open path, "a"
|
43
|
-
f.binmode
|
44
|
-
f.sync = config.autoflush_log # if true make sure every write flushes
|
45
|
-
|
46
|
-
logger = ActiveSupport::Logger.new f
|
37
|
+
logger = ActiveSupport::Logger.new(config.default_log_file)
|
47
38
|
logger.formatter = config.log_formatter
|
48
39
|
logger = ActiveSupport::TaggedLogging.new(logger)
|
49
40
|
logger
|
50
41
|
rescue StandardError
|
42
|
+
path = config.paths["log"].first
|
51
43
|
logger = ActiveSupport::TaggedLogging.new(ActiveSupport::Logger.new(STDERR))
|
52
44
|
logger.level = ActiveSupport::Logger::WARN
|
53
45
|
logger.warn(
|
@@ -64,7 +56,7 @@ INFO
|
|
64
56
|
# Initialize cache early in the stack so railties can make use of it.
|
65
57
|
initializer :initialize_cache, group: :all do
|
66
58
|
unless Rails.cache
|
67
|
-
Rails.cache = ActiveSupport::Cache.lookup_store(config.cache_store)
|
59
|
+
Rails.cache = ActiveSupport::Cache.lookup_store(*config.cache_store)
|
68
60
|
|
69
61
|
if Rails.cache.respond_to?(:middleware)
|
70
62
|
config.middleware.insert_before(::Rack::Runtime, Rails.cache.middleware)
|
@@ -1,7 +1,10 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require "ipaddr"
|
3
4
|
require "active_support/core_ext/kernel/reporting"
|
5
|
+
require "active_support/core_ext/symbol/starts_ends_with"
|
4
6
|
require "active_support/file_update_checker"
|
7
|
+
require "active_support/configuration_file"
|
5
8
|
require "rails/engine/configuration"
|
6
9
|
require "rails/source_annotation_extractor"
|
7
10
|
|
@@ -11,15 +14,17 @@ module Rails
|
|
11
14
|
attr_accessor :allow_concurrency, :asset_host, :autoflush_log,
|
12
15
|
:cache_classes, :cache_store, :consider_all_requests_local, :console,
|
13
16
|
:eager_load, :exceptions_app, :file_watcher, :filter_parameters,
|
14
|
-
:force_ssl, :helpers_paths, :
|
15
|
-
:railties_order, :relative_url_root, :secret_key_base,
|
17
|
+
:force_ssl, :helpers_paths, :hosts, :host_authorization, :logger, :log_formatter,
|
18
|
+
:log_tags, :railties_order, :relative_url_root, :secret_key_base,
|
16
19
|
:ssl_options, :public_file_server,
|
17
20
|
:session_options, :time_zone, :reload_classes_only_on_change,
|
18
21
|
:beginning_of_week, :filter_redirect, :x, :enable_dependency_loading,
|
19
22
|
:read_encrypted_secrets, :log_level, :content_security_policy_report_only,
|
20
|
-
:content_security_policy_nonce_generator, :
|
23
|
+
:content_security_policy_nonce_generator, :content_security_policy_nonce_directives,
|
24
|
+
:require_master_key, :credentials, :disable_sandbox, :add_autoload_paths_to_load_path,
|
25
|
+
:rake_eager_load
|
21
26
|
|
22
|
-
attr_reader :encoding, :api_only, :loaded_config_version
|
27
|
+
attr_reader :encoding, :api_only, :loaded_config_version, :autoloader
|
23
28
|
|
24
29
|
def initialize(*)
|
25
30
|
super
|
@@ -29,6 +34,8 @@ module Rails
|
|
29
34
|
@filter_parameters = []
|
30
35
|
@filter_redirect = []
|
31
36
|
@helpers_paths = []
|
37
|
+
@hosts = Array(([".localhost", IPAddr.new("0.0.0.0/0"), IPAddr.new("::/0")] if Rails.env.development?))
|
38
|
+
@host_authorization = {}
|
32
39
|
@public_file_server = ActiveSupport::OrderedOptions.new
|
33
40
|
@public_file_server.enabled = true
|
34
41
|
@public_file_server.index_name = "index"
|
@@ -48,7 +55,6 @@ module Rails
|
|
48
55
|
@autoflush_log = true
|
49
56
|
@log_formatter = ActiveSupport::Logger::SimpleFormatter.new
|
50
57
|
@eager_load = nil
|
51
|
-
@secret_token = nil
|
52
58
|
@secret_key_base = nil
|
53
59
|
@api_only = false
|
54
60
|
@debug_exception_response_format = nil
|
@@ -58,10 +64,20 @@ module Rails
|
|
58
64
|
@content_security_policy = nil
|
59
65
|
@content_security_policy_report_only = false
|
60
66
|
@content_security_policy_nonce_generator = nil
|
67
|
+
@content_security_policy_nonce_directives = nil
|
61
68
|
@require_master_key = false
|
62
69
|
@loaded_config_version = nil
|
70
|
+
@credentials = ActiveSupport::OrderedOptions.new
|
71
|
+
@credentials.content_path = default_credentials_content_path
|
72
|
+
@credentials.key_path = default_credentials_key_path
|
73
|
+
@autoloader = :classic
|
74
|
+
@disable_sandbox = false
|
75
|
+
@add_autoload_paths_to_load_path = true
|
76
|
+
@permissions_policy = nil
|
77
|
+
@rake_eager_load = false
|
63
78
|
end
|
64
79
|
|
80
|
+
# Loads default configurations. See {the result of the method for each version}[https://guides.rubyonrails.org/configuring.html#results-of-config-load-defaults].
|
65
81
|
def load_defaults(target_version)
|
66
82
|
case target_version.to_s
|
67
83
|
when "5.0"
|
@@ -92,10 +108,6 @@ module Rails
|
|
92
108
|
|
93
109
|
if respond_to?(:active_record)
|
94
110
|
active_record.cache_versioning = true
|
95
|
-
# Remove the temporary load hook from SQLite3Adapter when this is removed
|
96
|
-
ActiveSupport.on_load(:active_record_sqlite3adapter) do
|
97
|
-
ActiveRecord::ConnectionAdapters::SQLite3Adapter.represent_boolean_as_integer = true
|
98
|
-
end
|
99
111
|
end
|
100
112
|
|
101
113
|
if respond_to?(:action_dispatch)
|
@@ -104,7 +116,7 @@ module Rails
|
|
104
116
|
|
105
117
|
if respond_to?(:active_support)
|
106
118
|
active_support.use_authenticated_message_encryption = true
|
107
|
-
active_support.
|
119
|
+
active_support.hash_digest_class = ::Digest::SHA1
|
108
120
|
end
|
109
121
|
|
110
122
|
if respond_to?(:action_controller)
|
@@ -114,6 +126,80 @@ module Rails
|
|
114
126
|
if respond_to?(:action_view)
|
115
127
|
action_view.form_with_generates_ids = true
|
116
128
|
end
|
129
|
+
when "6.0"
|
130
|
+
load_defaults "5.2"
|
131
|
+
|
132
|
+
self.autoloader = :zeitwerk if RUBY_ENGINE == "ruby"
|
133
|
+
|
134
|
+
if respond_to?(:action_view)
|
135
|
+
action_view.default_enforce_utf8 = false
|
136
|
+
end
|
137
|
+
|
138
|
+
if respond_to?(:action_dispatch)
|
139
|
+
action_dispatch.use_cookies_with_metadata = true
|
140
|
+
end
|
141
|
+
|
142
|
+
if respond_to?(:action_mailer)
|
143
|
+
action_mailer.delivery_job = "ActionMailer::MailDeliveryJob"
|
144
|
+
end
|
145
|
+
|
146
|
+
if respond_to?(:active_storage)
|
147
|
+
active_storage.queues.analysis = :active_storage_analysis
|
148
|
+
active_storage.queues.purge = :active_storage_purge
|
149
|
+
|
150
|
+
active_storage.replace_on_assign_to_many = true
|
151
|
+
end
|
152
|
+
|
153
|
+
if respond_to?(:active_record)
|
154
|
+
active_record.collection_cache_versioning = true
|
155
|
+
end
|
156
|
+
when "6.1"
|
157
|
+
load_defaults "6.0"
|
158
|
+
|
159
|
+
self.autoloader = :zeitwerk if %w[ruby truffleruby].include?(RUBY_ENGINE)
|
160
|
+
|
161
|
+
if respond_to?(:active_record)
|
162
|
+
active_record.has_many_inversing = true
|
163
|
+
active_record.legacy_connection_handling = false
|
164
|
+
end
|
165
|
+
|
166
|
+
if respond_to?(:active_storage)
|
167
|
+
active_storage.track_variants = true
|
168
|
+
end
|
169
|
+
|
170
|
+
if respond_to?(:active_job)
|
171
|
+
active_job.retry_jitter = 0.15
|
172
|
+
active_job.skip_after_callbacks_if_terminated = true
|
173
|
+
end
|
174
|
+
|
175
|
+
if respond_to?(:action_dispatch)
|
176
|
+
action_dispatch.cookies_same_site_protection = :lax
|
177
|
+
action_dispatch.ssl_default_redirect_status = 308
|
178
|
+
end
|
179
|
+
|
180
|
+
if respond_to?(:action_controller)
|
181
|
+
action_controller.urlsafe_csrf_tokens = true
|
182
|
+
end
|
183
|
+
|
184
|
+
if respond_to?(:action_view)
|
185
|
+
action_view.form_with_generates_remote_forms = false
|
186
|
+
end
|
187
|
+
|
188
|
+
if respond_to?(:active_storage)
|
189
|
+
active_storage.queues.analysis = nil
|
190
|
+
active_storage.queues.purge = nil
|
191
|
+
end
|
192
|
+
|
193
|
+
if respond_to?(:action_mailbox)
|
194
|
+
action_mailbox.queues.incineration = nil
|
195
|
+
action_mailbox.queues.routing = nil
|
196
|
+
end
|
197
|
+
|
198
|
+
if respond_to?(:action_mailer)
|
199
|
+
action_mailer.deliver_later_queue_name = nil
|
200
|
+
end
|
201
|
+
|
202
|
+
ActiveSupport.utc_to_local_returns_utc_offset_times = true
|
117
203
|
else
|
118
204
|
raise "Unknown version #{target_version.to_s.inspect}"
|
119
205
|
end
|
@@ -140,9 +226,7 @@ module Rails
|
|
140
226
|
@debug_exception_response_format || :default
|
141
227
|
end
|
142
228
|
|
143
|
-
|
144
|
-
@debug_exception_response_format = value
|
145
|
-
end
|
229
|
+
attr_writer :debug_exception_response_format
|
146
230
|
|
147
231
|
def paths
|
148
232
|
@paths ||= begin
|
@@ -160,18 +244,35 @@ module Rails
|
|
160
244
|
end
|
161
245
|
end
|
162
246
|
|
247
|
+
# Load the database YAML without evaluating ERB. This allows us to
|
248
|
+
# create the rake tasks for multiple databases without filling in the
|
249
|
+
# configuration values or loading the environment. Do not use this
|
250
|
+
# method.
|
251
|
+
#
|
252
|
+
# This uses a DummyERB custom compiler so YAML can ignore the ERB
|
253
|
+
# tags and load the database.yml for the rake tasks.
|
254
|
+
def load_database_yaml # :nodoc:
|
255
|
+
if path = paths["config/database"].existent.first
|
256
|
+
require "rails/application/dummy_erb_compiler"
|
257
|
+
|
258
|
+
yaml = Pathname.new(path)
|
259
|
+
erb = DummyERB.new(yaml.read)
|
260
|
+
|
261
|
+
YAML.load(erb.result) || {}
|
262
|
+
else
|
263
|
+
{}
|
264
|
+
end
|
265
|
+
end
|
266
|
+
|
163
267
|
# Loads and returns the entire raw configuration of database from
|
164
268
|
# values stored in <tt>config/database.yml</tt>.
|
165
269
|
def database_configuration
|
166
270
|
path = paths["config/database"].existent.first
|
167
271
|
yaml = Pathname.new(path) if path
|
168
272
|
|
169
|
-
config = if yaml
|
170
|
-
|
171
|
-
|
172
|
-
loaded_yaml = YAML.load(ERB.new(yaml.read).result) || {}
|
173
|
-
shared = loaded_yaml.delete("shared")
|
174
|
-
if shared
|
273
|
+
config = if yaml&.exist?
|
274
|
+
loaded_yaml = ActiveSupport::ConfigurationFile.parse(yaml)
|
275
|
+
if (shared = loaded_yaml.delete("shared"))
|
175
276
|
loaded_yaml.each do |_k, values|
|
176
277
|
values.reverse_merge!(shared)
|
177
278
|
end
|
@@ -186,12 +287,8 @@ module Rails
|
|
186
287
|
end
|
187
288
|
|
188
289
|
config
|
189
|
-
rescue Psych::SyntaxError => e
|
190
|
-
raise "YAML syntax error occurred while parsing #{paths["config/database"].first}. " \
|
191
|
-
"Please note that YAML must be consistently indented using spaces. Tabs are not allowed. " \
|
192
|
-
"Error: #{e.message}"
|
193
290
|
rescue => e
|
194
|
-
raise e, "Cannot load
|
291
|
+
raise e, "Cannot load database configuration:\n#{e.message}", e.backtrace
|
195
292
|
end
|
196
293
|
|
197
294
|
def colorize_logging
|
@@ -235,7 +332,7 @@ module Rails
|
|
235
332
|
end
|
236
333
|
|
237
334
|
def annotations
|
238
|
-
SourceAnnotationExtractor::Annotation
|
335
|
+
Rails::SourceAnnotationExtractor::Annotation
|
239
336
|
end
|
240
337
|
|
241
338
|
def content_security_policy(&block)
|
@@ -246,14 +343,46 @@ module Rails
|
|
246
343
|
end
|
247
344
|
end
|
248
345
|
|
346
|
+
def permissions_policy(&block)
|
347
|
+
if block_given?
|
348
|
+
@permissions_policy = ActionDispatch::PermissionsPolicy.new(&block)
|
349
|
+
else
|
350
|
+
@permissions_policy
|
351
|
+
end
|
352
|
+
end
|
353
|
+
|
354
|
+
def autoloader=(autoloader)
|
355
|
+
case autoloader
|
356
|
+
when :classic
|
357
|
+
@autoloader = autoloader
|
358
|
+
when :zeitwerk
|
359
|
+
require "zeitwerk"
|
360
|
+
@autoloader = autoloader
|
361
|
+
else
|
362
|
+
raise ArgumentError, "config.autoloader may be :classic or :zeitwerk, got #{autoloader.inspect} instead"
|
363
|
+
end
|
364
|
+
end
|
365
|
+
|
366
|
+
def default_log_file
|
367
|
+
path = paths["log"].first
|
368
|
+
unless File.exist? File.dirname path
|
369
|
+
FileUtils.mkdir_p File.dirname path
|
370
|
+
end
|
371
|
+
|
372
|
+
f = File.open path, "a"
|
373
|
+
f.binmode
|
374
|
+
f.sync = autoflush_log # if true make sure every write flushes
|
375
|
+
f
|
376
|
+
end
|
377
|
+
|
249
378
|
class Custom #:nodoc:
|
250
379
|
def initialize
|
251
380
|
@configurations = Hash.new
|
252
381
|
end
|
253
382
|
|
254
383
|
def method_missing(method, *args)
|
255
|
-
if method
|
256
|
-
@configurations[
|
384
|
+
if method.end_with?("=")
|
385
|
+
@configurations[:"#{method[0..-2]}"] = args.first
|
257
386
|
else
|
258
387
|
@configurations.fetch(method) {
|
259
388
|
@configurations[method] = ActiveSupport::OrderedOptions.new
|
@@ -265,6 +394,27 @@ module Rails
|
|
265
394
|
true
|
266
395
|
end
|
267
396
|
end
|
397
|
+
|
398
|
+
private
|
399
|
+
def default_credentials_content_path
|
400
|
+
if credentials_available_for_current_env?
|
401
|
+
root.join("config", "credentials", "#{Rails.env}.yml.enc")
|
402
|
+
else
|
403
|
+
root.join("config", "credentials.yml.enc")
|
404
|
+
end
|
405
|
+
end
|
406
|
+
|
407
|
+
def default_credentials_key_path
|
408
|
+
if credentials_available_for_current_env?
|
409
|
+
root.join("config", "credentials", "#{Rails.env}.key")
|
410
|
+
else
|
411
|
+
root.join("config", "master.key")
|
412
|
+
end
|
413
|
+
end
|
414
|
+
|
415
|
+
def credentials_available_for_current_env?
|
416
|
+
File.exist?(root.join("config", "credentials", "#{Rails.env}.yml.enc"))
|
417
|
+
end
|
268
418
|
end
|
269
419
|
end
|
270
420
|
end
|
@@ -13,8 +13,11 @@ module Rails
|
|
13
13
|
|
14
14
|
def build_stack
|
15
15
|
ActionDispatch::MiddlewareStack.new do |middleware|
|
16
|
+
middleware.use ::ActionDispatch::HostAuthorization, config.hosts, config.action_dispatch.hosts_response_app, **config.host_authorization
|
17
|
+
|
16
18
|
if config.force_ssl
|
17
|
-
middleware.use ::ActionDispatch::SSL, config.ssl_options
|
19
|
+
middleware.use ::ActionDispatch::SSL, **config.ssl_options,
|
20
|
+
ssl_default_redirect_status: config.action_dispatch.ssl_default_redirect_status
|
18
21
|
end
|
19
22
|
|
20
23
|
middleware.use ::Rack::Sendfile, config.action_dispatch.x_sendfile_header
|
@@ -41,12 +44,13 @@ module Rails
|
|
41
44
|
|
42
45
|
middleware.use ::Rack::Runtime
|
43
46
|
middleware.use ::Rack::MethodOverride unless config.api_only
|
44
|
-
middleware.use ::ActionDispatch::RequestId
|
47
|
+
middleware.use ::ActionDispatch::RequestId, header: config.action_dispatch.request_id_header
|
45
48
|
middleware.use ::ActionDispatch::RemoteIp, config.action_dispatch.ip_spoofing_check, config.action_dispatch.trusted_proxies
|
46
49
|
|
47
50
|
middleware.use ::Rails::Rack::Logger, config.log_tags
|
48
51
|
middleware.use ::ActionDispatch::ShowExceptions, show_exceptions_app
|
49
52
|
middleware.use ::ActionDispatch::DebugExceptions, app, config.debug_exception_response_format
|
53
|
+
middleware.use ::ActionDispatch::ActionableExceptions
|
50
54
|
|
51
55
|
unless config.cache_classes
|
52
56
|
middleware.use ::ActionDispatch::Reloader, app.reloader
|
@@ -65,6 +69,7 @@ module Rails
|
|
65
69
|
|
66
70
|
unless config.api_only
|
67
71
|
middleware.use ::ActionDispatch::ContentSecurityPolicy::Middleware
|
72
|
+
middleware.use ::ActionDispatch::PermissionsPolicy::Middleware
|
68
73
|
end
|
69
74
|
|
70
75
|
middleware.use ::Rack::Head
|
@@ -76,7 +81,6 @@ module Rails
|
|
76
81
|
end
|
77
82
|
|
78
83
|
private
|
79
|
-
|
80
84
|
def load_rack_cache
|
81
85
|
rack_cache = config.action_dispatch.rack_cache
|
82
86
|
return unless rack_cache
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# These classes are used to strip out the ERB configuration
|
4
|
+
# values so we can evaluate the database.yml without evaluating
|
5
|
+
# the ERB values.
|
6
|
+
class DummyERB < ERB # :nodoc:
|
7
|
+
def make_compiler(trim_mode)
|
8
|
+
DummyCompiler.new trim_mode
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
class DummyCompiler < ERB::Compiler # :nodoc:
|
13
|
+
def compile_content(stag, out)
|
14
|
+
if stag == "<%="
|
15
|
+
out.push "_erbout << ''"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|