railties 6.0.6.1 → 6.1.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (160) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +225 -469
  3. data/MIT-LICENSE +1 -1
  4. data/RDOC_MAIN.rdoc +1 -1
  5. data/README.rdoc +1 -1
  6. data/lib/minitest/rails_plugin.rb +16 -1
  7. data/lib/rails/api/task.rb +1 -1
  8. data/lib/rails/application/bootstrap.rb +5 -5
  9. data/lib/rails/application/configuration.rb +53 -26
  10. data/lib/rails/application/default_middleware_stack.rb +5 -3
  11. data/lib/rails/application/finisher.rb +15 -2
  12. data/lib/rails/application/routes_reloader.rb +9 -2
  13. data/lib/rails/application.rb +45 -79
  14. data/lib/rails/backtrace_cleaner.rb +12 -7
  15. data/lib/rails/code_statistics.rb +3 -3
  16. data/lib/rails/code_statistics_calculator.rb +6 -6
  17. data/lib/rails/command/base.rb +1 -1
  18. data/lib/rails/command/behavior.rb +1 -1
  19. data/lib/rails/command/environment_argument.rb +1 -1
  20. data/lib/rails/command.rb +7 -1
  21. data/lib/rails/commands/credentials/USAGE +17 -2
  22. data/lib/rails/commands/credentials/credentials_command/diffing.rb +41 -0
  23. data/lib/rails/commands/credentials/credentials_command.rb +28 -4
  24. data/lib/rails/commands/db/system/change/change_command.rb +6 -1
  25. data/lib/rails/commands/dbconsole/dbconsole_command.rb +59 -57
  26. data/lib/rails/commands/encrypted/encrypted_command.rb +4 -4
  27. data/lib/rails/commands/generate/generate_command.rb +1 -1
  28. data/lib/rails/commands/notes/notes_command.rb +3 -13
  29. data/lib/rails/commands/rake/rake_command.rb +9 -8
  30. data/lib/rails/commands/secrets/USAGE +9 -3
  31. data/lib/rails/commands/server/server_command.rb +14 -41
  32. data/lib/rails/commands/test/test_command.rb +2 -2
  33. data/lib/rails/configuration.rb +40 -10
  34. data/lib/rails/engine/configuration.rb +1 -0
  35. data/lib/rails/engine/updater.rb +1 -1
  36. data/lib/rails/engine.rb +26 -15
  37. data/lib/rails/gem_version.rb +3 -3
  38. data/lib/rails/generators/actions/create_migration.rb +5 -0
  39. data/lib/rails/generators/actions.rb +48 -27
  40. data/lib/rails/generators/app_base.rb +32 -17
  41. data/lib/rails/generators/base.rb +14 -11
  42. data/lib/rails/generators/database.rb +3 -4
  43. data/lib/rails/generators/erb/scaffold/templates/_form.html.erb.tt +2 -2
  44. data/lib/rails/generators/generated_attribute.rb +3 -9
  45. data/lib/rails/generators/migration.rb +2 -1
  46. data/lib/rails/generators/model_helpers.rb +26 -2
  47. data/lib/rails/generators/named_base.rb +1 -1
  48. data/lib/rails/generators/rails/app/USAGE +2 -1
  49. data/lib/rails/generators/rails/app/app_generator.rb +89 -15
  50. data/lib/rails/generators/rails/app/templates/Gemfile.tt +10 -10
  51. data/lib/rails/generators/rails/app/templates/Rakefile.tt +1 -1
  52. data/lib/rails/generators/rails/app/templates/app/javascript/channels/consumer.js +1 -1
  53. data/lib/rails/generators/rails/app/templates/app/javascript/packs/application.js.tt +11 -4
  54. data/lib/rails/generators/rails/app/templates/app/views/layouts/application.html.erb.tt +2 -1
  55. data/lib/rails/generators/rails/app/templates/bin/rails.tt +2 -2
  56. data/lib/rails/generators/rails/app/templates/bin/rake.tt +2 -2
  57. data/lib/rails/generators/rails/app/templates/bin/setup.tt +4 -4
  58. data/lib/rails/generators/rails/app/templates/bin/spring.tt +7 -0
  59. data/lib/rails/generators/rails/app/templates/bin/yarn.tt +5 -7
  60. data/lib/rails/generators/rails/app/templates/config/application.rb.tt +7 -3
  61. data/lib/rails/generators/rails/app/templates/config/boot.rb.tt +8 -2
  62. data/lib/rails/generators/rails/app/templates/config/databases/jdbc.yml.tt +3 -4
  63. data/lib/rails/generators/rails/app/templates/config/databases/jdbcmysql.yml.tt +10 -9
  64. data/lib/rails/generators/rails/app/templates/config/databases/jdbcpostgresql.yml.tt +11 -10
  65. data/lib/rails/generators/rails/app/templates/config/databases/mysql.yml.tt +10 -9
  66. data/lib/rails/generators/rails/app/templates/config/databases/oracle.yml.tt +11 -10
  67. data/lib/rails/generators/rails/app/templates/config/databases/postgresql.yml.tt +11 -10
  68. data/lib/rails/generators/rails/app/templates/config/databases/sqlserver.yml.tt +10 -9
  69. data/lib/rails/generators/rails/app/templates/config/environment.rb.tt +1 -1
  70. data/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt +17 -3
  71. data/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt +14 -4
  72. data/lib/rails/generators/rails/app/templates/config/environments/test.rb.tt +12 -1
  73. data/lib/rails/generators/rails/app/templates/config/initializers/backtrace_silencers.rb.tt +4 -3
  74. data/lib/rails/generators/rails/app/templates/config/initializers/feature_policy.rb.tt +11 -0
  75. data/lib/rails/generators/rails/app/templates/config/initializers/filter_parameter_logging.rb.tt +3 -1
  76. data/lib/rails/generators/rails/app/templates/config/initializers/new_framework_defaults_6_1.rb.tt +45 -0
  77. data/lib/rails/generators/rails/app/templates/config/puma.rb.tt +1 -1
  78. data/lib/rails/generators/rails/app/templates/config.ru.tt +2 -1
  79. data/lib/rails/generators/rails/app/templates/db/seeds.rb.tt +1 -1
  80. data/lib/rails/generators/rails/app/templates/gitattributes.tt +14 -0
  81. data/lib/rails/generators/rails/app/templates/gitignore.tt +0 -1
  82. data/lib/rails/generators/rails/app/templates/package.json.tt +1 -1
  83. data/lib/rails/generators/rails/app/templates/test/test_helper.rb.tt +5 -5
  84. data/lib/rails/generators/rails/assets/USAGE +2 -3
  85. data/lib/rails/generators/rails/benchmark/USAGE +19 -0
  86. data/lib/rails/generators/rails/benchmark/benchmark_generator.rb +29 -0
  87. data/lib/rails/generators/rails/benchmark/templates/benchmark.rb.tt +15 -0
  88. data/lib/rails/generators/rails/controller/USAGE +2 -2
  89. data/lib/rails/generators/rails/controller/controller_generator.rb +2 -40
  90. data/lib/rails/generators/rails/credentials/credentials_generator.rb +1 -1
  91. data/lib/rails/generators/rails/generator/USAGE +2 -2
  92. data/lib/rails/generators/rails/generator/templates/USAGE.tt +1 -1
  93. data/lib/rails/generators/rails/helper/USAGE +2 -3
  94. data/lib/rails/generators/rails/integration_test/USAGE +2 -2
  95. data/lib/rails/generators/rails/migration/USAGE +4 -4
  96. data/lib/rails/generators/rails/model/USAGE +15 -16
  97. data/lib/rails/generators/rails/plugin/plugin_generator.rb +24 -23
  98. data/lib/rails/generators/rails/plugin/templates/%name%.gemspec.tt +10 -19
  99. data/lib/rails/generators/rails/plugin/templates/Gemfile.tt +3 -10
  100. data/lib/rails/generators/rails/plugin/templates/Rakefile.tt +4 -18
  101. data/lib/rails/generators/rails/plugin/templates/app/controllers/%namespaced_name%/application_controller.rb.tt +0 -1
  102. data/lib/rails/generators/rails/plugin/templates/bin/rails.tt +3 -3
  103. data/lib/rails/generators/rails/plugin/templates/gitignore.tt +13 -11
  104. data/lib/rails/generators/rails/plugin/templates/lib/%namespaced_name%.rb.tt +1 -0
  105. data/lib/rails/generators/rails/plugin/templates/rails/boot.rb.tt +1 -1
  106. data/lib/rails/generators/rails/plugin/templates/test/%namespaced_name%_test.rb.tt +4 -4
  107. data/lib/rails/generators/rails/plugin/templates/test/integration/navigation_test.rb.tt +1 -1
  108. data/lib/rails/generators/rails/plugin/templates/test/test_helper.rb.tt +0 -3
  109. data/lib/rails/generators/rails/resource/USAGE +4 -4
  110. data/lib/rails/generators/rails/resource_route/resource_route_generator.rb +2 -27
  111. data/lib/rails/generators/rails/scaffold/USAGE +5 -5
  112. data/lib/rails/generators/rails/scaffold_controller/USAGE +2 -2
  113. data/lib/rails/generators/rails/scaffold_controller/scaffold_controller_generator.rb +6 -0
  114. data/lib/rails/generators/rails/scaffold_controller/templates/api_controller.rb.tt +1 -1
  115. data/lib/rails/generators/rails/scaffold_controller/templates/controller.rb.tt +1 -1
  116. data/lib/rails/generators/rails/system_test/USAGE +2 -2
  117. data/lib/rails/generators/rails/task/USAGE +3 -3
  118. data/lib/rails/generators/test_case.rb +1 -1
  119. data/lib/rails/generators/test_unit/controller/controller_generator.rb +2 -0
  120. data/lib/rails/generators/test_unit/controller/templates/functional_test.rb.tt +3 -3
  121. data/lib/rails/generators/test_unit/generator/templates/generator_test.rb.tt +2 -2
  122. data/lib/rails/generators/test_unit/integration/templates/integration_test.rb.tt +1 -1
  123. data/lib/rails/generators/test_unit/job/templates/unit_test.rb.tt +1 -1
  124. data/lib/rails/generators/test_unit/mailer/templates/functional_test.rb.tt +1 -1
  125. data/lib/rails/generators/test_unit/model/templates/fixtures.yml.tt +1 -1
  126. data/lib/rails/generators/test_unit/model/templates/unit_test.rb.tt +1 -1
  127. data/lib/rails/generators/test_unit/plugin/templates/%file_name%_test.rb.tt +1 -1
  128. data/lib/rails/generators/test_unit/plugin/templates/test_helper.rb +2 -2
  129. data/lib/rails/generators/test_unit/scaffold/templates/api_functional_test.rb.tt +1 -1
  130. data/lib/rails/generators/test_unit/scaffold/templates/functional_test.rb.tt +1 -1
  131. data/lib/rails/generators/testing/assertions.rb +2 -2
  132. data/lib/rails/generators/testing/behaviour.rb +1 -1
  133. data/lib/rails/generators.rb +29 -15
  134. data/lib/rails/info.rb +1 -1
  135. data/lib/rails/info_controller.rb +1 -1
  136. data/lib/rails/mailers_controller.rb +1 -0
  137. data/lib/rails/paths.rb +14 -6
  138. data/lib/rails/railtie/configuration.rb +3 -2
  139. data/lib/rails/railtie.rb +28 -3
  140. data/lib/rails/source_annotation_extractor.rb +1 -15
  141. data/lib/rails/tasks/engine.rake +1 -4
  142. data/lib/rails/tasks/framework.rake +7 -1
  143. data/lib/rails/tasks/misc.rake +1 -1
  144. data/lib/rails/tasks/statistics.rake +1 -1
  145. data/lib/rails/tasks.rb +0 -4
  146. data/lib/rails/templates/rails/mailers/email.html.erb +1 -0
  147. data/lib/rails/templates/rails/welcome/index.html.erb +1 -1
  148. data/lib/rails/test_unit/reporter.rb +2 -1
  149. data/lib/rails/test_unit/runner.rb +12 -3
  150. data/lib/rails/test_unit/testing.rake +6 -0
  151. data/lib/rails.rb +5 -8
  152. metadata +29 -36
  153. data/lib/rails/generators/rails/app/templates/config/databases/frontbase.yml.tt +0 -50
  154. data/lib/rails/generators/rails/app/templates/config/databases/ibm_db.yml.tt +0 -86
  155. data/lib/rails/generators/rails/app/templates/config/initializers/new_framework_defaults_6_0.rb.tt +0 -45
  156. data/lib/rails/generators/rails/plugin/templates/rails/application.rb.tt +0 -23
  157. data/lib/rails/tasks/annotations.rake +0 -22
  158. data/lib/rails/tasks/dev.rake +0 -11
  159. data/lib/rails/tasks/initializers.rake +0 -9
  160. data/lib/rails/tasks/routes.rake +0 -9
