railties 6.0.4 → 6.1.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (159) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +248 -375
  3. data/MIT-LICENSE +1 -1
  4. data/RDOC_MAIN.rdoc +1 -1
  5. data/lib/minitest/rails_plugin.rb +16 -1
  6. data/lib/rails/application/bootstrap.rb +5 -5
  7. data/lib/rails/application/configuration.rb +77 -24
  8. data/lib/rails/application/default_middleware_stack.rb +5 -3
  9. data/lib/rails/application/finisher.rb +15 -2
  10. data/lib/rails/application/routes_reloader.rb +9 -2
  11. data/lib/rails/application.rb +53 -80
  12. data/lib/rails/backtrace_cleaner.rb +12 -7
  13. data/lib/rails/code_statistics.rb +3 -3
  14. data/lib/rails/code_statistics_calculator.rb +6 -6
  15. data/lib/rails/command/base.rb +1 -1
  16. data/lib/rails/command/behavior.rb +1 -1
  17. data/lib/rails/command/environment_argument.rb +1 -1
  18. data/lib/rails/command.rb +5 -1
  19. data/lib/rails/commands/credentials/USAGE +17 -2
  20. data/lib/rails/commands/credentials/credentials_command/diffing.rb +41 -0
  21. data/lib/rails/commands/credentials/credentials_command.rb +28 -4
  22. data/lib/rails/commands/db/system/change/change_command.rb +6 -1
  23. data/lib/rails/commands/dbconsole/dbconsole_command.rb +61 -58
  24. data/lib/rails/commands/encrypted/encrypted_command.rb +4 -4
  25. data/lib/rails/commands/generate/generate_command.rb +1 -1
  26. data/lib/rails/commands/notes/notes_command.rb +1 -11
  27. data/lib/rails/commands/rake/rake_command.rb +9 -8
  28. data/lib/rails/commands/secrets/USAGE +9 -3
  29. data/lib/rails/commands/server/server_command.rb +14 -41
  30. data/lib/rails/commands/test/test_command.rb +2 -2
  31. data/lib/rails/configuration.rb +40 -10
  32. data/lib/rails/engine/configuration.rb +1 -0
  33. data/lib/rails/engine/updater.rb +1 -1
  34. data/lib/rails/engine.rb +35 -32
  35. data/lib/rails/gem_version.rb +1 -1
  36. data/lib/rails/generators/actions/create_migration.rb +7 -0
  37. data/lib/rails/generators/actions.rb +50 -29
  38. data/lib/rails/generators/app_base.rb +48 -23
  39. data/lib/rails/generators/base.rb +14 -11
  40. data/lib/rails/generators/database.rb +3 -4
  41. data/lib/rails/generators/erb/scaffold/templates/_form.html.erb.tt +3 -3
  42. data/lib/rails/generators/generated_attribute.rb +3 -9
  43. data/lib/rails/generators/migration.rb +2 -1
  44. data/lib/rails/generators/model_helpers.rb +26 -2
  45. data/lib/rails/generators/named_base.rb +1 -1
  46. data/lib/rails/generators/rails/app/USAGE +2 -1
  47. data/lib/rails/generators/rails/app/app_generator.rb +87 -15
  48. data/lib/rails/generators/rails/app/templates/Gemfile.tt +11 -11
  49. data/lib/rails/generators/rails/app/templates/Rakefile.tt +1 -1
  50. data/lib/rails/generators/rails/app/templates/app/javascript/channels/consumer.js +1 -1
  51. data/lib/rails/generators/rails/app/templates/app/javascript/packs/application.js.tt +11 -11
  52. data/lib/rails/generators/rails/app/templates/app/views/layouts/application.html.erb.tt +2 -1
  53. data/lib/rails/generators/rails/app/templates/bin/rails.tt +5 -2
  54. data/lib/rails/generators/rails/app/templates/bin/rake.tt +5 -2
  55. data/lib/rails/generators/rails/app/templates/bin/setup.tt +4 -4
  56. data/lib/rails/generators/rails/app/templates/bin/spring.tt +13 -0
  57. data/lib/rails/generators/rails/app/templates/bin/yarn.tt +9 -3
  58. data/lib/rails/generators/rails/app/templates/config/application.rb.tt +14 -7
  59. data/lib/rails/generators/rails/app/templates/config/boot.rb.tt +2 -2
  60. data/lib/rails/generators/rails/app/templates/config/databases/jdbc.yml.tt +3 -4
  61. data/lib/rails/generators/rails/app/templates/config/databases/jdbcmysql.yml.tt +10 -9
  62. data/lib/rails/generators/rails/app/templates/config/databases/jdbcpostgresql.yml.tt +11 -10
  63. data/lib/rails/generators/rails/app/templates/config/databases/mysql.yml.tt +10 -9
  64. data/lib/rails/generators/rails/app/templates/config/databases/oracle.yml.tt +11 -10
  65. data/lib/rails/generators/rails/app/templates/config/databases/postgresql.yml.tt +11 -10
  66. data/lib/rails/generators/rails/app/templates/config/databases/sqlserver.yml.tt +10 -9
  67. data/lib/rails/generators/rails/app/templates/config/environment.rb.tt +1 -1
  68. data/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt +17 -3
  69. data/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt +15 -5
  70. data/lib/rails/generators/rails/app/templates/config/environments/test.rb.tt +12 -1
  71. data/lib/rails/generators/rails/app/templates/config/initializers/backtrace_silencers.rb.tt +4 -3
  72. data/lib/rails/generators/rails/app/templates/config/initializers/filter_parameter_logging.rb.tt +3 -1
  73. data/lib/rails/generators/rails/app/templates/config/initializers/new_framework_defaults_6_1.rb.tt +67 -0
  74. data/lib/rails/generators/rails/app/templates/config/initializers/permissions_policy.rb.tt +11 -0
  75. data/lib/rails/generators/rails/app/templates/config/puma.rb.tt +6 -1
  76. data/lib/rails/generators/rails/app/templates/config.ru.tt +2 -1
  77. data/lib/rails/generators/rails/app/templates/db/seeds.rb.tt +1 -1
  78. data/lib/rails/generators/rails/app/templates/gitattributes.tt +14 -0
  79. data/lib/rails/generators/rails/app/templates/gitignore.tt +0 -1
  80. data/lib/rails/generators/rails/app/templates/package.json.tt +1 -1
  81. data/lib/rails/generators/rails/app/templates/test/test_helper.rb.tt +5 -5
  82. data/lib/rails/generators/rails/assets/USAGE +2 -3
  83. data/lib/rails/generators/rails/benchmark/USAGE +19 -0
  84. data/lib/rails/generators/rails/benchmark/benchmark_generator.rb +29 -0
  85. data/lib/rails/generators/rails/benchmark/templates/benchmark.rb.tt +15 -0
  86. data/lib/rails/generators/rails/controller/USAGE +2 -2
  87. data/lib/rails/generators/rails/controller/controller_generator.rb +2 -40
  88. data/lib/rails/generators/rails/credentials/credentials_generator.rb +1 -1
  89. data/lib/rails/generators/rails/generator/USAGE +2 -2
  90. data/lib/rails/generators/rails/generator/templates/USAGE.tt +1 -1
  91. data/lib/rails/generators/rails/helper/USAGE +2 -3
  92. data/lib/rails/generators/rails/integration_test/USAGE +2 -2
  93. data/lib/rails/generators/rails/migration/USAGE +4 -4
  94. data/lib/rails/generators/rails/model/USAGE +15 -16
  95. data/lib/rails/generators/rails/plugin/plugin_generator.rb +25 -23
  96. data/lib/rails/generators/rails/plugin/templates/%name%.gemspec.tt +10 -19
  97. data/lib/rails/generators/rails/plugin/templates/Gemfile.tt +3 -10
  98. data/lib/rails/generators/rails/plugin/templates/Rakefile.tt +4 -18
  99. data/lib/rails/generators/rails/plugin/templates/app/controllers/%namespaced_name%/application_controller.rb.tt +0 -1
  100. data/lib/rails/generators/rails/plugin/templates/bin/rails.tt +3 -3
  101. data/lib/rails/generators/rails/plugin/templates/gitignore.tt +13 -11
  102. data/lib/rails/generators/rails/plugin/templates/lib/%namespaced_name%.rb.tt +1 -0
  103. data/lib/rails/generators/rails/plugin/templates/rails/boot.rb.tt +1 -1
  104. data/lib/rails/generators/rails/plugin/templates/test/%namespaced_name%_test.rb.tt +4 -4
  105. data/lib/rails/generators/rails/plugin/templates/test/integration/navigation_test.rb.tt +1 -1
  106. data/lib/rails/generators/rails/plugin/templates/test/test_helper.rb.tt +0 -3
  107. data/lib/rails/generators/rails/resource/USAGE +4 -4
  108. data/lib/rails/generators/rails/resource_route/resource_route_generator.rb +2 -27
  109. data/lib/rails/generators/rails/scaffold/USAGE +5 -5
  110. data/lib/rails/generators/rails/scaffold_controller/USAGE +2 -2
  111. data/lib/rails/generators/rails/scaffold_controller/scaffold_controller_generator.rb +6 -0
  112. data/lib/rails/generators/rails/scaffold_controller/templates/api_controller.rb.tt +1 -1
  113. data/lib/rails/generators/rails/scaffold_controller/templates/controller.rb.tt +1 -1
  114. data/lib/rails/generators/rails/system_test/USAGE +2 -2
  115. data/lib/rails/generators/rails/task/USAGE +3 -3
  116. data/lib/rails/generators/test_case.rb +1 -1
  117. data/lib/rails/generators/test_unit/controller/controller_generator.rb +2 -0
  118. data/lib/rails/generators/test_unit/controller/templates/functional_test.rb.tt +3 -3
  119. data/lib/rails/generators/test_unit/generator/templates/generator_test.rb.tt +2 -2
  120. data/lib/rails/generators/test_unit/integration/templates/integration_test.rb.tt +1 -1
  121. data/lib/rails/generators/test_unit/job/templates/unit_test.rb.tt +1 -1
  122. data/lib/rails/generators/test_unit/mailer/templates/functional_test.rb.tt +1 -1
  123. data/lib/rails/generators/test_unit/model/templates/fixtures.yml.tt +1 -1
  124. data/lib/rails/generators/test_unit/model/templates/unit_test.rb.tt +1 -1
  125. data/lib/rails/generators/test_unit/plugin/templates/%file_name%_test.rb.tt +1 -1
  126. data/lib/rails/generators/test_unit/plugin/templates/test_helper.rb +2 -2
  127. data/lib/rails/generators/test_unit/scaffold/templates/api_functional_test.rb.tt +1 -1
  128. data/lib/rails/generators/test_unit/scaffold/templates/functional_test.rb.tt +1 -1
  129. data/lib/rails/generators/testing/assertions.rb +2 -2
  130. data/lib/rails/generators/testing/behaviour.rb +1 -1
  131. data/lib/rails/generators.rb +29 -15
  132. data/lib/rails/info.rb +1 -1
  133. data/lib/rails/info_controller.rb +1 -1
  134. data/lib/rails/mailers_controller.rb +1 -0
  135. data/lib/rails/paths.rb +14 -6
  136. data/lib/rails/railtie/configuration.rb +3 -2
  137. data/lib/rails/railtie.rb +31 -10
  138. data/lib/rails/source_annotation_extractor.rb +2 -16
  139. data/lib/rails/tasks/engine.rake +1 -4
  140. data/lib/rails/tasks/framework.rake +7 -1
  141. data/lib/rails/tasks/misc.rake +1 -1
  142. data/lib/rails/tasks/statistics.rake +1 -1
  143. data/lib/rails/tasks/yarn.rake +14 -2
  144. data/lib/rails/tasks.rb +0 -4
  145. data/lib/rails/templates/rails/mailers/email.html.erb +1 -0
  146. data/lib/rails/templates/rails/welcome/index.html.erb +1 -1
  147. data/lib/rails/test_unit/reporter.rb +2 -1
  148. data/lib/rails/test_unit/runner.rb +12 -3
  149. data/lib/rails/test_unit/testing.rake +6 -0
  150. data/lib/rails.rb +5 -8
  151. metadata +25 -31
  152. data/lib/rails/generators/rails/app/templates/config/databases/frontbase.yml.tt +0 -50
  153. data/lib/rails/generators/rails/app/templates/config/databases/ibm_db.yml.tt +0 -86
  154. data/lib/rails/generators/rails/app/templates/config/initializers/new_framework_defaults_6_0.rb.tt +0 -45
  155. data/lib/rails/generators/rails/plugin/templates/rails/application.rb.tt +0 -23
  156. data/lib/rails/tasks/annotations.rake +0 -22
  157. data/lib/rails/tasks/dev.rake +0 -11
  158. data/lib/rails/tasks/initializers.rake +0 -9
  159. 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
 
