railties 5.2.6.2 → 6.0.0.beta1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of railties might be problematic. Click here for more details.

Files changed (143) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +183 -199
  3. data/MIT-LICENSE +1 -1
  4. data/RDOC_MAIN.rdoc +35 -28
  5. data/README.rdoc +1 -1
  6. data/lib/minitest/rails_plugin.rb +6 -10
  7. data/lib/rails/all.rb +4 -0
  8. data/lib/rails/api/generator.rb +2 -1
  9. data/lib/rails/api/task.rb +16 -0
  10. data/lib/rails/app_loader.rb +1 -1
  11. data/lib/rails/app_updater.rb +3 -1
  12. data/lib/rails/application/configuration.rb +54 -12
  13. data/lib/rails/application/default_middleware_stack.rb +2 -0
  14. data/lib/rails/application.rb +21 -45
  15. data/lib/rails/backtrace_cleaner.rb +5 -17
  16. data/lib/rails/code_statistics.rb +3 -3
  17. data/lib/rails/command/actions.rb +0 -10
  18. data/lib/rails/command/base.rb +1 -5
  19. data/lib/rails/command/behavior.rb +4 -46
  20. data/lib/rails/command/environment_argument.rb +1 -11
  21. data/lib/rails/command/spellchecker.rb +58 -0
  22. data/lib/rails/command.rb +11 -10
  23. data/lib/rails/commands/credentials/USAGE +19 -1
  24. data/lib/rails/commands/credentials/credentials_command.rb +42 -23
  25. data/lib/rails/commands/db/system/change/change_command.rb +20 -0
  26. data/lib/rails/commands/dbconsole/dbconsole_command.rb +2 -2
  27. data/lib/rails/commands/dev/dev_command.rb +17 -0
  28. data/lib/rails/commands/encrypted/encrypted_command.rb +2 -3
  29. data/lib/rails/commands/help/help_command.rb +1 -1
  30. data/lib/rails/commands/initializers/initializers_command.rb +16 -0
  31. data/lib/rails/commands/new/new_command.rb +2 -2
  32. data/lib/rails/commands/notes/notes_command.rb +39 -0
  33. data/lib/rails/commands/plugin/plugin_command.rb +1 -1
  34. data/lib/rails/commands/routes/routes_command.rb +37 -0
  35. data/lib/rails/commands/runner/runner_command.rb +6 -6
  36. data/lib/rails/commands/secrets/USAGE +3 -3
  37. data/lib/rails/commands/secrets/secrets_command.rb +3 -3
  38. data/lib/rails/commands/server/server_command.rb +109 -48
  39. data/lib/rails/configuration.rb +1 -7
  40. data/lib/rails/engine/configuration.rb +3 -1
  41. data/lib/rails/engine.rb +3 -9
  42. data/lib/rails/gem_version.rb +4 -4
  43. data/lib/rails/generators/actions.rb +48 -37
  44. data/lib/rails/generators/app_base.rb +49 -89
  45. data/lib/rails/generators/app_name.rb +50 -0
  46. data/lib/rails/generators/base.rb +0 -4
  47. data/lib/rails/generators/database.rb +57 -0
  48. data/lib/rails/generators/erb/mailer/mailer_generator.rb +1 -1
  49. data/lib/rails/generators/erb/scaffold/templates/index.html.erb.tt +1 -1
  50. data/lib/rails/generators/erb/scaffold/templates/show.html.erb.tt +1 -1
  51. data/lib/rails/generators/generated_attribute.rb +17 -17
  52. data/lib/rails/generators/model_helpers.rb +8 -1
  53. data/lib/rails/generators/named_base.rb +1 -5
  54. data/lib/rails/generators/rails/app/app_generator.rb +37 -72
  55. data/lib/rails/generators/rails/app/templates/Gemfile.tt +3 -6
  56. data/lib/rails/generators/rails/app/templates/app/assets/config/manifest.js.tt +0 -3
  57. data/lib/rails/generators/rails/app/templates/app/{assets/javascripts/cable.js.tt → javascript/channels/consumer.js} +2 -9
  58. data/lib/rails/generators/rails/app/templates/app/javascript/channels/index.js +5 -0
  59. data/lib/rails/generators/rails/app/templates/app/javascript/packs/application.js.tt +15 -0
  60. data/lib/rails/generators/rails/app/templates/app/jobs/application_job.rb.tt +5 -0
  61. data/lib/rails/generators/rails/app/templates/app/views/layouts/application.html.erb.tt +4 -4
  62. data/lib/rails/generators/rails/app/templates/bin/setup.tt +4 -5
  63. data/lib/rails/generators/rails/app/templates/bin/update.tt +6 -7
  64. data/lib/rails/generators/rails/app/templates/config/application.rb.tt +2 -0
  65. data/lib/rails/generators/rails/app/templates/config/cable.yml.tt +1 -1
  66. data/lib/rails/generators/rails/app/templates/config/databases/frontbase.yml.tt +2 -2
  67. data/lib/rails/generators/rails/app/templates/config/databases/ibm_db.yml.tt +2 -2
  68. data/lib/rails/generators/rails/app/templates/config/databases/jdbc.yml.tt +2 -2
  69. data/lib/rails/generators/rails/app/templates/config/databases/jdbcmysql.yml.tt +3 -3
  70. data/lib/rails/generators/rails/app/templates/config/databases/jdbcpostgresql.yml.tt +3 -3
  71. data/lib/rails/generators/rails/app/templates/config/databases/mysql.yml.tt +4 -4
  72. data/lib/rails/generators/rails/app/templates/config/databases/oracle.yml.tt +2 -2
  73. data/lib/rails/generators/rails/app/templates/config/databases/postgresql.yml.tt +6 -6
  74. data/lib/rails/generators/rails/app/templates/config/databases/sqlserver.yml.tt +2 -2
  75. data/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt +3 -2
  76. data/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt +5 -12
  77. data/lib/rails/generators/rails/app/templates/config/environments/test.rb.tt +6 -2
  78. data/lib/rails/generators/rails/app/templates/config/initializers/assets.rb.tt +1 -1
  79. data/lib/rails/generators/rails/app/templates/config/initializers/content_security_policy.rb.tt +4 -0
  80. data/lib/rails/generators/rails/app/templates/config/initializers/new_framework_defaults_6_0.rb.tt +33 -0
  81. data/lib/rails/generators/rails/app/templates/config/locales/en.yml +1 -1
  82. data/lib/rails/generators/rails/app/templates/config/puma.rb.tt +3 -5
  83. data/lib/rails/generators/rails/app/templates/config/routes.rb.tt +1 -1
  84. data/lib/rails/generators/rails/app/templates/config/spring.rb.tt +6 -6
  85. data/lib/rails/generators/rails/app/templates/gitignore.tt +2 -7
  86. data/lib/rails/generators/rails/app/templates/package.json.tt +7 -1
  87. data/lib/rails/generators/rails/app/templates/ruby-version.tt +1 -1
  88. data/lib/rails/generators/rails/app/templates/test/channels/application_cable/connection_test.rb.tt +11 -0
  89. data/lib/rails/generators/rails/app/templates/test/test_helper.rb.tt +7 -0
  90. data/lib/rails/generators/rails/assets/USAGE +1 -4
  91. data/lib/rails/generators/rails/assets/assets_generator.rb +0 -8
  92. data/lib/rails/generators/rails/controller/controller_generator.rb +11 -1
  93. data/lib/rails/generators/rails/credentials/credentials_generator.rb +7 -8
  94. data/lib/rails/generators/rails/db/system/change/change_generator.rb +55 -0
  95. data/lib/rails/generators/rails/encrypted_file/encrypted_file_generator.rb +4 -5
  96. data/lib/rails/generators/rails/helper/helper_generator.rb +5 -0
  97. data/lib/rails/generators/rails/plugin/plugin_generator.rb +9 -18
  98. data/lib/rails/generators/rails/plugin/templates/app/controllers/%namespaced_name%/application_controller.rb.tt +1 -1
  99. data/lib/rails/generators/rails/plugin/templates/app/helpers/%namespaced_name%/application_helper.rb.tt +1 -1
  100. data/lib/rails/generators/rails/plugin/templates/app/jobs/%namespaced_name%/application_job.rb.tt +1 -1
  101. data/lib/rails/generators/rails/plugin/templates/app/mailers/%namespaced_name%/application_mailer.rb.tt +1 -1
  102. data/lib/rails/generators/rails/plugin/templates/app/models/%namespaced_name%/application_record.rb.tt +1 -1
  103. data/lib/rails/generators/rails/plugin/templates/gitignore.tt +1 -1
  104. data/lib/rails/generators/rails/plugin/templates/lib/%namespaced_name%/engine.rb.tt +1 -1
  105. data/lib/rails/generators/rails/plugin/templates/lib/%namespaced_name%/railtie.rb.tt +1 -1
  106. data/lib/rails/generators/rails/plugin/templates/test/test_helper.rb.tt +1 -2
  107. data/lib/rails/generators/resource_helpers.rb +1 -6
  108. data/lib/rails/generators/test_unit/integration/integration_generator.rb +6 -0
  109. data/lib/rails/generators/test_unit/job/job_generator.rb +5 -0
  110. data/lib/rails/generators/test_unit/mailer/mailer_generator.rb +1 -1
  111. data/lib/rails/generators/test_unit/scaffold/scaffold_generator.rb +1 -1
  112. data/lib/rails/generators/test_unit/system/system_generator.rb +5 -0
  113. data/lib/rails/generators/testing/behaviour.rb +3 -0
  114. data/lib/rails/generators.rb +11 -12
  115. data/lib/rails/info.rb +2 -2
  116. data/lib/rails/info_controller.rb +1 -1
  117. data/lib/rails/mailers_controller.rb +1 -1
  118. data/lib/rails/paths.rb +19 -9
  119. data/lib/rails/railtie.rb +1 -1
  120. data/lib/rails/ruby_version_check.rb +3 -3
  121. data/lib/rails/secrets.rb +0 -1
  122. data/lib/rails/source_annotation_extractor.rb +125 -117
  123. data/lib/rails/tasks/annotations.rake +9 -9
  124. data/lib/rails/tasks/dev.rake +5 -4
  125. data/lib/rails/tasks/framework.rake +5 -1
  126. data/lib/rails/tasks/initializers.rake +5 -4
  127. data/lib/rails/tasks/log.rake +0 -1
  128. data/lib/rails/tasks/routes.rake +4 -26
  129. data/lib/rails/tasks/statistics.rake +1 -0
  130. data/lib/rails/tasks/yarn.rake +1 -1
  131. data/lib/rails/templates/rails/welcome/index.html.erb +2 -2
  132. data/lib/rails/test_help.rb +11 -9
  133. data/lib/rails/test_unit/reporter.rb +1 -1
  134. data/lib/rails/test_unit/runner.rb +5 -5
  135. data/lib/rails/test_unit/testing.rake +1 -1
  136. metadata +33 -27
  137. data/lib/rails/commands/encrypted/USAGE +0 -28
  138. data/lib/rails/generators/js/assets/assets_generator.rb +0 -15
  139. data/lib/rails/generators/js/assets/templates/javascript.js +0 -2
  140. data/lib/rails/generators/rails/app/templates/app/assets/javascripts/application.js.tt +0 -22
  141. data/lib/rails/generators/rails/app/templates/bin/bundle.tt +0 -2
  142. data/lib/rails/generators/rails/app/templates/config/initializers/new_framework_defaults_5_2.rb.tt +0 -38
  143. data/lib/rails/generators/rails/assets/templates/javascript.js +0 -2