data/MIT-LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2004-2019 David Heinemeier Hansson
1
+ Copyright (c) 2004-2020 David Heinemeier Hansson
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/RDOC_MAIN.rdoc CHANGED
@@ -68,7 +68,7 @@ and may also be used independently outside \Rails.
68
68
  3. Change directory to +myapp+ and start the web server:
69
69
 
70
70
  $ cd myapp
71
- $ rails server
71
+ $ bin/rails server
72
72
 
73
73
  Run with <tt>--help</tt> or <tt>-h</tt> for options.
74
74
 
data/README.rdoc CHANGED
@@ -17,7 +17,7 @@ The latest version of Railties can be installed with RubyGems:
17
17
 
18
18
  Source code can be downloaded as part of the Rails project on GitHub
19
19
 
20
- * https://github.com/rails/rails/tree/main/railties
20
+ * https://github.com/rails/rails/tree/master/railties
21
21
 
22
22
  == License
23
23
 
@@ -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(*)
@@ -40,7 +53,9 @@ 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
- Minitest.backtrace_filter = ::Rails.backtrace_cleaner if ::Rails.respond_to?(:backtrace_cleaner)
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
61
  # Suppress summary reports when outputting inline rerun snippets.
@@ -189,7 +189,7 @@ module Rails
189
189
 
