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
@@ -52,6 +52,9 @@ module Rails
52
52
  class_option :skip_active_record, type: :boolean, aliases: "-O", default: false,
53
53
  desc: "Skip Active Record files"
54
54
 
55
+ class_option :skip_active_job, type: :boolean, default: false,
56
+ desc: "Skip Active Job"
57
+
55
58
  class_option :skip_active_storage, type: :boolean, default: false,
56
59
  desc: "Skip Active Storage files"
57
60
 
@@ -76,6 +79,9 @@ module Rails
76
79
  class_option :skip_turbolinks, type: :boolean, default: false,
77
80
  desc: "Skip turbolinks gem"
78
81
 
82
+ class_option :skip_jbuilder, type: :boolean, default: false,
83
+ desc: "Skip jbuilder gem"
84
+
79
85
  class_option :skip_test, type: :boolean, aliases: "-T", default: false,
80
86
  desc: "Skip test files"
81
87
 
@@ -86,10 +92,13 @@ module Rails
86
92
  desc: "Skip bootsnap gem"
87
93
 
88
94
  class_option :dev, type: :boolean, default: false,
89
- desc: "Setup the #{name} with Gemfile pointing to your Rails checkout"
95
+ desc: "Set up the #{name} with Gemfile pointing to your Rails checkout"
90
96
 
91
97
  class_option :edge, type: :boolean, default: false,
92
- desc: "Setup the #{name} with Gemfile pointing to Rails repository"
98
+ desc: "Set up the #{name} with Gemfile pointing to Rails repository"
99
+
100
+ class_option :master, type: :boolean, default: false,
101
+ desc: "Set up the #{name} with Gemfile pointing to Rails repository main branch"
93
102
 
94
103
  class_option :rc, type: :string, default: nil,
95
104
  desc: "Path to file containing extra configuration options for rails command"
@@ -101,8 +110,9 @@ module Rails
101
110
  desc: "Show this help message and quit"
102
111
  end
103
112
 
104
- def initialize(*args)
105
- @gem_filter = lambda { |gem| true }
113
+ def initialize(positional_argv, option_argv, *)
114
+ @argv = [*positional_argv, *option_argv]
115
+ @gem_filter = lambda { |gem| true }
106
116
  @extra_entries = []
107
117
  super
108
118
  end
@@ -152,7 +162,7 @@ module Rails
152
162
  end
153
163
 
154
164
  def build(meth, *args) # :doc:
155
- builder.send(meth, *args) if builder.respond_to?(meth)
165
+ builder.public_send(meth, *args) if builder.respond_to?(meth)
156
166
  end
157
167
 
158
168
  def create_root # :doc:
@@ -163,9 +173,14 @@ module Rails
163
173
  end
164
174
 
165
175
  def apply_rails_template # :doc:
176
+ original_argv = ARGV.dup
177
+ ARGV.replace(@argv)
178
+
166
179
  apply rails_template if rails_template
167
180
  rescue Thor::Error, LoadError, Errno::ENOENT => e
168
181
  raise Error, "The template [#{rails_template}] could not be loaded. Error: #{e}"
182
+ ensure
183
+ ARGV.replace(original_argv)
169
184
  end
170
185
 
171
186
  def set_default_accessors! # :doc:
@@ -191,7 +206,7 @@ module Rails
191
206
  def web_server_gemfile_entry # :doc:
192
207
  return [] if options[:skip_puma]
193
208
  comment = "Use Puma as the app server"
194
- GemfileEntry.new("puma", "~> 4.1", comment)
209
+ GemfileEntry.new("puma", "~> 5.0", comment)
195
210
  end
196
211
 
197
212
  def include_all_railties? # :doc:
@@ -201,7 +216,8 @@ module Rails
201
216
  :skip_action_mailer,
202
217
  :skip_test,
203
218
  :skip_sprockets,
204
- :skip_action_cable
219
+ :skip_action_cable,
220
+ :skip_active_job
205
221
  ),
206
222
  skip_active_storage?,
207
223
  skip_action_mailbox?,
@@ -242,6 +258,10 @@ module Rails
242
258
  options[:skip_action_text] || skip_active_storage?