@@ -43,18 +43,14 @@ module Minitest
43
43
  Minitest.backtrace_filter = ::Rails.backtrace_cleaner if ::Rails.respond_to?(:backtrace_cleaner)
44
44
  end
45
45
 
46
- self.plugin_rails_replace_reporters(reporter, options)
47
- end
48
-
49
- def self.plugin_rails_replace_reporters(minitest_reporter, options)
50
- return unless minitest_reporter.kind_of?(Minitest::CompositeReporter)
46
+ # Suppress summary reports when outputting inline rerun snippets.
47
+ if reporter.reporters.reject! { |reporter| reporter.kind_of?(SummaryReporter) }
48
+ reporter << SuppressedSummaryReporter.new(options[:io], options)
49
+ end
51
50
 
52
51
  # Replace progress reporter for colors.
53
- if minitest_reporter.reporters.reject! { |reporter| reporter.kind_of?(SummaryReporter) } != nil
54
- minitest_reporter << SuppressedSummaryReporter.new(options[:io], options)
55
- end
56
- if minitest_reporter.reporters.reject! { |reporter| reporter.kind_of?(ProgressReporter) } != nil
57
- minitest_reporter << ::Rails::TestUnitReporter.new(options[:io], options)
52
+ if reporter.reporters.reject! { |reporter| reporter.kind_of?(ProgressReporter) }
53
+ reporter << ::Rails::TestUnitReporter.new(options[:io], options)
58
54
  end