@@ -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.
@@ -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
 
@@ -32,6 +35,7 @@ module Rails
32
35
  @filter_redirect = []
33
36
  @helpers_paths = []
34
37
  @hosts = Array(([".localhost", IPAddr.new("0.0.0.0/0"), IPAddr.new("::/0")] if Rails.env.development?))
38
+ @host_authorization = {}
35
39
  @public_file_server = ActiveSupport::OrderedOptions.new
36
40
  @public_file_server.enabled = true
37
41
  @public_file_server.index_name = "index"
@@ -69,6 +73,8 @@ module Rails
69
73
  @autoloader = :classic
70
74
  @disable_sandbox = false
71
75
  @add_autoload_paths_to_load_path = true
76
+ @permissions_policy = nil
77
+ @rake_eager_load = false
72
78
  end
73
79
 
74
80
  # Loads default configurations. See {the result of the method for each version}[https://guides.rubyonrails.org/configuring.html#results-of-config-load-defaults].
@@ -110,7 +116,7 @@ module Rails
110
116
 
111
117
  if respond_to?(:active_support)
112
118
  active_support.use_authenticated_message_encryption = true
113
- active_support.use_sha1_digests = true
119
+ active_support.hash_digest_class = ::Digest::SHA1
114
120
  end
115
121
 