243
259
  end
244
260
 
261
+ def skip_dev_gems? # :doc:
262
+ options[:skip_dev_gems]
263
+ end
264
+
245
265
  class GemfileEntry < Struct.new(:name, :version, :comment, :options, :commented_out)
246
266
  def initialize(name, version, comment, options = {}, commented_out = false)
247
267
  super
@@ -281,7 +301,11 @@ module Rails
281
301
  ]
282
302
  elsif options.edge?
283
303
  [
284
- GemfileEntry.github("rails", "rails/rails", "6-0-stable")
304
+ GemfileEntry.github("rails", "rails/rails", "6-1-stable")
305
+ ]
306
+ elsif options.master?
307
+ [
308
+ GemfileEntry.github("rails", "rails/rails", "main")
285
309
  ]
286
310
  else
287
311
  [GemfileEntry.version("rails",
@@ -312,14 +336,11 @@ module Rails
312
336
  def webpacker_gemfile_entry
313
337
  return [] if options[:skip_javascript]
314
338
 
315
- if options.dev? || options.edge?
316
- GemfileEntry.github "webpacker", "rails/webpacker", nil, "Use development version of Webpacker"
317
- else
318
- GemfileEntry.version "webpacker", "~> 4.0", "Transpile app-like JavaScript. Read more: https://github.com/rails/webpacker"
319
- end
339
+ GemfileEntry.version "webpacker", "~> 5.0", "Transpile app-like JavaScript. Read more: https://github.com/rails/webpacker"
320
340
  end
321
341
 
322
342
  def jbuilder_gemfile_entry
343
+ return [] if options[:skip_jbuilder]
323
344
  comment = "Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder"
324
345
  GemfileEntry.new "jbuilder", "~> 2.7", comment, {}, options[:api]
325
346
  end
@@ -400,7 +421,7 @@ module Rails
400
421
  end
401
422
 
402
423
  def os_supports_listen_out_of_the_box?
403
- RbConfig::CONFIG["host_os"] =~ /darwin|linux/
424
+ /darwin|linux/.match?(RbConfig::CONFIG["host_os"])
404
425
  end
405
426
 
406
427
  def run_bundle
@@ -408,9 +429,19 @@ module Rails
408
429
  end
409
430
 
410
431
  def run_webpack
411
- if webpack_install?
412
- rails_command "webpacker:install"
413
- rails_command "webpacker:install:#{options[:webpack]}" if options[:webpack] && options[:webpack] != "webpack"
432
+ return unless webpack_install?
433
+
434
+ unless bundle_install?
435
+ say <<~EXPLAIN
436
+ Skipping `rails webpacker:install` because `bundle install` was skipped.
437
+ To complete setup, you must run `bundle install` followed by `rails webpacker:install`.
438
+ EXPLAIN
439
+ return
440
+ end
441
+
442
+ rails_command "webpacker:install"
443
+ if options[:webpack] && options[:webpack] != "webpack"
444
+ rails_command "webpacker:install:#{options[:webpack]}"
414
445
  end
415
446
  end
416
447
 
@@ -420,12 +451,6 @@ module Rails
420
451
  end
421
452
  end
422
453
 
423
- def generate_spring_binstubs
424
- if bundle_install? && spring_install?
425
- bundle_command("exec spring binstub --all")
426
- end
427
- end
428
-
429
454
  def empty_directory_with_keep_file(destination, config = {})
430
455
  empty_directory(destination, config)
431
456
  keep_file(destination)
@@ -19,7 +19,9 @@ module Rails
19
19
  include Rails::Generators::Actions
20
20
 
21
21
  class_option :skip_namespace, type: :boolean, default: false,
22
- desc: "Skip namespace (affects only isolated applications)"
22
+ desc: "Skip namespace (affects only isolated engines)"
23
+ class_option :skip_collision_check, type: :boolean, default: false,
24
+ desc: "Skip collision check"
23
25
 
24
26
  add_runtime_options!
25
27
  strict_args_position!
@@ -51,7 +53,7 @@ module Rails
51
53
  # is removed.
52
54
  def self.namespace(name = nil)
53
55
  return super if name
54
- @namespace ||= super.sub(/_generator$/, "").sub(/:generators:/, ":")
56
+ @namespace ||= super.delete_suffix("_generator").sub(/:generators:/, ":")
55
57
  end
56
58
 
57
59
  # Convenience method to hide this generator from the available ones when
@@ -77,7 +79,7 @@ module Rails
77
79
  #
78
80
  # For example, if the user invoke the controller generator as:
79
81
  #
80
- # rails generate controller Account --test-framework=test_unit
82
+ # bin/rails generate controller Account --test-framework=test_unit
81
83
  #
82
84
  # The controller generator will then try to invoke the following generators:
83
85
  #
@@ -132,11 +134,11 @@ module Rails
132
134
  # All hooks come with switches for user interface. If you do not want
133
135
  # to use any test framework, you can do:
134
136
  #
135
- # rails generate controller Account --skip-test-framework
137
+ # bin/rails generate controller Account --skip-test-framework
136
138
  #
137
139
  # Or similarly:
138
140
  #
139
- # rails generate controller Account --no-test-framework
141
+ # bin/rails generate controller Account --no-test-framework
140
142
  #
141
143
  # ==== Boolean hooks
142
144
  #
@@ -148,7 +150,7 @@ module Rails
148
150
  #
149
151
  # Then, if you want webrat to be invoked, just supply:
150
152
  #
151
- # rails generate controller Account --webrat
153
+ # bin/rails generate controller Account --webrat
152
154
  #
153
155
  # The hooks lookup is similar as above:
154
156
  #
@@ -235,7 +237,7 @@ module Rails
235
237
  # Invoke source_root so the default_source_root is set.
236
238
  base.source_root
237
239
 
238
- if base.name && base.name !~ /Base$/
240
+ if base.name && !base.name.end_with?("Base")
239
241
  Rails::Generators.subclasses << base
240
242
 
241
243
  Rails::Generators.templates_path.each do |path|
@@ -253,6 +255,7 @@ module Rails
253
255
  # application or Ruby on Rails.
254
256
  def class_collisions(*class_names)
255
257
  return unless behavior == :invoke
258
+ return if options.skip_collision_check?
256
259
  return if options.force?
257
260
 
258
261
  class_names.flatten.each do |class_name|
@@ -266,8 +269,8 @@ module Rails
266
269
 
267
270
  if last && last.const_defined?(last_name.camelize, false)
268
271
  raise Error, "The name '#{class_name}' is either already used in your application " \
269
- "or reserved by Ruby on Rails. Please choose an alternative or use " \
270
- "--force to skip this check and run this generator again."
272
+ "or reserved by Ruby on Rails. Please choose an alternative or use --skip-collision-check " \
273
+ "or --force to skip this check and run this generator again."
271
274
  end
272
275
  end
273
276
  end
@@ -316,7 +319,7 @@ module Rails
316
319
 
317
320
  # Use Rails default banner.
318
321
  def self.banner # :doc:
319
- "rails generate #{namespace.sub(/^rails:/, '')} #{arguments.map(&:usage).join(' ')} [options]".gsub(/\s+/, " ")
322
+ "rails generate #{namespace.delete_prefix("rails:")} #{arguments.map(&:usage).join(' ')} [options]".gsub(/\s+/, " ")
320
323
  end
321
324
 
322
325
  # Sets the base_name taking into account the current class namespace.
@@ -333,7 +336,7 @@ module Rails
333
336
  def self.generator_name # :doc:
334
337
  @generator_name ||= begin
335
338
  if generator = name.to_s.split("::").last
336
- generator.sub!(/Generator$/, "")
339
+ generator.delete_suffix!("Generator")
337
340
  generator.underscore
338
341
  end
339
342
  end
@@ -4,7 +4,7 @@ module Rails
4
4
  module Generators
5
5
  module Database # :nodoc:
6
6
  JDBC_DATABASES = %w( jdbcmysql jdbcsqlite3 jdbcpostgresql jdbc )
7
- DATABASES = %w( mysql postgresql sqlite3 oracle frontbase ibm_db sqlserver ) + JDBC_DATABASES
7
+ DATABASES = %w( mysql postgresql sqlite3 oracle sqlserver ) + JDBC_DATABASES
8
8
 
9
9
  def initialize(*)
10
10
  super
@@ -13,11 +13,10 @@ module Rails
13
13
 
14
14
  def gem_for_database(database = options[:database])
15
15
  case database
16
- when "mysql" then ["mysql2", [">= 0.4.4"]]
17
- when "postgresql" then ["pg", [">= 0.18", "< 2.0"]]
16
+ when "mysql" then ["mysql2", ["~> 0.5"]]
17
+ when "postgresql" then ["pg", ["~> 1.1"]]
18
18
  when "sqlite3" then ["sqlite3", ["~> 1.4"]]
19
19
  when "oracle" then ["activerecord-oracle_enhanced-adapter", nil]
20
- when "frontbase" then ["ruby-frontbase", nil]
21
20
  when "sqlserver" then ["activerecord-sqlserver-adapter", nil]
22
21
  when "jdbcmysql" then ["activerecord-jdbcmysql-adapter", nil]
23
22
  when "jdbcsqlite3" then ["activerecord-jdbcsqlite3-adapter", nil]
@@ -1,11 +1,11 @@
1
- <%%= form_with(model: <%= model_resource_name %>, local: true) do |form| %>
1
+ <%%= form_with(model: <%= model_resource_name %>) do |form| %>
2
2
  <%% if <%= singular_table_name %>.errors.any? %>
3
3
  <div id="error_explanation">
4
4
  <h2><%%= pluralize(<%= singular_table_name %>.errors.count, "error") %> prohibited this <%= singular_table_name %> from being saved:</h2>
5
5
 
6
6
  <ul>
7
- <%% <%= singular_table_name %>.errors.full_messages.each do |message| %>
8
- <li><%%= message %></li>
7
+ <%% <%= singular_table_name %>.errors.each do |error| %>
8
+ <li><%%= error.full_message %></li>
9
9
  <%% end %>
10
10
  </ul>
11
11
  </div>
@@ -1,7 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "active_support/time"
4
- require "active_support/deprecation"
5
4
 
6
5
  module Rails
7
6
  module Generators
@@ -52,11 +51,6 @@ module Rails
52
51
  provided_options = $2.split(/[,.-]/)
53
52
  options = Hash[provided_options.map { |opt| [opt.to_sym, true] }]
54
53
 
55
- if options[:required]
56
- ActiveSupport::Deprecation.warn("Passing {required} option has no effect on the model generator. It will be removed in Rails 6.1.\n")
57
- options.delete(:required)
58
- end
59
-
60
54
  return type, options
61
55
  else
62
56
  return type, {}
@@ -107,11 +101,11 @@ module Rails
107
101
  end
108
102
 
109
103
  def plural_name
110
- name.sub(/_id$/, "").pluralize
104
+ name.delete_suffix("_id").pluralize
111
105
  end
112
106
 
113
107
  def singular_name
114
- name.sub(/_id$/, "").singularize
108
+ name.delete_suffix("_id").singularize
115
109
  end
116
110
 
117
111
  def human_name
@@ -131,7 +125,7 @@ module Rails
131
125
  end
132
126
 
133
127
  def foreign_key?
134
- !!(name =~ /_id$/)
128
+ name.end_with?("_id")
135
129
  end
136
130
 
137
131
  def reference?
@@ -62,13 +62,14 @@ module Rails
62
62
  dir, base = File.split(destination)
63
63
  numbered_destination = File.join(dir, ["%migration_number%", base].join("_"))
64
64
 
65
- create_migration numbered_destination, nil, config do
65
+ file = create_migration numbered_destination, nil, config do
66
66
  if ERB.instance_method(:initialize).parameters.assoc(:key) # Ruby 2.6+
67
67
  ERB.new(::File.binread(source), trim_mode: "-", eoutvar: "@output_buffer").result(context)
68
68
  else
69
69
  ERB.new(::File.binread(source), nil, "-", "@output_buffer").result(context)
70
70
  end
71
71
  end
72
+ Rails::Generators.add_generated_file(file)
72
73
  end
73
74
  end
74
75
  end
@@ -11,6 +11,11 @@ module Rails
11
11
  [WARNING] Rails cannot recover singular form from its plural form '%s'.
12
12
  Please setup custom inflection rules for this noun before running the generator in config/initializers/inflections.rb.
13
13
  WARNING
14
+ INFLECTION_IMPOSSIBLE_ERROR_MESSAGE = <<~ERROR
15
+ Rails cannot recover the underscored form from its camelcase form '%s'.
16
+ Please use an underscored name instead, either '%s' or '%s'.
17
+ Or setup custom inflection rules for this noun before running the generator in config/initializers/inflections.rb.
18
+ ERROR
14
19
  mattr_accessor :skip_warn
15
20
 
16
21
  def self.included(base) #:nodoc:
@@ -19,7 +24,7 @@ module Rails
19
24
 
20
25
  def initialize(args, *_options)
21
26
  super
22
- if name == name.pluralize && name.singularize != name.pluralize && !options[:force_plural]
27
+ if plural_model_name?(name) && !options[:force_plural]
23
28
  singular = name.singularize
24
29
  unless ModelHelpers.skip_warn
25
30
  say PLURAL_MODEL_NAME_WARN_MESSAGE % [name, singular]
@@ -27,11 +32,30 @@ module Rails
27
32
  name.replace singular
28
33
  assign_names!(name)
29
34
  end
30
- if name.singularize != name.pluralize.singularize && ! ModelHelpers.skip_warn
35
+ if inflection_impossible?(name)
36
+ option1 = name.singularize.underscore
37
+ option2 = name.pluralize.underscore.singularize
38
+ raise Error, INFLECTION_IMPOSSIBLE_ERROR_MESSAGE % [name, option1, option2]
39
+ end
40
+ if irregular_model_name?(name) && ! ModelHelpers.skip_warn
31
41
  say IRREGULAR_MODEL_NAME_WARN_MESSAGE % [name.pluralize]
32
42
  end
33
43
  ModelHelpers.skip_warn = true
34
44
  end
45
+
46
+ private
47
+ def plural_model_name?(name)
48
+ name == name.pluralize && name.singularize != name.pluralize
49
+ end
50
+
51
+ def irregular_model_name?(name)
52
+ name.singularize != name.pluralize.singularize
53
+ end
54
+
55
+ def inflection_impossible?(name)
56
+ name != name.underscore &&
57
+ name.singularize.underscore != name.pluralize.underscore.singularize
58
+ end
35
59
  end
36
60
  end
37
61
  end
@@ -22,7 +22,7 @@ module Rails
22
22
  no_tasks do
23
23
  def template(source, *args, &block)
24
24
  inside_template do
25
- super
25
+ Rails::Generators.add_generated_file(super)
26
26
  end
27
27
  end
28
28
 
@@ -3,7 +3,8 @@ Description:
3
3
  directory structure and configuration at the path you specify.
4
4
 
5
5
  You can specify extra command-line arguments to be used every time
6
- 'rails new' runs in the .railsrc configuration file in your home directory.
6
+ 'rails new' runs in the .railsrc configuration file in your home directory,
7
+ or in $XDG_CONFIG_HOME/rails/railsrc if XDG_CONFIG_HOME is set.
7
8
 
8
9
  Note that the arguments specified in the .railsrc file don't affect the
9
10
  defaults values shown above in this help message.
@@ -66,6 +66,10 @@ module Rails
66
66
  template "gitignore", ".gitignore"
67
67
  end
68
68
 
69
+ def gitattributes
70
+ template "gitattributes", ".gitattributes"
71
+ end
72
+
69
73
  def version_control
70
74
  if !options[:skip_git] && !options[:pretend]
71
75
  run "git init", capture: options[:quiet], abort_on_failure: false
@@ -90,14 +94,21 @@ module Rails
90
94
  "#{shebang}\n" + content
91
95
  end
92
96
  chmod "bin", 0755 & ~File.umask, verbose: false
97
+
98
+ remove_file "bin/spring" unless spring_install?
99
+ remove_file "bin/yarn" if options[:skip_javascript]
93
100
  end
94
101
 
95
102
  def bin_when_updating
96
103
  bin
104
+ end
97
105
 
98
- if options[:skip_javascript]
99
- remove_file "bin/yarn"
106
+ def yarn_when_updating
107
+ template "bin/yarn", force: true do |content|
108
+ "#{shebang}\n" + content
100
109
  end
110
+
111
+ chmod "bin", 0755 & ~File.umask, verbose: false
101
112
  end
102
113
 
103
114
  def config
@@ -125,10 +136,12 @@ module Rails
125
136
  rack_cors_config_exist = File.exist?("config/initializers/cors.rb")
126
137
  assets_config_exist = File.exist?("config/initializers/assets.rb")
127
138
  csp_config_exist = File.exist?("config/initializers/content_security_policy.rb")
139
+ permissions_policy_config_exist = File.exist?("config/initializers/permissions_policy.rb")
128
140
 
129
141
  @config_target_version = Rails.application.config.loaded_config_version || "5.0"
130
142
 
131
143
  config
144
+ configru
132
145
 
133
146
  unless cookie_serializer_config_exist
134
147
  gsub_file "config/initializers/cookies_serializer.rb", /json(?!,)/, "marshal"
@@ -158,6 +171,10 @@ module Rails
158
171
  unless csp_config_exist
159
172
  remove_file "config/initializers/content_security_policy.rb"
160
173
  end
174
+
175
+ unless permissions_policy_config_exist
176
+ remove_file "config/initializers/permissions_policy.rb"
177
+ end
161
178
  end
162
179
  end
163
180
 
@@ -205,7 +222,6 @@ module Rails
205
222
  end
206
223
 
207
224
  def test
208
- empty_directory_with_keep_file "test/fixtures"
209
225
  empty_directory_with_keep_file "test/fixtures/files"
210
226
  empty_directory_with_keep_file "test/controllers"
211
227
  empty_directory_with_keep_file "test/mailers"
@@ -244,7 +260,9 @@ module Rails
244
260
  # can change in Ruby 1.8.7 when we FileUtils.cd.
245
261
  RAILS_DEV_PATH = File.expand_path("../../../../../..", __dir__)
246
262
 
247
- class AppGenerator < AppBase # :nodoc:
263
+ class AppGenerator < AppBase
264
+ # :stopdoc:
265
+
248
266
  WEBPACKS = %w( react vue angular elm stimulus )
249
267
 
250
268
  add_shared_options_for "application"
@@ -256,6 +274,9 @@ module Rails
256
274
  class_option :api, type: :boolean,
257
275
  desc: "Preconfigure smaller stack for API only apps"
258
276
 
277
+ class_option :minimal, type: :boolean,
278
+ desc: "Preconfigure a minimal rails app"
279
+
259
280
  class_option :skip_bundle, type: :boolean, aliases: "-B", default: false,
260
281
  desc: "Don't run bundle install"
261
282
 
@@ -278,6 +299,29 @@ module Rails
278
299
  self.options = options.merge(skip_sprockets: true, skip_javascript: true).freeze
279
300
  end
280
301
 
302
+ if options[:minimal]
303
+ self.options = options.merge(
304
+ skip_action_cable: true,
305
+ skip_action_mailer: true,
306
+ skip_action_mailbox: true,
307
+ skip_action_text: true,
308
+ skip_active_job: true,
309
+ skip_active_storage: true,
310
+ skip_bootsnap: true,
311
+ skip_dev_gems: true,
312
+ skip_javascript: true,
313
+ skip_jbuilder: true,
314
+ skip_spring: true,
315
+ skip_system_test: true,
316
+ skip_webpack_install: true,
317
+ skip_turbolinks: true).tap do |option|
318
+ if option[:webpack]
319
+ option[:skip_webpack_install] = false
320
+ option[:skip_javascript] = false
321
+ end
322
+ end.freeze
323
+ end
324
+
281
325
  @after_bundle_callbacks = []
282
326
  end
283
327
 
@@ -289,8 +333,13 @@ module Rails
289
333
  build(:rakefile)
290
334
  build(:ruby_version)
291
335
  build(:configru)
292
- build(:gitignore) unless options[:skip_git]
293
- build(:gemfile) unless options[:skip_gemfile]
336
+
337
+ unless options[:skip_git]
338
+ build(:gitignore)
339
+ build(:gitattributes)
340
+ end
341
+
342
+ build(:gemfile) unless options[:skip_gemfile]
294
343
  build(:version_control)
295
344
  build(:package_json) unless options[:skip_javascript]
296
345
  end
@@ -308,9 +357,14 @@ module Rails
308
357
  end
309
358
  remove_task :update_bin_files
310
359
 
360
+ def update_bin_yarn
361
+ build(:yarn_when_updating)
362
+ end
363
+ remove_task :update_bin_yarn
364
+
311
365
  def update_active_storage
312
366
  unless skip_active_storage?
313
- rails_command "active_storage:update"
367
+ rails_command "active_storage:update", inline: true
314
368
  end
315
369
  end
316
370
  remove_task :update_active_storage
@@ -420,11 +474,18 @@ module Rails
420
474
  end
421
475
 
422
476
  def delete_js_folder_skipping_javascript
423
- if options[:skip_javascript]
477
+ if options[:skip_javascript] && !options[:minimal]
424
478
  remove_dir "app/javascript"
425
479
  end
426
480
  end
427
481
 
482
+ def delete_js_packs_when_minimal_skipping_webpack
483
+ if options[:minimal] && options[:skip_webpack_install]
484
+ remove_dir "app/javascript/packs"
485
+ keep_file "app/javascript"
486
+ end
487
+ end
488
+
428
489
  def delete_assets_initializer_skipping_sprockets
429
490
  if options[:skip_sprockets]
430
491
  remove_file "config/initializers/assets.rb"
@@ -437,6 +498,12 @@ module Rails
437
498
  end
438
499
  end
439
500
 
501
+ def delete_active_job_folder_if_skipping_active_job
502
+ if options[:skip_active_job]
503
+ remove_dir "app/jobs"
504
+ end
505
+ end
506
+
440
507
  def delete_action_mailer_files_skipping_action_mailer
441
508
  if options[:skip_action_mailer]
442
509
  remove_file "app/views/layouts/mailer.html.erb"
@@ -458,6 +525,7 @@ module Rails
458
525
  if options[:api]
459
526
  remove_file "config/initializers/cookies_serializer.rb"
460
527
  remove_file "config/initializers/content_security_policy.rb"
528
+ remove_file "config/initializers/permissions_policy.rb"
461
529
  end
462
530
  end
463
531
 
@@ -469,20 +537,16 @@ module Rails
469
537
 
470
538
  def delete_new_framework_defaults
471
539
  unless options[:update]
472
- remove_file "config/initializers/new_framework_defaults_6_0.rb"
540
+ remove_file "config/initializers/new_framework_defaults_6_1.rb"
473
541
  end
474
542
  end
475
543
 
476
- def delete_bin_yarn
477
- remove_file "bin/yarn" if options[:skip_javascript]
478
- end
479
-
480
544
  def finish_template
481
545
  build(:leftovers)
482
546
  end
483
547
 
484
548
  public_task :apply_rails_template, :run_bundle
485
- public_task :generate_bundler_binstub, :generate_spring_binstubs
549
+ public_task :generate_bundler_binstub
486
550
  public_task :run_webpack
487
551
 
488
552
  def run_after_bundle_callbacks
@@ -493,6 +557,8 @@ module Rails
493
557
  "rails new #{arguments.map(&:usage).join(' ')} [options]"
494
558
  end
495
559
 
560
+ # :startdoc:
561
+
496
562
  private
497
563
  # Define file as an alias to create_file for backwards compatibility.
498
564
  def file(*args, &block)
@@ -534,7 +600,13 @@ module Rails
534
600
  end
535
601
 
536
602
  def self.default_rc_file
537
- File.expand_path("~/.railsrc")
603
+ xdg_config_home = ENV["XDG_CONFIG_HOME"].presence || "~/.config"
604
+ xdg_railsrc = File.expand_path("rails/railsrc", xdg_config_home)
605
+ if File.exist?(xdg_railsrc)
606
+ xdg_railsrc
607
+ else
608
+ File.expand_path("~/.railsrc")
609
+ end
538
610
  end
539
611
 
540
612
  private