190
190
  class EdgeTask < RepoTask
191
191
  def rails_version
192
- "main@#{`git rev-parse HEAD`[0, 7]}"
192
+ "master@#{`git rev-parse HEAD`[0, 7]}"
193
193
  end
194
194
  end
195
195
 
@@ -19,12 +19,12 @@ module Rails
19
19
 
20
20
  initializer :set_eager_load, group: :all do
21
21
  if config.eager_load.nil?
22
- warn <<-INFO
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
- * 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
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
29
  INFO
30
30
  config.eager_load = config.cache_classes
@@ -2,7 +2,9 @@
2
2
 
3
3
  require "ipaddr"
4
4
  require "active_support/core_ext/kernel/reporting"
5
+ require "active_support/core_ext/symbol/starts_ends_with"
5
6
  require "active_support/file_update_checker"
7
+ require "active_support/configuration_file"
6
8
  require "rails/engine/configuration"
7
9
  require "rails/source_annotation_extractor"
8
10
 
@@ -12,14 +14,15 @@ module Rails
12
14
  attr_accessor :allow_concurrency, :asset_host, :autoflush_log,
13
15
  :cache_classes, :cache_store, :consider_all_requests_local, :console,
14
16
  :eager_load, :exceptions_app, :file_watcher, :filter_parameters,