59
55
  end
60
56
 
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|
@@ -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, classes = classes.partition { |klass| core_extension?(klass) }
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
@@ -74,6 +74,22 @@ module Rails
74
74
  )
75
75
  },
76
76
 
77
+ "actionmailbox" => {
78
+ include: %w(
79
+ README.md
80
+ app/**/action_mailbox/**/*.rb
81
+ lib/action_mailbox/**/*.rb
82
+ )
83
+ },
84
+
85
+ "actiontext" => {
86
+ include: %w(
87
+ README.md
88
+ app/**/action_text/**/*.rb
89
+ lib/action_text/**/*.rb
90
+ )
91
+ },
92
+
77
93
  "railties" => {
78
94
  include: %w(
79
95
  README.rdoc
@@ -49,7 +49,7 @@ EOS
49
49
  if exe = find_executable
50
50
  contents = File.read(exe)
51
51
 
52
- if contents =~ /(APP|ENGINE)_PATH/
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")
@@ -21,12 +21,14 @@ 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)
30
32
  options[:skip_spring] = !defined?(Spring)
31
33
  options
32
34
  end
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "ipaddr"
3
4
  require "active_support/core_ext/kernel/reporting"
4
5
  require "active_support/file_update_checker"
5
6
  require "rails/engine/configuration"
@@ -11,13 +12,13 @@ module Rails
11
12
  attr_accessor :allow_concurrency, :asset_host, :autoflush_log,
12
13
  :cache_classes, :cache_store, :consider_all_requests_local, :console,
13
14
  :eager_load, :exceptions_app, :file_watcher, :filter_parameters,
14
- :force_ssl, :helpers_paths, :logger, :log_formatter, :log_tags,
15
- :railties_order, :relative_url_root, :secret_key_base, :secret_token,
15
+ :force_ssl, :helpers_paths, :hosts, :logger, :log_formatter, :log_tags,
16
+ :railties_order, :relative_url_root, :secret_key_base,
16
17
  :ssl_options, :public_file_server,
17
18
  :session_options, :time_zone, :reload_classes_only_on_change,
18
19
  :beginning_of_week, :filter_redirect, :x, :enable_dependency_loading,
19
20
  :read_encrypted_secrets, :log_level, :content_security_policy_report_only,
20
- :content_security_policy_nonce_generator, :require_master_key
21
+ :content_security_policy_nonce_generator, :require_master_key, :credentials
21
22
 
22
23
  attr_reader :encoding, :api_only, :loaded_config_version
23
24
 
@@ -29,6 +30,7 @@ module Rails
29
30
  @filter_parameters = []
30
31
  @filter_redirect = []
31
32
  @helpers_paths = []
33
+ @hosts = Array(([IPAddr.new("0.0.0.0/0"), IPAddr.new("::/0"), "localhost"] if Rails.env.development?))
32
34
  @public_file_server = ActiveSupport::OrderedOptions.new
33
35
  @public_file_server.enabled = true
34
36
  @public_file_server.index_name = "index"
@@ -48,7 +50,6 @@ module Rails
48
50
  @autoflush_log = true
49
51
  @log_formatter = ActiveSupport::Logger::SimpleFormatter.new
50
52
  @eager_load = nil
51
- @secret_token = nil
52
53
  @secret_key_base = nil
53
54
  @api_only = false
54
55
  @debug_exception_response_format = nil
@@ -60,6 +61,9 @@ module Rails
60
61
  @content_security_policy_nonce_generator = nil
61
62
  @require_master_key = false
62
63
  @loaded_config_version = nil
64
+ @credentials = ActiveSupport::OrderedOptions.new
65
+ @credentials.content_path = default_credentials_content_path
66
+ @credentials.key_path = default_credentials_key_path
63
67
  end
64
68
 
65
69
  def load_defaults(target_version)
@@ -92,10 +96,6 @@ module Rails
92
96
 
93
97
  if respond_to?(:active_record)
94
98
  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
99
  end
100
100
 
101
101
  if respond_to?(:action_dispatch)
@@ -114,6 +114,29 @@ module Rails
114
114
  if respond_to?(:action_view)
115
115
  action_view.form_with_generates_ids = true
116
116
  end
117
+ when "6.0"
118
+ load_defaults "5.2"
119
+
120
+ if respond_to?(:action_view)
121
+ action_view.default_enforce_utf8 = false
122
+ end
123
+
124
+ if respond_to?(:action_dispatch)
125
+ action_dispatch.use_cookies_with_metadata = true
126
+ end
127
+
128
+ if respond_to?(:action_mailer)
129
+ action_mailer.delivery_job = "ActionMailer::MailDeliveryJob"
130
+ end
131
+
132
+ if respond_to?(:active_job)
133
+ active_job.return_false_on_aborted_enqueue = true
134
+ end
135
+
136
+ if respond_to?(:active_storage)
137
+ active_storage.queues.analysis = :active_storage_analysis
138
+ active_storage.queues.purge = :active_storage_purge
139
+ end
117
140
  else
118
141
  raise "Unknown version #{target_version.to_s.inspect}"
119
142
  end
@@ -140,9 +163,7 @@ module Rails
140
163
  @debug_exception_response_format || :default
141
164
  end
142
165
 
143
- def debug_exception_response_format=(value)
144
- @debug_exception_response_format = value
145
- end
166
+ attr_writer :debug_exception_response_format
146
167
 
147
168
  def paths
148
169
  @paths ||= begin
@@ -235,7 +256,7 @@ module Rails
235
256
  end
236
257
 
237
258
  def annotations
238
- SourceAnnotationExtractor::Annotation
259
+ Rails::SourceAnnotationExtractor::Annotation
239
260
  end
240
261
 
241
262
  def content_security_policy(&block)
@@ -265,6 +286,27 @@ module Rails
265
286
  true
266
287
  end
267
288
  end
289
+
290
+ private
291
+ def default_credentials_content_path
292
+ if credentials_available_for_current_env?
293
+ root.join("config", "credentials", "#{Rails.env}.yml.enc")
294
+ else
295
+ root.join("config", "credentials.yml.enc")
296
+ end
297
+ end
298
+
299
+ def default_credentials_key_path
300
+ if credentials_available_for_current_env?
301
+ root.join("config", "credentials", "#{Rails.env}.key")
302
+ else
303
+ root.join("config", "master.key")
304
+ end
305
+ end
306
+
307
+ def credentials_available_for_current_env?
308
+ File.exist?(root.join("config", "credentials", "#{Rails.env}.yml.enc"))
309
+ end
268
310
  end
269
311
  end
270
312
  end
@@ -13,6 +13,8 @@ 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
17
+
16
18
  if config.force_ssl
17
19
  middleware.use ::ActionDispatch::SSL, config.ssl_options
18
20
  end
@@ -172,14 +172,9 @@ module Rails
172
172
  def key_generator
173
173
  # number of iterations selected based on consultation with the google security
174
174
  # team. Details at https://github.com/rails/rails/pull/6952#issuecomment-7661220
175
- @caching_key_generator ||=
176
- if secret_key_base
177
- ActiveSupport::CachingKeyGenerator.new(
178
- ActiveSupport::KeyGenerator.new(secret_key_base, iterations: 1000)
179
- )
180
- else
181
- ActiveSupport::LegacyKeyGenerator.new(secrets.secret_token)
182
- end
175
+ @caching_key_generator ||= ActiveSupport::CachingKeyGenerator.new(
176
+ ActiveSupport::KeyGenerator.new(secret_key_base, iterations: 1000)
177
+ )
183
178
  end
184
179
 
185
180
  # Returns a message verifier object.
@@ -232,7 +227,12 @@ module Rails
232
227
 
233
228
  if yaml.exist?
234
229
  require "erb"
235
- (YAML.load(ERB.new(yaml.read).result) || {})[env] || {}
230
+ config = YAML.load(ERB.new(yaml.read).result) || {}
231
+ config = (config["shared"] || {}).merge(config[env] || {})
232
+
233
+ ActiveSupport::OrderedOptions.new.tap do |config_as_ordered_options|
234
+ config_as_ordered_options.update(config.deep_symbolize_keys)
235
+ end
236
236
  else
237
237
  raise "Could not load configuration. No such file - #{yaml}"
238
238
  end
@@ -249,7 +249,6 @@ module Rails
249
249
  super.merge(
250
250
  "action_dispatch.parameter_filter" => config.filter_parameters,
251
251
  "action_dispatch.redirect_filter" => config.filter_redirect,
252
- "action_dispatch.secret_token" => secrets.secret_token,
253
252
  "action_dispatch.secret_key_base" => secret_key_base,
254
253
  "action_dispatch.show_exceptions" => config.action_dispatch.show_exceptions,
255
254
  "action_dispatch.show_detailed_exceptions" => config.consider_all_requests_local,
@@ -267,6 +266,7 @@ module Rails
267
266
  "action_dispatch.cookies_serializer" => config.action_dispatch.cookies_serializer,
268
267
  "action_dispatch.cookies_digest" => config.action_dispatch.cookies_digest,
269
268
  "action_dispatch.cookies_rotations" => config.action_dispatch.cookies_rotations,
269
+ "action_dispatch.use_cookies_with_metadata" => config.action_dispatch.use_cookies_with_metadata,
270
270
  "action_dispatch.content_security_policy" => config.content_security_policy,
271
271
  "action_dispatch.content_security_policy_report_only" => config.content_security_policy_report_only,
272
272
  "action_dispatch.content_security_policy_nonce_generator" => config.content_security_policy_nonce_generator
@@ -373,9 +373,7 @@ module Rails
373
373
  @config ||= Application::Configuration.new(self.class.find_root(self.class.called_from))
374
374
  end
375
375
 
376
- def config=(configuration) #:nodoc:
377
- @config = configuration
378
- end
376
+ attr_writer :config
379
377
 
380
378
  # Returns secrets added to config/secrets.yml.
381
379
  #
@@ -400,22 +398,12 @@ module Rails
400
398
 
401
399
  # Fallback to config.secret_key_base if secrets.secret_key_base isn't set
402
400
  secrets.secret_key_base ||= config.secret_key_base
403
- # Fallback to config.secret_token if secrets.secret_token isn't set
404
- secrets.secret_token ||= config.secret_token
405
-
406
- if secrets.secret_token.present?
407
- ActiveSupport::Deprecation.warn(
408
- "`secrets.secret_token` is deprecated in favor of `secret_key_base` and will be removed in Rails 6.0."
409
- )
410
- end
411
401
 
412
402
  secrets
413
403
  end
414
404
  end
415
405
 
416
- def secrets=(secrets) #:nodoc:
417
- @secrets = secrets
418
- end
406
+ attr_writer :secrets
419
407
 
420
408
  # The secret_key_base is used as the input secret to the application's key generator, which in turn
421
409
  # is used to create all MessageVerifiers/MessageEncryptors, including the ones that sign and encrypt cookies.
@@ -426,8 +414,8 @@ module Rails
426
414
  # then credentials.secret_key_base, and finally secrets.secret_key_base. For most applications,
427
415
  # the correct place to store it is in the encrypted credentials file.
428
416
  def secret_key_base
429
- if Rails.env.development? || Rails.env.test?
430
- secrets.secret_key_base ||= generate_development_secret
417
+ if Rails.env.test? || Rails.env.development?
418
+ secrets.secret_key_base || Digest::MD5.hexdigest(self.class.name)
431
419
  else
432
420
  validate_secret_key_base(
433
421
  ENV["SECRET_KEY_BASE"] || credentials.secret_key_base || secrets.secret_key_base
@@ -438,13 +426,17 @@ module Rails
438
426
  # Decrypts the credentials hash as kept in +config/credentials.yml.enc+. This file is encrypted with
439
427
  # the Rails master key, which is either taken from <tt>ENV["RAILS_MASTER_KEY"]</tt> or from loading
440
428
  # +config/master.key+.
429
+ # If specific credentials file exists for current environment, it takes precedence, thus for +production+
430
+ # environment look first for +config/credentials/production.yml.enc+ with master key taken
431
+ # from <tt>ENV["RAILS_MASTER_KEY"]</tt> or from loading +config/credentials/production.key+.
432
+ # Default behavior can be overwritten by setting +config.credentials.content_path+ and +config.credentials.key_path+.
441
433
  def credentials
442
- @credentials ||= encrypted("config/credentials.yml.enc")
434
+ @credentials ||= encrypted(config.credentials.content_path, key_path: config.credentials.key_path)
443
435
  end
444
436
 
445
437
  # Shorthand to decrypt any encrypted configurations or files.
446
438
  #
447
- # For any file added with <tt>bin/rails encrypted:edit</tt> call +read+ to decrypt
439
+ # For any file added with <tt>rails encrypted:edit</tt> call +read+ to decrypt
448
440
  # the file with the master key.
449
441
  # The master key is either stored in +config/master.key+ or <tt>ENV["RAILS_MASTER_KEY"]</tt>.
450
442
  #
@@ -581,29 +573,13 @@ module Rails
581
573
  secret_key_base
582
574
  elsif secret_key_base
583
575
  raise ArgumentError, "`secret_key_base` for #{Rails.env} environment must be a type of String`"
584
- elsif secrets.secret_token.blank?
576
+ else
585
577
  raise ArgumentError, "Missing `secret_key_base` for '#{Rails.env}' environment, set this string with `rails credentials:edit`"
586
578
  end
587
579
  end
588
580
 
589
581
  private
590
582
 
591
- def generate_development_secret
592
- if secrets.secret_key_base.nil?
593
- key_file = Rails.root.join("tmp/development_secret.txt")
594
-
595
- if !File.exist?(key_file)
596
- random_key = SecureRandom.hex(64)
597
- FileUtils.mkdir_p(key_file.dirname)
598
- File.binwrite(key_file, random_key)
599
- end
600
-
601
- secrets.secret_key_base = File.binread(key_file)
602
- end
603
-
604
- secrets.secret_key_base
605
- end
606
-
607
583
  def build_request(env)
608
584
  req = super
609
585
  env["ORIGINAL_FULLPATH"] = req.fullpath
@@ -5,30 +5,18 @@ require "active_support/backtrace_cleaner"
5
5
  module Rails
6
6
  class BacktraceCleaner < ActiveSupport::BacktraceCleaner
7
7
  APP_DIRS_PATTERN = /^\/?(app|config|lib|test|\(\w*\))/
8
- RENDER_TEMPLATE_PATTERN = /:in `_render_template_\w*'/
9
- EMPTY_STRING = "".freeze
10
- SLASH = "/".freeze
11
- DOT_SLASH = "./".freeze
8
+ RENDER_TEMPLATE_PATTERN = /:in `.*_\w+_{2,3}\d+_\d+'/
9
+ EMPTY_STRING = ""
10
+ SLASH = "/"
11
+ DOT_SLASH = "./"
12
12
 
13
13
  def initialize
14
14
  super
15
- @root = "#{Rails.root}/".freeze
15
+ @root = "#{Rails.root}/"
16
16
  add_filter { |line| line.sub(@root, EMPTY_STRING) }
17
17
  add_filter { |line| line.sub(RENDER_TEMPLATE_PATTERN, EMPTY_STRING) }
18
18
  add_filter { |line| line.sub(DOT_SLASH, SLASH) } # for tests
19
-
20
- add_gem_filters
21
19
  add_silencer { |line| !APP_DIRS_PATTERN.match?(line) }
22
20
  end
23
-
24
- private
25
- def add_gem_filters
26
- gems_paths = (Gem.path | [Gem.default_dir]).map { |p| Regexp.escape(p) }
27
- return if gems_paths.empty?
28
-
29
- gems_regexp = %r{(#{gems_paths.join('|')})/gems/([^/]+)-([\w.]+)/(.*)}
30
- gems_result = '\2 (\3) \4'.freeze
31
- add_filter { |line| line.sub(gems_regexp, gems_result) }
32
- end
33
21
  end
34
22
  end
@@ -46,7 +46,7 @@ class CodeStatistics #:nodoc:
46
46
 
47
47
  if File.directory?(path) && (/^\./ !~ file_name)
48
48
  stats.add(calculate_directory_statistics(path, pattern))
49
- elsif file_name =~ pattern
49
+ elsif file_name&.match?(pattern)
50
50
  stats.add_by_file_path(path)
51
51
  end
52
52
  end
@@ -95,8 +95,8 @@ class CodeStatistics #:nodoc:
95
95
  end
96
96
 
97
97
  def print_line(name, statistics)
98
- m_over_c = (statistics.methods / statistics.classes) rescue m_over_c = 0
99
- loc_over_m = (statistics.code_lines / statistics.methods) - 2 rescue loc_over_m = 0
98
+ m_over_c = (statistics.methods / statistics.classes) rescue 0
99
+ loc_over_m = (statistics.code_lines / statistics.methods) - 2 rescue 0
100
100
 
101
101
  print "| #{name.ljust(20)} "
102
102
  HEADERS.each_key do |k|
@@ -11,20 +11,10 @@ module Rails
11
11
  end
12
12
 
13
13
  def require_application_and_environment!
14
- require_application!
15
- require_environment!
16
- end
17
-
18
- def require_application!
19
14
  require ENGINE_PATH if defined?(ENGINE_PATH)
20
15
 
21
16
  if defined?(APP_PATH)
22
17
  require APP_PATH
23
- end
24
- end
25
-
26
- def require_environment!
27
- if defined?(APP_PATH)
28
18
  Rails.application.require_environment!
29
19
  end
30
20
  end
@@ -17,10 +17,6 @@ module Rails
17
17
  include Actions
18
18
 
19
19
  class << self
20
- def exit_on_failure? # :nodoc:
21
- false
22
- end
23
-
24
20
  # Returns true when the app is a Rails engine.
25
21
  def engine?
26
22
  defined?(ENGINE_ROOT)
@@ -74,7 +70,7 @@ module Rails
74
70
  end
75
71
 
76
72
  def executable
77
- "bin/rails #{command_name}"
73
+ "rails #{command_name}"
78
74
  end
79
75
 
80
76
  # Use Rails' default banner.
@@ -19,46 +19,6 @@ module Rails
19
19
  end
20
20
 
21
21
  private
22
-
23
- # This code is based directly on the Text gem implementation.
24
- # Copyright (c) 2006-2013 Paul Battley, Michael Neumann, Tim Fletcher.
25
- #
26
- # Returns a value representing the "cost" of transforming str1 into str2.
27
- def levenshtein_distance(str1, str2) # :doc:
28
- s = str1
29
- t = str2
30
- n = s.length
31
- m = t.length
32
-
33
- return m if (0 == n)
34
- return n if (0 == m)
35
-
36
- d = (0..m).to_a
37
- x = nil
38
-
39
- # avoid duplicating an enumerable object in the loop
40
- str2_codepoint_enumerable = str2.each_codepoint
41
-
42
- str1.each_codepoint.with_index do |char1, i|
43
- e = i + 1
44
-
45
- str2_codepoint_enumerable.with_index do |char2, j|
46
- cost = (char1 == char2) ? 0 : 1
47
- x = [
48
- d[j + 1] + 1, # insertion
49
- e + 1, # deletion
50
- d[j] + cost # substitution
51
- ].min
52
- d[j] = e
53
- e = x
54
- end
55
-
56
- d[m] = x
57
- end
58
-
59
- x
60
- end
61
-
62
22
  # Prints a list of generators.
63
23
  def print_list(base, namespaces)
64
24
  return if namespaces.empty?
@@ -96,12 +56,10 @@ module Rails
96
56
  def lookup!
97
57
  $LOAD_PATH.each do |base|
98
58
  Dir[File.join(base, *file_lookup_paths)].each do |path|
99
- begin
100
- path = path.sub("#{base}/", "")
101
- require path
102
- rescue Exception
103
- # No problem
104
- end
59
+ path = path.sub("#{base}/", "")
60
+ require path
61
+ rescue Exception
62
+ # No problem
105
63
  end
106
64
  end
107
65
  end
@@ -8,23 +8,13 @@ module Rails
8
8
  extend ActiveSupport::Concern
9
9
 
10
10
  included do
11
- argument :environment, optional: true, banner: "environment"
12
-
13
11
  class_option :environment, aliases: "-e", type: :string,
14
12
  desc: "Specifies the environment to run this console under (test/development/production)."
15
13
  end
16
14
 
17
15
  private
18
16
  def extract_environment_option_from_argument
19
- if environment
20
- self.options = options.merge(environment: acceptable_environment(environment))
21
-
22
- ActiveSupport::Deprecation.warn "Passing the environment's name as a " \
23
- "regular argument is deprecated and " \
24
- "will be removed in the next Rails " \
25
- "version. Please, use the -e option " \
26
- "instead."
27
- elsif options[:environment]
17
+ if options[:environment]
28
18
  self.options = options.merge(environment: acceptable_environment(options[:environment]))
29
19
  else
30
20
  self.options = options.merge(environment: Rails::Command.environment)
@@ -0,0 +1,58 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Rails
4
+ module Command
5
+ module Spellchecker # :nodoc:
6
+ class << self
7
+ def suggest(word, from:)
8
+ if defined?(DidYouMean::SpellChecker)
9
+ DidYouMean::SpellChecker.new(dictionary: from.map(&:to_s)).correct(word).first
10
+ else
11
+ from.sort_by { |w| levenshtein_distance(word, w) }.first
12
+ end
13
+ end
14
+
15
+ private
16
+
17
+ # This code is based directly on the Text gem implementation.
18
+ # Copyright (c) 2006-2013 Paul Battley, Michael Neumann, Tim Fletcher.
19
+ #
20
+ # Returns a value representing the "cost" of transforming str1 into str2.
21
+ def levenshtein_distance(str1, str2) # :doc:
22
+ s = str1
23
+ t = str2
24
+ n = s.length
25
+ m = t.length
26
+
27
+ return m if 0 == n
28
+ return n if 0 == m
29
+
30
+ d = (0..m).to_a
31
+ x = nil
32
+
33
+ # avoid duplicating an enumerable object in the loop
34
+ str2_codepoint_enumerable = str2.each_codepoint
35
+
36
+ str1.each_codepoint.with_index do |char1, i|
37
+ e = i + 1
38
+
39
+ str2_codepoint_enumerable.with_index do |char2, j|
40
+ cost = (char1 == char2) ? 0 : 1
41
+ x = [
42
+ d[j + 1] + 1, # insertion
43
+ e + 1, # deletion
44
+ d[j] + cost # substitution
45
+ ].min
46
+ d[j] = e
47
+ e = x
48
+ end
49
+
50
+ d[m] = x
51
+ end
52
+
53
+ x
54
+ end
55
+ end
56
+ end
57
+ end
58
+ end