116
122
  if respond_to?(:action_controller)
@@ -131,17 +137,12 @@ module Rails
131
137
 
132
138
  if respond_to?(:action_dispatch)
133
139
  action_dispatch.use_cookies_with_metadata = true
134
- action_dispatch.return_only_media_type_on_content_type = false
135
140
  end
136
141
 
137
142
  if respond_to?(:action_mailer)
138
143
  action_mailer.delivery_job = "ActionMailer::MailDeliveryJob"
139
144
  end
140
145
 
141
- if respond_to?(:active_job)
142
- active_job.return_false_on_aborted_enqueue = true
143
- end
144
-
145
146
  if respond_to?(:active_storage)
146
147
  active_storage.queues.analysis = :active_storage_analysis
147
148
  active_storage.queues.purge = :active_storage_purge
@@ -152,6 +153,54 @@ module Rails
152
153
  if respond_to?(:active_record)
153
154
  active_record.collection_cache_versioning = true
154
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
+ action_view.preload_links_header = true
187
+ end
188
+
189
+ if respond_to?(:active_storage)
190
+ active_storage.queues.analysis = nil
191
+ active_storage.queues.purge = nil
192
+ end
193
+
194
+ if respond_to?(:action_mailbox)
195
+ action_mailbox.queues.incineration = nil
196
+ action_mailbox.queues.routing = nil
197
+ end
198
+
199
+ if respond_to?(:action_mailer)
200
+ action_mailer.deliver_later_queue_name = nil
201
+ end
202
+
203
+ ActiveSupport.utc_to_local_returns_utc_offset_times = true
155
204
  else