15
- :force_ssl, :helpers_paths, :hosts, :logger, :log_formatter, :log_tags,
16
- :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,
17
19
  :ssl_options, :public_file_server,
18
20
  :session_options, :time_zone, :reload_classes_only_on_change,
19
21
  :beginning_of_week, :filter_redirect, :x, :enable_dependency_loading,
20
22
  :read_encrypted_secrets, :log_level, :content_security_policy_report_only,
21
23
  :content_security_policy_nonce_generator, :content_security_policy_nonce_directives,
22
- :require_master_key, :credentials, :disable_sandbox, :add_autoload_paths_to_load_path
24
+ :require_master_key, :credentials, :disable_sandbox, :add_autoload_paths_to_load_path,
25
+ :rake_eager_load
23
26
 
24
27
  attr_reader :encoding, :api_only, :loaded_config_version, :autoloader
25
28
 
@@ -31,11 +34,8 @@ module Rails
31
34
  @filter_parameters = []
32
35
  @filter_redirect = []
33
36
  @helpers_paths = []
34
- if Rails.env.development?
35
- @hosts = ActionDispatch::HostAuthorization::ALLOWED_HOSTS_IN_DEVELOPMENT.dup
36
- else
37
- @hosts = []
38
- end
37
+ @hosts = Array(([".localhost", IPAddr.new("0.0.0.0/0"), IPAddr.new("::/0")] if Rails.env.development?))
38
+ @host_authorization = {}
39
39
  @public_file_server = ActiveSupport::OrderedOptions.new
40
40
  @public_file_server.enabled = true
41
41
  @public_file_server.index_name = "index"
@@ -73,6 +73,8 @@ module Rails
73
73
  @autoloader = :classic
74
74
  @disable_sandbox = false
75
75
  @add_autoload_paths_to_load_path = true
76
+ @feature_policy = nil
77
+ @rake_eager_load = false
76
78
  end
77
79
 
78
80
  # Loads default configurations. See {the result of the method for each version}[https://guides.rubyonrails.org/configuring.html#results-of-config-load-defaults].
@@ -114,7 +116,7 @@ module Rails
114
116
 
115
117
  if respond_to?(:active_support)
116
118
  active_support.use_authenticated_message_encryption = true
117
- active_support.use_sha1_digests = true
119
+ active_support.hash_digest_class = ::Digest::SHA1
118
120
  end
119
121
 
120
122
  if respond_to?(:action_controller)
@@ -135,17 +137,12 @@ module Rails
135
137
 
136
138
  if respond_to?(:action_dispatch)
137
139
  action_dispatch.use_cookies_with_metadata = true
138
- action_dispatch.return_only_media_type_on_content_type = false
139
140
  end
140
141
 
141
142
  if respond_to?(:action_mailer)
142
143
  action_mailer.delivery_job = "ActionMailer::MailDeliveryJob"
143
144
  end
144
145
 
145
- if respond_to?(:active_job)
146
- active_job.return_false_on_aborted_enqueue = true
147
- end
148
-
149
146
  if respond_to?(:active_storage)
150
147
  active_storage.queues.analysis = :active_storage_analysis
151
148
  active_storage.queues.purge = :active_storage_purge
@@ -156,6 +153,35 @@ module Rails
156
153
  if respond_to?(:active_record)
157
154
  active_record.collection_cache_versioning = true
158
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
+ ActiveSupport.utc_to_local_returns_utc_offset_times = true
159
185
  else
160
186
  raise "Unknown version #{target_version.to_s.inspect}"
161
187
  end
@@ -226,12 +252,9 @@ module Rails
226
252
  path = paths["config/database"].existent.first
227
253
  yaml = Pathname.new(path) if path
228
254
 
229
- config = if yaml && yaml.exist?
230
- require "yaml"
231
- require "erb"
232
- loaded_yaml = YAML.load(ERB.new(yaml.read).result) || {}
233
- shared = loaded_yaml.delete("shared")
234
- if shared
255
+ config = if yaml&.exist?
256
+ loaded_yaml = ActiveSupport::ConfigurationFile.parse(yaml)
257
+ if (shared = loaded_yaml.delete("shared"))
235
258
  loaded_yaml.each do |_k, values|
236
259
  values.reverse_merge!(shared)
237
260
  end
@@ -246,10 +269,6 @@ module Rails
246
269
  end
247
270
 