156
205
  raise "Unknown version #{target_version.to_s.inspect}"
157
206
  end
@@ -207,10 +256,13 @@ module Rails
207
256
  if path = paths["config/database"].existent.first
208
257
  require "rails/application/dummy_erb_compiler"
209
258
 
210
- yaml = Pathname.new(path)
211
- erb = DummyERB.new(yaml.read)
259
+ yaml = DummyERB.new(Pathname.new(path).read).result
212
260
 
213
- YAML.load(erb.result) || {}
261
+ if YAML.respond_to?(:unsafe_load)
262
+ YAML.unsafe_load(yaml) || {}
263
+ else
264
+ YAML.load(yaml) || {}
265
+ end
214
266
  else
215
267
  {}
216
268
  end
@@ -222,12 +274,9 @@ module Rails
222
274
  path = paths["config/database"].existent.first
223
275
  yaml = Pathname.new(path) if path
224
276
 
225
- config = if yaml && yaml.exist?
226
- require "yaml"
227
- require "erb"
228
- loaded_yaml = YAML.load(ERB.new(yaml.read).result) || {}
229
- shared = loaded_yaml.delete("shared")
230
- if shared
277
+ config = if yaml&.exist?
278
+ loaded_yaml = ActiveSupport::ConfigurationFile.parse(yaml)
279
+ if (shared = loaded_yaml.delete("shared"))
231
280
  loaded_yaml.each do |_k, values|
232
281
  values.reverse_merge!(shared)
233
282
  end
@@ -242,10 +291,6 @@ module Rails
242
291
  end
243
292
 
244
293
  config
245
- rescue Psych::SyntaxError => e
246
- raise "YAML syntax error occurred while parsing #{paths["config/database"].first}. " \
247
- "Please note that YAML must be consistently indented using spaces. Tabs are not allowed. " \
248
- "Error: #{e.message}"
249
294
  rescue => e
250
295
  raise e, "Cannot load database configuration:\n#{e.message}", e.backtrace
251
296
  end
@@ -302,6 +347,14 @@ module Rails
302
347
  end
303
348
  end
304
349
 
350
+ def permissions_policy(&block)
351
+ if block_given?
352
+ @permissions_policy = ActionDispatch::PermissionsPolicy.new(&block)
353
+ else
354
+ @permissions_policy
355
+ end
356
+ end
357
+
305
358
  def autoloader=(autoloader)
306
359
  case autoloader
307
360
  when :classic
@@ -332,8 +385,8 @@ module Rails
332
385
  end
333
386
 
334
387
  def method_missing(method, *args)
335
- if method =~ /=$/
336
- @configurations[$`.to_sym] = args.first
388
+ if method.end_with?("=")
389
+ @configurations[:"#{method[0..-2]}"] = args.first
337
390
  else
338
391
  @configurations.fetch(method) {
339
392
  @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::PermissionsPolicy::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,47 @@ 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"]
246
+ all_configs = ActiveSupport::ConfigurationFile.parse(yaml).deep_symbolize_keys
247
+ config, shared = all_configs[env.to_sym], all_configs[:shared]
229
248
 
230
- config ||= {} if shared.nil? || shared.is_a?(Hash)
249
+ if shared
250
+ config = {} if config.nil?
251
+ if config.is_a?(Hash)
252
+ config = shared.deep_merge(config)
253
+ end
254
+ end
231
255
 
232
256
  if config.is_a?(Hash)
233
- ActiveSupport::OrderedOptions.new.update(NonSymbolAccessDeprecatedHash.new(shared&.deep_merge(config) || config))
234
- else
235
- config || shared
257
+ config = ActiveSupport::OrderedOptions.new.update(config)
236
258
  end
259
+
260
+ config
237
261
  else
238
262
  raise "Could not load configuration. No such file - #{yaml}"
239
263
  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
264
  end
245
265
 
246
266
  # Stores some of the Rails initial environment parameters which
@@ -267,11 +287,13 @@ module Rails
267
287
  "action_dispatch.cookies_serializer" => config.action_dispatch.cookies_serializer,
268
288
  "action_dispatch.cookies_digest" => config.action_dispatch.cookies_digest,
269
289
  "action_dispatch.cookies_rotations" => config.action_dispatch.cookies_rotations,
290
+ "action_dispatch.cookies_same_site_protection" => coerce_same_site_protection(config.action_dispatch.cookies_same_site_protection),
270
291
  "action_dispatch.use_cookies_with_metadata" => config.action_dispatch.use_cookies_with_metadata,
271
292
  "action_dispatch.content_security_policy" => config.content_security_policy,
272
293
  "action_dispatch.content_security_policy_report_only" => config.content_security_policy_report_only,
273
294
  "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
295
+ "action_dispatch.content_security_policy_nonce_directives" => config.content_security_policy_nonce_directives,
296
+ "action_dispatch.permissions_policy" => config.permissions_policy,
275
297
  )
276
298
  end
277
299
  end
@@ -307,6 +329,12 @@ module Rails
307
329
  self.class.generators(&blk)
308
330
  end
309
331
 
332
+ # Sends any server called in the instance of a new application up
333
+ # to the +server+ method defined in Rails::Railtie.
334
+ def server(&blk)
335
+ self.class.server(&blk)
336
+ end
337
+
310
338
  # Sends the +isolate_namespace+ method up to the class method.
311
339
  def isolate_namespace(mod)
312
340
  self.class.isolate_namespace(mod)
@@ -377,20 +405,6 @@ module Rails
377
405
 
378
406
  attr_writer :config
379
407
 
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
408
  def secrets
395
409
  @secrets ||= begin
396
410
  secrets = ActiveSupport::OrderedOptions.new
@@ -405,7 +419,7 @@ module Rails
405
419
  end
406
420
  end
407
421
 
408
- attr_writer :secrets
422
+ attr_writer :secrets, :credentials
409
423
 
410
424
  # The secret_key_base is used as the input secret to the application's key generator, which in turn
411
425
  # is used to create all MessageVerifiers/MessageEncryptors, including the ones that sign and encrypt cookies.
@@ -481,10 +495,6 @@ module Rails
481
495
  config.helpers_paths
482
496
  end
483
497
 
484
- console do
485
- require "pp"
486
- end
487
-
488
498
  console do
489
499
  unless ::Kernel.private_method_defined?(:y)
490
500
  require "psych/y"
@@ -516,9 +526,9 @@ module Rails
516
526
  def run_tasks_blocks(app) #:nodoc:
517
527
  railties.each { |r| r.run_tasks_blocks(app) }
518
528
  super
519
- require "rails/tasks"
529
+ load "rails/tasks.rb"
520
530
  task :environment do
521
- ActiveSupport.on_load(:before_initialize) { config.eager_load = false }
531
+ ActiveSupport.on_load(:before_initialize) { config.eager_load = config.rake_eager_load }
522
532
 
523
533
  require_environment!
524
534
  end
@@ -539,6 +549,11 @@ module Rails
539
549
  super
540
550
  end
541
551
 
552
+ def run_server_blocks(app) #:nodoc:
553
+ railties.each { |r| r.run_server_blocks(app) }
554
+ super
555
+ end
556
+
542
557
  # Returns the ordered railties for this application considering railties_order.
543
558
  def ordered_railties #:nodoc:
544
559
  @ordered_railties ||= begin
@@ -585,7 +600,7 @@ module Rails
585
600
  elsif secret_key_base
586
601
  raise ArgumentError, "`secret_key_base` for #{Rails.env} environment must be a type of String`"
587
602
  else
588
- raise ArgumentError, "Missing `secret_key_base` for '#{Rails.env}' environment, set this string with `rails credentials:edit`"
603
+ raise ArgumentError, "Missing `secret_key_base` for '#{Rails.env}' environment, set this string with `bin/rails credentials:edit`"
589
604
  end
590
605
  end
591
606
 
@@ -617,50 +632,8 @@ module Rails
617
632
  config.app_middleware + super
618
633
  end
619
634
 
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
635
+ def coerce_same_site_protection(protection)
636
+ protection.respond_to?(:call) ? protection : proc { protection }
664
637
  end
665
638
  end
666
639
  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