248
271
  config
249
- rescue Psych::SyntaxError => e
250
- raise "YAML syntax error occurred while parsing #{paths["config/database"].first}. " \
251
- "Please note that YAML must be consistently indented using spaces. Tabs are not allowed. " \
252
- "Error: #{e.message}"
253
272
  rescue => e
254
273
  raise e, "Cannot load database configuration:\n#{e.message}", e.backtrace
255
274
  end
@@ -306,6 +325,14 @@ module Rails
306
325
  end
307
326
  end
308
327
 
328
+ def feature_policy(&block)
329
+ if block_given?
330
+ @feature_policy = ActionDispatch::FeaturePolicy.new(&block)
331
+ else
332
+ @feature_policy
333
+ end
334
+ end
335
+
309
336
  def autoloader=(autoloader)
310
337
  case autoloader
311
338
  when :classic
@@ -336,8 +363,8 @@ module Rails
336
363
  end
337
364
 
338
365
  def method_missing(method, *args)
339
- if method =~ /=$/
340
- @configurations[$`.to_sym] = args.first
366
+ if method.end_with?("=")
367
+ @configurations[:"#{method[0..-2]}"] = args.first
341
368
  else
342
369
  @configurations.fetch(method) {
343
370
  @configurations[method] = ActiveSupport::OrderedOptions.new
@@ -13,10 +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
16
+ middleware.use ::ActionDispatch::HostAuthorization, config.hosts, config.action_dispatch.hosts_response_app, **config.host_authorization
17
17
 
18
18
  if config.force_ssl
19
- 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
20
21
  end
21
22
 
22
23
  middleware.use ::Rack::Sendfile, config.action_dispatch.x_sendfile_header
@@ -43,7 +44,7 @@ module Rails
43
44
 
44
45
  middleware.use ::Rack::Runtime
45
46
  middleware.use ::Rack::MethodOverride unless config.api_only
46
- middleware.use ::ActionDispatch::RequestId
47
+ middleware.use ::ActionDispatch::RequestId, header: config.action_dispatch.request_id_header
47
48
  middleware.use ::ActionDispatch::RemoteIp, config.action_dispatch.ip_spoofing_check, config.action_dispatch.trusted_proxies
48
49
 
49
50
  middleware.use ::Rails::Rack::Logger, config.log_tags
@@ -68,6 +69,7 @@ module Rails
68
69
 
69
70
  unless config.api_only
70
71
  middleware.use ::ActionDispatch::ContentSecurityPolicy::Middleware
72
+ middleware.use ::ActionDispatch::FeaturePolicy::Middleware
71
73
  end
72
74
 
73
75
  middleware.use ::Rack::Head
@@ -60,7 +60,18 @@ module Rails
60
60
 
61
61
  #{unload_message}
62
62
 
63
- Please, check the "Autoloading and Reloading Constants" guide for solutions.
63
+ In order to autoload safely at boot time, please wrap your code in a reloader
64
+ callback this way:
65
+
66
+ Rails.application.reloader.to_prepare do
67
+ # Autoload classes and modules needed at boot time here.
68
+ end
69
+
70
+ That block runs when the application boots, and every time there is a reload.
71
+ For historical reasons, it may run twice, so it has to be idempotent.
72
+
73
+ Check the "Autoloading and Reloading Constants" guide to learn more about how
74
+ Rails autoloads and reloads.
64
75
  WARNING
65
76
  end
66
77
 
@@ -216,7 +227,9 @@ module Rails
216
227
  app.reloader.check = lambda { true }
217
228
  end
218
229
 
219
- if config.reload_classes_only_on_change
230
+ if config.cache_classes
231
+ # No reloader
232
+ elsif config.reload_classes_only_on_change
220
233
  reloader = config.file_watcher.new(*watchable_args, &callback)
221
234
  reloaders << reloader
222
235
 
@@ -5,13 +5,14 @@ require "active_support/core_ext/module/delegation"
5
5
  module Rails
6
6
  class Application
7
7
  class RoutesReloader
8
- attr_reader :route_sets, :paths
8
+ attr_reader :route_sets, :paths, :external_routes
9
9
  attr_accessor :eager_load
10
10
  delegate :execute_if_updated, :execute, :updated?, to: :updater
11
11
 
12
12
  def initialize
13
13
  @paths = []
14
14
  @route_sets = []
15
+ @external_routes = []
15
16
  @eager_load = false
16
17
  end
17
18
 
@@ -26,7 +27,13 @@ module Rails
26
27
 
27
28
  private
28
29
  def updater
29
- @updater ||= ActiveSupport::FileUpdateChecker.new(paths) { reload! }
30
+ @updater ||= begin
31
+ dirs = @external_routes.each_with_object({}) do |dir, hash|
32
+ hash[dir.to_s] = %w(rb)
33
+ end
34
+
35
+ ActiveSupport::FileUpdateChecker.new(paths, dirs) { reload! }
36
+ end
30
37
  end
31
38
 
32
39
  def clear!
@@ -6,8 +6,8 @@ require "active_support/core_ext/object/blank"
6
6
  require "active_support/key_generator"
7
7
  require "active_support/message_verifier"
8
8
  require "active_support/encrypted_configuration"
9
- require "active_support/deprecation"
10
9
  require "active_support/hash_with_indifferent_access"
10
+ require "active_support/configuration_file"
11
11
  require "rails/engine"
12
12
  require "rails/secrets"
13
13
 
@@ -45,7 +45,7 @@ module Rails
45
45
  # process. From the moment you require "config/application.rb" in your app,
46
46
  # the booting process goes like this:
47
47
  #
48
- # 1) require "config/boot.rb" to setup load paths
48
+ # 1) require "config/boot.rb" to set up load paths
49
49
  # 2) require railties and engines
50
50
  # 3) Define Rails.application as "class MyApp::Application < Rails::Application"
51
51
  # 4) Run config.before_configuration callbacks
@@ -205,12 +205,13 @@ module Rails
205
205
 
206
206
  # Convenience for loading config/foo.yml for the current Rails env.
207
207
  #
208
- # Example:
208
+ # Examples:
209
209
  #
210
210
  # # config/exception_notification.yml:
211
211
  # production:
212
212
  # url: http://127.0.0.1:8080
213
213
  # namespace: my_app_production
214
+ #
214
215
  # development:
215
216
  # url: http://localhost:3001
216
217
  # namespace: my_app_development
@@ -219,28 +220,40 @@ module Rails
219
220
  # Rails.application.configure do
220
221
  # config.middleware.use ExceptionNotifier, config_for(:exception_notification)
221
222
  # end
223
+ #
224
+ # # You can also store configurations in a shared section which will be
225
+ # # merged with the environment configuration
226
+ #
227
+ # # config/example.yml
228
+ # shared:
229
+ # foo:
230
+ # bar:
231
+ # baz: 1
232
+ #
233
+ # development:
234
+ # foo:
235
+ # bar:
236
+ # qux: 2
237
+ #
238
+ # # development environment
239
+ # Rails.application.config_for(:example)[:foo][:bar]
240
+ # # => { baz: 1, qux: 2 }
222
241
  def config_for(name, env: Rails.env)
223
242
  yaml = name.is_a?(Pathname) ? name : Pathname.new("#{paths["config"].existent.first}/#{name}.yml")
224
243
 
225
244
  if yaml.exist?
226
245
  require "erb"
227
- all_configs = YAML.load(ERB.new(yaml.read).result) || {}
228
- config, shared = all_configs[env], all_configs["shared"]
229
-
230
- config ||= {} if shared.nil? || shared.is_a?(Hash)
246
+ all_configs = ActiveSupport::ConfigurationFile.parse(yaml, symbolize_names: true)
247
+ config, shared = all_configs[env.to_sym], all_configs[:shared]
231
248
 
232
249
  if config.is_a?(Hash)
233
- ActiveSupport::OrderedOptions.new.update(NonSymbolAccessDeprecatedHash.new(shared&.deep_merge(config) || config))
250
+ ActiveSupport::OrderedOptions.new.update(shared&.deep_merge(config) || config)
234
251
  else
235
252
  config || shared
236
253
  end
237
254
  else
238
255
  raise "Could not load configuration. No such file - #{yaml}"
239
256
  end
240
- rescue Psych::SyntaxError => error
241
- raise "YAML syntax error occurred while parsing #{yaml}. " \
242
- "Please note that YAML must be consistently indented using spaces. Tabs are not allowed. " \
243
- "Error: #{error.message}"
244
257
  end
245
258
 
246
259
  # Stores some of the Rails initial environment parameters which
@@ -267,11 +280,13 @@ module Rails
267
280
  "action_dispatch.cookies_serializer" => config.action_dispatch.cookies_serializer,
268
281
  "action_dispatch.cookies_digest" => config.action_dispatch.cookies_digest,
269
282
  "action_dispatch.cookies_rotations" => config.action_dispatch.cookies_rotations,
283
+ "action_dispatch.cookies_same_site_protection" => coerce_same_site_protection(config.action_dispatch.cookies_same_site_protection),
270
284
  "action_dispatch.use_cookies_with_metadata" => config.action_dispatch.use_cookies_with_metadata,
271
285
  "action_dispatch.content_security_policy" => config.content_security_policy,
272
286
  "action_dispatch.content_security_policy_report_only" => config.content_security_policy_report_only,
273
287
  "action_dispatch.content_security_policy_nonce_generator" => config.content_security_policy_nonce_generator,
274
- "action_dispatch.content_security_policy_nonce_directives" => config.content_security_policy_nonce_directives
288
+ "action_dispatch.content_security_policy_nonce_directives" => config.content_security_policy_nonce_directives,
289
+ "action_dispatch.feature_policy" => config.feature_policy,
275
290
  )
276
291
  end
277
292
  end
@@ -307,6 +322,12 @@ module Rails
307
322
  self.class.generators(&blk)
308
323
  end
309
324
 
325
+ # Sends any server called in the instance of a new application up
326
+ # to the +server+ method defined in Rails::Railtie.
327
+ def server(&blk)
328
+ self.class.server(&blk)
329
+ end
330
+
310
331
  # Sends the +isolate_namespace+ method up to the class method.
311
332
  def isolate_namespace(mod)
312
333
  self.class.isolate_namespace(mod)
@@ -377,20 +398,6 @@ module Rails
377
398
 
378
399
  attr_writer :config
379
400
 
380
- # Returns secrets added to config/secrets.yml.
381
- #
382
- # Example:
383
- #
384
- # development:
385
- # secret_key_base: 836fa3665997a860728bcb9e9a1e704d427cfc920e79d847d79c8a9a907b9e965defa4154b2b86bdec6930adbe33f21364523a6f6ce363865724549fdfc08553
386
- # test:
387
- # secret_key_base: 5a37811464e7d378488b0f073e2193b093682e4e21f5d6f3ae0a4e1781e61a351fdc878a843424e81c73fb484a40d23f92c8dafac4870e74ede6e5e174423010
388
- # production:
389
- # secret_key_base: <%= ENV["SECRET_KEY_BASE"] %>
390
- # namespace: my_app_production
391
- #
392
- # +Rails.application.secrets.namespace+ returns +my_app_production+ in the
393
- # production environment.
394
401
  def secrets
395
402
  @secrets ||= begin
396
403
  secrets = ActiveSupport::OrderedOptions.new
@@ -405,7 +412,7 @@ module Rails
405
412
  end
406
413
  end
407
414
 
408
- attr_writer :secrets
415
+ attr_writer :secrets, :credentials
409
416
 
410
417
  # The secret_key_base is used as the input secret to the application's key generator, which in turn
411
418
  # is used to create all MessageVerifiers/MessageEncryptors, including the ones that sign and encrypt cookies.
@@ -481,10 +488,6 @@ module Rails
481
488
  config.helpers_paths
482
489
  end
483
490
 
484
- console do
485
- require "pp"
486
- end
487
-
488
491
  console do
489
492
  unless ::Kernel.private_method_defined?(:y)
490
493
  require "psych/y"
@@ -516,9 +519,9 @@ module Rails
516
519
  def run_tasks_blocks(app) #:nodoc:
517
520
  railties.each { |r| r.run_tasks_blocks(app) }
518
521
  super
519
- require "rails/tasks"
522
+ load "rails/tasks.rb"
520
523
  task :environment do
521
- ActiveSupport.on_load(:before_initialize) { config.eager_load = false }
524
+ ActiveSupport.on_load(:before_initialize) { config.eager_load = config.rake_eager_load }
522
525
 
523
526
  require_environment!
524
527
  end
@@ -539,6 +542,11 @@ module Rails
539
542
  super
540
543
  end
541
544
 
545
+ def run_server_blocks(app) #:nodoc:
546
+ railties.each { |r| r.run_server_blocks(app) }
547
+ super
548
+ end
549
+
542
550
  # Returns the ordered railties for this application considering railties_order.
543
551
  def ordered_railties #:nodoc:
544
552
  @ordered_railties ||= begin
@@ -585,7 +593,7 @@ module Rails
585
593
  elsif secret_key_base
586
594
  raise ArgumentError, "`secret_key_base` for #{Rails.env} environment must be a type of String`"
587
595
  else
588
- raise ArgumentError, "Missing `secret_key_base` for '#{Rails.env}' environment, set this string with `rails credentials:edit`"
596
+ raise ArgumentError, "Missing `secret_key_base` for '#{Rails.env}' environment, set this string with `bin/rails credentials:edit`"
589
597
  end
590
598
  end
591
599
 
@@ -617,50 +625,8 @@ module Rails
617
625
  config.app_middleware + super
618
626
  end
619
627
 
620
- class NonSymbolAccessDeprecatedHash < HashWithIndifferentAccess # :nodoc:
621
- def initialize(value = nil)
622
- if value.is_a?(Hash)
623
- value.each_pair { |k, v| self[k] = v }
624
- else
625
- super
626
- end
627
- end
628
-
629
- def []=(key, value)
630
- regular_writer(key.to_sym, convert_value(value, for: :assignment))
631
- end
632
-
633
- private
634
- def convert_key(key)
635
- unless key.kind_of?(Symbol)
636
- ActiveSupport::Deprecation.warn(<<~MESSAGE.squish)
637
- Accessing hashes returned from config_for by non-symbol keys
638
- is deprecated and will be removed in Rails 6.1.
639
- Use symbols for access instead.
640
- MESSAGE
641
-
642
- key = key.to_sym
643
- end
644
-
645
- key
646
- end
647
-
648
- def convert_value(value, options = {}) # :doc:
649
- if value.is_a? Hash
650
- if options[:for] == :to_hash
651
- value.to_hash
652
- else
653
- self.class.new(value)
654
- end
655
- elsif value.is_a?(Array)
656
- if options[:for] != :assignment || value.frozen?
657
- value = value.dup
658
- end
659
- value.map! { |e| convert_value(e, options) }
660
- else
661
- value
662
- end
663
- end
628
+ def coerce_same_site_protection(protection)
629
+ protection.respond_to?(:call) ? protection : proc { protection }
664
630
  end
665
631
  end
666
632
  end
@@ -1,21 +1,26 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "active_support/backtrace_cleaner"
4
+ require "active_support/core_ext/string/access"
4
5
 
5
6
  module Rails
6
7
  class BacktraceCleaner < ActiveSupport::BacktraceCleaner
7
- APP_DIRS_PATTERN = /^\/?(app|config|lib|test|\(\w*\))/
8
+ APP_DIRS_PATTERN = /\A(?:\.\/)?(?:app|config|lib|test|\(\w*\))/
8
9
  RENDER_TEMPLATE_PATTERN = /:in `.*_\w+_{2,3}\d+_\d+'/
9
- EMPTY_STRING = ""
10
- SLASH = "/"
11
- DOT_SLASH = "./"
12
10
 
13
11
  def initialize
14
12
  super
15
13
  @root = "#{Rails.root}/"
16
- add_filter { |line| line.sub(@root, EMPTY_STRING) }
17
- add_filter { |line| line.sub(RENDER_TEMPLATE_PATTERN, EMPTY_STRING) }
18
- add_filter { |line| line.sub(DOT_SLASH, SLASH) } # for tests
14
+ add_filter do |line|
15
+ line.start_with?(@root) ? line.from(@root.size) : line
16
+ end
17
+ add_filter do |line|
18
+ if RENDER_TEMPLATE_PATTERN.match?(line)
19
+ line.sub(RENDER_TEMPLATE_PATTERN, "")
20
+ else
21
+ line
22
+ end
23
+ end
19
24
  add_silencer { |line| !APP_DIRS_PATTERN.match?(line) }
20
25
  end
21
26
  end
@@ -40,13 +40,13 @@ class CodeStatistics #:nodoc:
40
40
  Hash[@pairs.map { |pair| [pair.first, calculate_directory_statistics(pair.last)] }]
41
41
  end
42
42
 
43
- def calculate_directory_statistics(directory, pattern = /^(?!\.).*?\.(rb|js|coffee|rake)$/)
43
+ def calculate_directory_statistics(directory, pattern = /^(?!\.).*?\.(rb|js|ts|coffee|rake)$/)
44
44
  stats = CodeStatisticsCalculator.new
45
45
 
46
46
  Dir.foreach(directory) do |file_name|
47
47
  path = "#{directory}/#{file_name}"
48
48
 
49
- if File.directory?(path) && (/^\./ !~ file_name)
49
+ if File.directory?(path) && !file_name.start_with?(".")
50
50
  stats.add(calculate_directory_statistics(path, pattern))
51
51
  elsif file_name&.match?(pattern)
52
52
  stats.add_by_file_path(path)
@@ -75,7 +75,7 @@ class CodeStatistics #:nodoc:
75
75
  end
76
76
 
77
77
  def width_for(label)
78
- [@statistics.values.sum { |s| s.send(label) }.to_s.size, HEADERS[label].length].max
78
+ [@statistics.values.sum { |s| s.public_send(label) }.to_s.size, HEADERS[label].length].max
79
79
  end
80
80
 
81
81
  def print_header
@@ -58,20 +58,20 @@ class CodeStatisticsCalculator #:nodoc:
58
58
  @lines += 1
59
59
 
60
60
  if comment_started
61
- if patterns[:end_block_comment] && line =~ patterns[:end_block_comment]
61
+ if patterns[:end_block_comment] && patterns[:end_block_comment].match?(line)
62
62
  comment_started = false
63
63
  end
64
64
  next
65
65
  else
66
- if patterns[:begin_block_comment] && line =~ patterns[:begin_block_comment]
66
+ if patterns[:begin_block_comment] && patterns[:begin_block_comment].match?(line)
67
67
  comment_started = true
68
68
  next
69
69
  end
70
70
  end
71
71
 
72
- @classes += 1 if patterns[:class] && line =~ patterns[:class]
73
- @methods += 1 if patterns[:method] && line =~ patterns[:method]
74
- if line !~ /^\s*$/ && (patterns[:line_comment].nil? || line !~ patterns[:line_comment])
72
+ @classes += 1 if patterns[:class] && patterns[:class].match?(line)
73
+ @methods += 1 if patterns[:method] && patterns[:method].match?(line)
74
+ if !line.match?(/^\s*$/) && (patterns[:line_comment].nil? || !line.match?(patterns[:line_comment]))
75
75
  @code_lines += 1
76
76
  end
77
77
  end
@@ -82,7 +82,7 @@ class CodeStatisticsCalculator #:nodoc:
82
82
  if file_path.end_with? "_test.rb"
83
83
  :minitest
84
84
  else
85
- File.extname(file_path).sub(/\A\./, "").downcase.to_sym
85
+ File.extname(file_path).delete_prefix(".").downcase.to_sym
86
86
  end
87
87
  end
88
88
  end