railties 6.1.7.8 → 7.0.8.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (164) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +219 -320
  3. data/RDOC_MAIN.rdoc +16 -16
  4. data/README.rdoc +1 -2
  5. data/lib/minitest/rails_plugin.rb +1 -1
  6. data/lib/rails/all.rb +0 -1
  7. data/lib/rails/app_updater.rb +9 -6
  8. data/lib/rails/application/bootstrap.rb +24 -5
  9. data/lib/rails/application/configuration.rb +95 -33
  10. data/lib/rails/application/default_middleware_stack.rb +22 -3
  11. data/lib/rails/application/finisher.rb +53 -95
  12. data/lib/rails/application/routes_reloader.rb +8 -0
  13. data/lib/rails/application.rb +74 -101
  14. data/lib/rails/application_controller.rb +3 -3
  15. data/lib/rails/autoloaders/inflector.rb +21 -0
  16. data/lib/rails/autoloaders.rb +42 -42
  17. data/lib/rails/code_statistics.rb +2 -2
  18. data/lib/rails/code_statistics_calculator.rb +10 -1
  19. data/lib/rails/command/base.rb +26 -12
  20. data/lib/rails/command/behavior.rb +1 -1
  21. data/lib/rails/command/environment_argument.rb +1 -1
  22. data/lib/rails/command.rb +9 -6
  23. data/lib/rails/commands/console/console_command.rb +4 -0
  24. data/lib/rails/commands/credentials/USAGE +4 -2
  25. data/lib/rails/commands/credentials/credentials_command/diffing.rb +26 -16
  26. data/lib/rails/commands/credentials/credentials_command.rb +7 -3
  27. data/lib/rails/commands/dbconsole/dbconsole_command.rb +10 -11
  28. data/lib/rails/commands/help/USAGE +3 -2
  29. data/lib/rails/commands/runner/runner_command.rb +3 -2
  30. data/lib/rails/commands/server/server_command.rb +7 -5
  31. data/lib/rails/configuration.rb +18 -23
  32. data/lib/rails/console/helpers.rb +2 -2
  33. data/lib/rails/engine/configuration.rb +3 -3
  34. data/lib/rails/engine.rb +31 -37
  35. data/lib/rails/gem_version.rb +5 -5
  36. data/lib/rails/generators/actions/create_migration.rb +2 -4
  37. data/lib/rails/generators/actions.rb +229 -62
  38. data/lib/rails/generators/app_base.rb +155 -130
  39. data/lib/rails/generators/app_name.rb +1 -1
  40. data/lib/rails/generators/base.rb +12 -16
  41. data/lib/rails/generators/erb/scaffold/scaffold_generator.rb +2 -0
  42. data/lib/rails/generators/erb/scaffold/templates/_form.html.erb.tt +8 -8
  43. data/lib/rails/generators/erb/scaffold/templates/edit.html.erb.tt +8 -4
  44. data/lib/rails/generators/erb/scaffold/templates/index.html.erb.tt +11 -28
  45. data/lib/rails/generators/erb/scaffold/templates/new.html.erb.tt +7 -3
  46. data/lib/rails/generators/erb/scaffold/templates/partial.html.erb.tt +17 -0
  47. data/lib/rails/generators/erb/scaffold/templates/show.html.erb.tt +8 -17
  48. data/lib/rails/generators/erb.rb +1 -1
  49. data/lib/rails/generators/generated_attribute.rb +45 -9
  50. data/lib/rails/generators/migration.rb +2 -6
  51. data/lib/rails/generators/model_helpers.rb +1 -1
  52. data/lib/rails/generators/named_base.rb +13 -13
  53. data/lib/rails/generators/rails/app/app_generator.rb +70 -91
  54. data/lib/rails/generators/rails/app/templates/Gemfile.tt +44 -52
  55. data/lib/rails/generators/rails/app/templates/app/assets/stylesheets/application.css.tt +2 -2
  56. data/lib/rails/generators/rails/app/templates/app/mailers/application_mailer.rb.tt +2 -2
  57. data/lib/rails/generators/rails/app/templates/app/models/application_record.rb.tt +1 -1
  58. data/lib/rails/generators/rails/app/templates/app/views/layouts/application.html.erb.tt +3 -9
  59. data/lib/rails/generators/rails/app/templates/bin/rails.tt +1 -4
  60. data/lib/rails/generators/rails/app/templates/bin/rake.tt +0 -3
  61. data/lib/rails/generators/rails/app/templates/bin/setup.tt +9 -14
  62. data/lib/rails/generators/rails/app/templates/config/application.rb.tt +0 -1
  63. data/lib/rails/generators/rails/app/templates/config/boot.rb.tt +1 -1
  64. data/lib/rails/generators/rails/app/templates/config/databases/jdbc.yml.tt +2 -2
  65. data/lib/rails/generators/rails/app/templates/config/databases/jdbcmysql.yml.tt +3 -3
  66. data/lib/rails/generators/rails/app/templates/config/databases/jdbcpostgresql.yml.tt +3 -3
  67. data/lib/rails/generators/rails/app/templates/config/databases/jdbcsqlite3.yml.tt +2 -2
  68. data/lib/rails/generators/rails/app/templates/config/databases/mysql.yml.tt +3 -3
  69. data/lib/rails/generators/rails/app/templates/config/databases/oracle.yml.tt +2 -2
  70. data/lib/rails/generators/rails/app/templates/config/databases/postgresql.yml.tt +3 -3
  71. data/lib/rails/generators/rails/app/templates/config/databases/sqlite3.yml.tt +1 -1
  72. data/lib/rails/generators/rails/app/templates/config/databases/sqlserver.yml.tt +5 -5
  73. data/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt +7 -13
  74. data/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt +12 -39
  75. data/lib/rails/generators/rails/app/templates/config/environments/test.rb.tt +7 -12
  76. data/lib/rails/generators/rails/app/templates/config/initializers/assets.rb.tt +1 -5
  77. data/lib/rails/generators/rails/app/templates/config/initializers/content_security_policy.rb.tt +21 -28
  78. data/lib/rails/generators/rails/app/templates/config/initializers/cors.rb.tt +2 -2
  79. data/lib/rails/generators/rails/app/templates/config/initializers/filter_parameter_logging.rb.tt +3 -1
  80. data/lib/rails/generators/rails/app/templates/config/initializers/inflections.rb.tt +4 -4
  81. data/lib/rails/generators/rails/app/templates/config/initializers/new_framework_defaults_7_0.rb.tt +143 -0
  82. data/lib/rails/generators/rails/app/templates/config/locales/en.yml +3 -3
  83. data/lib/rails/generators/rails/app/templates/config/puma.rb.tt +1 -1
  84. data/lib/rails/generators/rails/app/templates/config/routes.rb.tt +4 -1
  85. data/lib/rails/generators/rails/app/templates/config/storage.yml.tt +5 -5
  86. data/lib/rails/generators/rails/app/templates/db/seeds.rb.tt +2 -2
  87. data/lib/rails/generators/rails/app/templates/gitattributes.tt +0 -5
  88. data/lib/rails/generators/rails/app/templates/gitignore.tt +3 -1
  89. data/lib/rails/generators/rails/app/templates/test/test_helper.rb.tt +1 -1
  90. data/lib/rails/generators/rails/controller/controller_generator.rb +1 -2
  91. data/lib/rails/generators/rails/controller/templates/controller.rb.tt +0 -4
  92. data/lib/rails/generators/rails/db/system/change/change_generator.rb +1 -1
  93. data/lib/rails/generators/rails/generator/templates/%file_name%_generator.rb.tt +1 -1
  94. data/lib/rails/generators/rails/plugin/plugin_generator.rb +76 -27
  95. data/lib/rails/generators/rails/plugin/templates/%name%.gemspec.tt +7 -3
  96. data/lib/rails/generators/rails/plugin/templates/Gemfile.tt +9 -31
  97. data/lib/rails/generators/rails/plugin/templates/README.md.tt +1 -1
  98. data/lib/rails/generators/rails/plugin/templates/app/mailers/%namespaced_name%/application_mailer.rb.tt +2 -2
  99. data/lib/rails/generators/rails/plugin/templates/app/views/layouts/%namespaced_name%/application.html.erb.tt +0 -3
  100. data/lib/rails/generators/rails/plugin/templates/bin/rails.tt +7 -6
  101. data/lib/rails/generators/rails/plugin/templates/gitignore.tt +0 -5
  102. data/lib/rails/generators/rails/plugin/templates/lib/%namespaced_name%/engine.rb.tt +2 -2
  103. data/lib/rails/generators/rails/plugin/templates/lib/%namespaced_name%/version.rb.tt +1 -1
  104. data/lib/rails/generators/rails/plugin/templates/rails/boot.rb.tt +2 -2
  105. data/lib/rails/generators/rails/plugin/templates/test/test_helper.rb.tt +2 -7
  106. data/lib/rails/generators/rails/scaffold/scaffold_generator.rb +0 -19
  107. data/lib/rails/generators/rails/scaffold_controller/templates/api_controller.rb.tt +1 -5
  108. data/lib/rails/generators/rails/scaffold_controller/templates/controller.rb.tt +6 -10
  109. data/lib/rails/generators/resource_helpers.rb +2 -2
  110. data/lib/rails/generators/test_unit/generator/templates/generator_test.rb.tt +1 -1
  111. data/lib/rails/generators/test_unit/model/templates/fixtures.yml.tt +2 -2
  112. data/lib/rails/generators/test_unit/scaffold/scaffold_generator.rb +3 -3
  113. data/lib/rails/generators/test_unit/scaffold/templates/api_functional_test.rb.tt +5 -5
  114. data/lib/rails/generators/test_unit/scaffold/templates/functional_test.rb.tt +7 -7
  115. data/lib/rails/generators/test_unit/scaffold/templates/system_test.rb.tt +9 -11
  116. data/lib/rails/generators/testing/behaviour.rb +3 -4
  117. data/lib/rails/generators.rb +17 -24
  118. data/lib/rails/info.rb +1 -1
  119. data/lib/rails/info_controller.rb +1 -3
  120. data/lib/rails/initializable.rb +1 -1
  121. data/lib/rails/mailers_controller.rb +2 -4
  122. data/lib/rails/paths.rb +1 -1
  123. data/lib/rails/rack/logger.rb +7 -9
  124. data/lib/rails/railtie/configuration.rb +1 -2
  125. data/lib/rails/railtie.rb +36 -13
  126. data/lib/rails/ruby_version_check.rb +3 -3
  127. data/lib/rails/source_annotation_extractor.rb +1 -1
  128. data/lib/rails/tasks/framework.rake +7 -9
  129. data/lib/rails/tasks/statistics.rake +3 -1
  130. data/lib/rails/tasks/tmp.rake +8 -1
  131. data/lib/rails/tasks/yarn.rake +8 -9
  132. data/lib/rails/tasks/zeitwerk.rake +2 -10
  133. data/lib/rails/templates/layouts/application.html.erb +15 -0
  134. data/lib/rails/templates/rails/mailers/email.html.erb +13 -11
  135. data/lib/rails/templates/rails/welcome/index.html.erb +64 -48
  136. data/lib/rails/test_help.rb +4 -0
  137. data/lib/rails/test_unit/railtie.rb +0 -4
  138. data/lib/rails/test_unit/runner.rb +16 -9
  139. data/lib/rails/test_unit/testing.rake +4 -9
  140. data/lib/rails/version.rb +1 -1
  141. data/lib/rails/welcome_controller.rb +1 -0
  142. data/lib/rails.rb +13 -2
  143. metadata +33 -37
  144. data/lib/rails/command/spellchecker.rb +0 -57
  145. data/lib/rails/generators/css/assets/assets_generator.rb +0 -15
  146. data/lib/rails/generators/css/assets/templates/stylesheet.css +0 -4
  147. data/lib/rails/generators/css/scaffold/scaffold_generator.rb +0 -18
  148. data/lib/rails/generators/rails/app/templates/app/javascript/channels/consumer.js +0 -6
  149. data/lib/rails/generators/rails/app/templates/app/javascript/channels/index.js +0 -5
  150. data/lib/rails/generators/rails/app/templates/app/javascript/packs/application.js.tt +0 -23
  151. data/lib/rails/generators/rails/app/templates/bin/spring.tt +0 -13
  152. data/lib/rails/generators/rails/app/templates/bin/yarn.tt +0 -16
  153. data/lib/rails/generators/rails/app/templates/config/initializers/application_controller_renderer.rb.tt +0 -8
  154. data/lib/rails/generators/rails/app/templates/config/initializers/backtrace_silencers.rb.tt +0 -8
  155. data/lib/rails/generators/rails/app/templates/config/initializers/cookies_serializer.rb.tt +0 -5
  156. data/lib/rails/generators/rails/app/templates/config/initializers/mime_types.rb.tt +0 -4
  157. data/lib/rails/generators/rails/app/templates/config/initializers/new_framework_defaults_6_1.rb.tt +0 -67
  158. data/lib/rails/generators/rails/app/templates/config/initializers/wrap_parameters.rb.tt +0 -16
  159. data/lib/rails/generators/rails/app/templates/config/spring.rb.tt +0 -6
  160. data/lib/rails/generators/rails/app/templates/package.json.tt +0 -11
  161. data/lib/rails/generators/rails/assets/USAGE +0 -16
  162. data/lib/rails/generators/rails/assets/assets_generator.rb +0 -26
  163. data/lib/rails/generators/rails/assets/templates/stylesheet.css +0 -4
  164. data/lib/rails/generators/rails/scaffold/templates/scaffold.css +0 -80
@@ -1,41 +1,19 @@
1
- source 'https://rubygems.org'
1
+ source "https://rubygems.org"
2
2
  git_source(:github) { |repo| "https://github.com/#{repo}.git" }
3
+ <% unless options[:skip_gemspec] -%>
3
4
 
4
- <% if options[:skip_gemspec] -%>
5
- <%= '# ' if options.dev? || options.edge? || options.master? -%>gem 'rails', '<%= Array(rails_version_specifier).join("', '") %>'
6
- <% else -%>
7
5
  # Specify your gem's dependencies in <%= name %>.gemspec.
8
6
  gemspec
9
7
  <% end -%>
10
- <% unless options[:skip_active_record] -%>
11
-
12
- group :development do
13
- gem '<%= gem_for_database[0] %>'
14
- end
8
+ <% gemfile_entries.each do |gemfile_entry| %>
9
+ <%= gemfile_entry %>
15
10
  <% end -%>
11
+ <% if RUBY_ENGINE == "ruby" -%>
16
12
 
17
- <% if options.dev? || options.edge? -%>
18
- # Your gem is dependent on dev or edge Rails. Once you can lock this
19
- # dependency down to a specific version, move it to your gemspec.
20
- <% max_width = gemfile_entries.map { |g| g.name.length }.max -%>
21
- <% gemfile_entries.each do |gem| -%>
22
- <% if gem.comment -%>
23
-
24
- # <%= gem.comment %>
25
- <% end -%>
26
- <%= gem.commented_out ? '# ' : '' %>gem '<%= gem.name %>'<%= %(, '#{gem.version}') if gem.version -%>
27
- <% if gem.options.any? -%>
28
- , <%= gem.options.map { |k,v|
29
- "#{k}: #{v.inspect}" }.join(', ') %>
30
- <% end -%>
31
- <% end -%>
32
-
33
- <% end -%>
34
- <% if RUBY_ENGINE == 'ruby' -%>
35
- # To use a debugger
36
- # gem 'byebug', group: [:development, :test]
13
+ # Start debugger with binding.b [https://github.com/ruby/debug]
14
+ # gem "debug", ">= 1.0.0"
37
15
  <% end -%>
38
- <% if RUBY_PLATFORM.match(/bccwin|cygwin|emx|mingw|mswin|wince|java/) -%>
16
+ <% if RUBY_PLATFORM.match?(/bccwin|cygwin|emx|mingw|mswin|wince|java/) -%>
39
17
 
40
- gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
18
+ gem "tzinfo-data", platforms: %i[ mingw mswin x64_mingw jruby ]
41
19
  <% end -%>
@@ -8,7 +8,7 @@ How to use my plugin.
8
8
  Add this line to your application's Gemfile:
9
9
 
10
10
  ```ruby
11
- gem '<%= name %>'
11
+ gem "<%= name %>"
12
12
  ```
13
13
 
14
14
  And then execute:
@@ -1,7 +1,7 @@
1
1
  <%= wrap_in_modules <<~rb
2
2
  class ApplicationMailer < ActionMailer::Base
3
- default from: 'from@example.com'
4
- layout 'mailer'
3
+ default from: "from@example.com"
4
+ layout "mailer"
5
5
  end
6
6
  rb
7
7
  %>
@@ -6,9 +6,6 @@
6
6
  <%%= csp_meta_tag %>
7
7
 
8
8
  <%%= stylesheet_link_tag "<%= namespaced_name %>/application", media: "all" %>
9
- <%- unless options[:skip_javascript] -%>
10
- <%%= javascript_include_tag "<%= namespaced_name %>/application" %>
11
- <%- end -%>
12
9
  </head>
13
10
  <body>
14
11
 
@@ -1,14 +1,14 @@
1
1
  # This command will automatically be run when you run "rails" with Rails gems
2
2
  # installed from the root of your application.
3
3
 
4
- ENGINE_ROOT = File.expand_path('..', __dir__)
5
- ENGINE_PATH = File.expand_path('../lib/<%= namespaced_name -%>/engine', __dir__)
4
+ ENGINE_ROOT = File.expand_path("..", __dir__)
5
+ ENGINE_PATH = File.expand_path("../lib/<%= namespaced_name -%>/engine", __dir__)
6
6
  <% if with_dummy_app? -%>
7
- APP_PATH = File.expand_path('../<%= dummy_path -%>/config/application', __dir__)
7
+ APP_PATH = File.expand_path("../<%= dummy_path -%>/config/application", __dir__)
8
8
  <% end -%>
9
9
 
10
10
  # Set up gems listed in the Gemfile.
11
- ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__)
11
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__)
12
12
  require "bundler/setup" if File.exist?(ENV["BUNDLE_GEMFILE"])
13
13
 
14
14
  <% if include_all_railties? -%>
@@ -17,14 +17,15 @@ require "rails/all"
17
17
  require "rails"
18
18
  # Pick the frameworks you want:
19
19
  require "active_model/railtie"
20
- require "active_job/railtie"
20
+ <%= comment_if :skip_active_job %>require "active_job/railtie"
21
21
  <%= comment_if :skip_active_record %>require "active_record/railtie"
22
22
  <%= comment_if :skip_active_storage %>require "active_storage/engine"
23
23
  require "action_controller/railtie"
24
24
  <%= comment_if :skip_action_mailer %>require "action_mailer/railtie"
25
+ <%= comment_if :skip_action_mailbox %>require "action_mailbox/engine"
26
+ <%= comment_if :skip_action_text %>require "action_text/engine"
25
27
  require "action_view/railtie"
26
28
  <%= comment_if :skip_action_cable %>require "action_cable/engine"
27
- <%= comment_if :skip_sprockets %>require "sprockets/railtie"
28
29
  <%= comment_if :skip_test %>require "rails/test_unit/railtie"
29
30
  <% end -%>
30
31
  require "rails/engine/commands"
@@ -9,13 +9,8 @@
9
9
  /<%= dummy_path %>/db/*.sqlite3-*
10
10
  <% end -%>
11
11
  /<%= dummy_path %>/log/*.log
12
- <% unless options[:skip_javascript] -%>
13
- /<%= dummy_path %>/node_modules/
14
- /<%= dummy_path %>/yarn-error.log
15
- <% end -%>
16
12
  <% unless skip_active_storage? -%>
17
13
  /<%= dummy_path %>/storage/
18
14
  <% end -%>
19
15
  /<%= dummy_path %>/tmp/
20
16
  <% end -%>
21
- .byebug_history
@@ -1,7 +1,7 @@
1
1
  <%= wrap_in_modules <<~rb
2
2
  class Engine < ::Rails::Engine
3
- #{mountable? ? ' isolate_namespace ' + camelized_modules : ' '}
4
- #{api? ? " config.generators.api_only = true" : ' '}
3
+ #{mountable? ? " isolate_namespace " + camelized_modules : " "}
4
+ #{api? ? " config.generators.api_only = true" : " "}
5
5
  end
6
6
  rb
7
7
  %>
@@ -1 +1 @@
1
- <%= wrap_in_modules "VERSION = '0.1.0'" %>
1
+ <%= wrap_in_modules 'VERSION = "0.1.0"' %>
@@ -1,5 +1,5 @@
1
1
  # Set up gems listed in the Gemfile.
2
- ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../../Gemfile', __dir__)
2
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../../Gemfile", __dir__)
3
3
 
4
4
  require "bundler/setup" if File.exist?(ENV["BUNDLE_GEMFILE"])
5
- $LOAD_PATH.unshift File.expand_path('../../../lib', __dir__)
5
+ $LOAD_PATH.unshift File.expand_path("../../../lib", __dir__)
@@ -1,20 +1,15 @@
1
1
  # Configure Rails Environment
2
2
  ENV["RAILS_ENV"] = "test"
3
3
 
4
- require_relative "<%= File.join('..', options[:dummy_path], 'config/environment') -%>"
4
+ require_relative "<%= File.join("..", options[:dummy_path], "config/environment") -%>"
5
5
  <% unless options[:skip_active_record] -%>
6
6
  ActiveRecord::Migrator.migrations_paths = [File.expand_path("../<%= options[:dummy_path] -%>/db/migrate", __dir__)]
7
7
  <% if options[:mountable] -%>
8
- ActiveRecord::Migrator.migrations_paths << File.expand_path('../db/migrate', __dir__)
8
+ ActiveRecord::Migrator.migrations_paths << File.expand_path("../db/migrate", __dir__)
9
9
  <% end -%>
10
10
  <% end -%>
11
11
  require "rails/test_help"
12
12
 
13
- <% unless engine? -%>
14
- require "rails/test_unit/reporter"
15
- Rails::TestUnitReporter.executable = 'bin/test'
16
- <% end -%>
17
-
18
13
  <% unless options[:skip_active_record] -%>
19
14
  # Load fixtures from the engine
20
15
  if ActiveSupport::TestCase.respond_to?(:fixture_path=)
@@ -9,28 +9,9 @@ module Rails
9
9
  remove_class_option :actions
10
10
 
11
11
  class_option :api, type: :boolean
12
- class_option :stylesheets, type: :boolean, desc: "Generate Stylesheets"
13
- class_option :stylesheet_engine, desc: "Engine for Stylesheets"
14
- class_option :assets, type: :boolean
15
12
  class_option :resource_route, type: :boolean
16
- class_option :scaffold_stylesheet, type: :boolean
17
-
18
- def handle_skip
19
- @options = @options.merge(stylesheets: false) unless options[:assets]
20
- @options = @options.merge(stylesheet_engine: false) unless options[:stylesheets] && options[:scaffold_stylesheet]
21
- end
22
13
 
23
14
  hook_for :scaffold_controller, required: true
24
-
25
- hook_for :assets do |assets|
26
- invoke assets, [controller_name]
27
- end
28
-
29
- hook_for :stylesheet_engine do |stylesheet_engine|
30
- if behavior == :invoke
31
- invoke stylesheet_engine, [controller_name]
32
- end
33
- end
34
15
  end
35
16
  end
36
17
  end
@@ -1,10 +1,6 @@
1
- <% if namespaced? -%>
2
- require_dependency "<%= namespaced_path %>/application_controller"
3
-
4
- <% end -%>
5
1
  <% module_namespacing do -%>
6
2
  class <%= controller_class_name %>Controller < ApplicationController
7
- before_action :set_<%= singular_table_name %>, only: [:show, :update, :destroy]
3
+ before_action :set_<%= singular_table_name %>, only: %i[ show update destroy ]
8
4
 
9
5
  # GET <%= route_url %>
10
6
  def index
@@ -1,10 +1,6 @@
1
- <% if namespaced? -%>
2
- require_dependency "<%= namespaced_path %>/application_controller"
3
-
4
- <% end -%>
5
1
  <% module_namespacing do -%>
6
2
  class <%= controller_class_name %>Controller < ApplicationController
7
- before_action :set_<%= singular_table_name %>, only: [:show, :edit, :update, :destroy]
3
+ before_action :set_<%= singular_table_name %>, only: %i[ show edit update destroy ]
8
4
 
9
5
  # GET <%= route_url %>
10
6
  def index
@@ -29,25 +25,25 @@ class <%= controller_class_name %>Controller < ApplicationController
29
25
  @<%= singular_table_name %> = <%= orm_class.build(class_name, "#{singular_table_name}_params") %>
30
26
 
31
27
  if @<%= orm_instance.save %>
32
- redirect_to <%= redirect_resource_name %>, notice: <%= "'#{human_name} was successfully created.'" %>
28
+ redirect_to <%= redirect_resource_name %>, notice: <%= %("#{human_name} was successfully created.") %>
33
29
  else
34
- render :new
30
+ render :new, status: :unprocessable_entity
35
31
  end
36
32
  end
37
33
 
38
34
  # PATCH/PUT <%= route_url %>/1
39
35
  def update
40
36
  if @<%= orm_instance.update("#{singular_table_name}_params") %>
41
- redirect_to <%= redirect_resource_name %>, notice: <%= "'#{human_name} was successfully updated.'" %>
37
+ redirect_to <%= redirect_resource_name %>, notice: <%= %("#{human_name} was successfully updated.") %>, status: :see_other
42
38
  else
43
- render :edit
39
+ render :edit, status: :unprocessable_entity
44
40
  end
45
41
  end
46
42
 
47
43
  # DELETE <%= route_url %>/1
48
44
  def destroy
49
45
  @<%= orm_instance.destroy %>
50
- redirect_to <%= index_helper %>_url, notice: <%= "'#{human_name} was successfully destroyed.'" %>
46
+ redirect_to <%= index_helper %>_url, notice: <%= %("#{human_name} was successfully destroyed.") %>, status: :see_other
51
47
  end
52
48
 
53
49
  private
@@ -8,13 +8,13 @@ module Rails
8
8
  # Deal with controller names on scaffold and add some helpers to deal with
9
9
  # ActiveModel.
10
10
  module ResourceHelpers # :nodoc:
11
- def self.included(base) #:nodoc:
11
+ def self.included(base) # :nodoc:
12
12
  base.include(Rails::Generators::ModelHelpers)
13
13
  base.class_option :model_name, type: :string, desc: "ModelName to be used"
14
14
  end
15
15
 
16
16
  # Set controller variables on initialization.
17
- def initialize(*args) #:nodoc:
17
+ def initialize(*args) # :nodoc:
18
18
  super
19
19
  controller_name = name
20
20
  if options[:model_name]
@@ -4,7 +4,7 @@ require "<%= generator_path %>"
4
4
  <% module_namespacing do -%>
5
5
  class <%= class_name %>GeneratorTest < Rails::Generators::TestCase
6
6
  tests <%= class_name %>Generator
7
- destination Rails.root.join('tmp/generators')
7
+ destination Rails.root.join("tmp/generators")
8
8
  setup :prepare_destination
9
9
 
10
10
  # test "generator runs without errors" do
@@ -4,7 +4,7 @@
4
4
  <%= name %>:
5
5
  <% attributes.each do |attribute| -%>
6
6
  <%- if attribute.password_digest? -%>
7
- password_digest: <%%= BCrypt::Password.create('secret') %>
7
+ password_digest: <%%= BCrypt::Password.create("secret") %>
8
8
  <%- elsif attribute.reference? -%>
9
9
  <%= yaml_key_value(attribute.column_name.delete_suffix("_id"), attribute.default || name) %>
10
10
  <%- elsif !attribute.virtual? -%>
@@ -18,7 +18,7 @@
18
18
  <% else -%>
19
19
 
20
20
  # This model initially had no columns defined. If you add columns to the
21
- # model remove the '{}' from the fixture names and add the columns immediately
21
+ # model remove the "{}" from the fixture names and add the columns immediately
22
22
  # below each fixture, per the syntax in the comments below
23
23
  #
24
24
  one: {}
@@ -45,13 +45,13 @@ module TestUnit # :nodoc:
45
45
  def attributes_hash
46
46
  return {} if attributes_names.empty?
47
47
 
48
- attributes_names.map do |name|
48
+ attributes_names.filter_map do |name|
49
49
  if %w(password password_confirmation).include?(name) && attributes.any?(&:password_digest?)
50
- ["#{name}", "'secret'"]
50
+ ["#{name}", '"secret"']
51
51
  elsif !virtual?(name)
52
52
  ["#{name}", "@#{singular_table_name}.#{name}"]
53
53
  end
54
- end.compact.sort.to_h
54
+ end.sort.to_h
55
55
  end
56
56
 
57
57
  def boolean?(name)
@@ -16,11 +16,11 @@ class <%= controller_class_name %>ControllerTest < ActionDispatch::IntegrationTe
16
16
  end
17
17
 
18
18
  test "should create <%= singular_table_name %>" do
19
- assert_difference('<%= class_name %>.count') do
19
+ assert_difference("<%= class_name %>.count") do
20
20
  post <%= index_helper %>_url, params: { <%= "#{singular_table_name}: { #{attributes_string} }" %> }, as: :json
21
21
  end
22
22
 
23
- assert_response 201
23
+ assert_response :created
24
24
  end
25
25
 
26
26
  test "should show <%= singular_table_name %>" do
@@ -30,15 +30,15 @@ class <%= controller_class_name %>ControllerTest < ActionDispatch::IntegrationTe
30
30
 
31
31
  test "should update <%= singular_table_name %>" do
32
32
  patch <%= show_helper %>, params: { <%= "#{singular_table_name}: { #{attributes_string} }" %> }, as: :json
33
- assert_response 200
33
+ assert_response :success
34
34
  end
35
35
 
36
36
  test "should destroy <%= singular_table_name %>" do
37
- assert_difference('<%= class_name %>.count', -1) do
37
+ assert_difference("<%= class_name %>.count", -1) do
38
38
  delete <%= show_helper %>, as: :json
39
39
  end
40
40
 
41
- assert_response 204
41
+ assert_response :no_content
42
42
  end
43
43
  end
44
44
  <% end -%>
@@ -11,7 +11,7 @@ class <%= controller_class_name %>ControllerTest < ActionDispatch::IntegrationTe
11
11
  end
12
12
 
13
13
  test "should get index" do
14
- get <%= index_helper %>_url
14
+ get <%= index_helper(type: :url) %>
15
15
  assert_response :success
16
16
  end
17
17
 
@@ -21,11 +21,11 @@ class <%= controller_class_name %>ControllerTest < ActionDispatch::IntegrationTe
21
21
  end
22
22
 
23
23
  test "should create <%= singular_table_name %>" do
24
- assert_difference('<%= class_name %>.count') do
25
- post <%= index_helper %>_url, params: { <%= "#{singular_table_name}: { #{attributes_string} }" %> }
24
+ assert_difference("<%= class_name %>.count") do
25
+ post <%= index_helper(type: :url) %>, params: { <%= "#{singular_table_name}: { #{attributes_string} }" %> }
26
26
  end
27
27
 
28
- assert_redirected_to <%= singular_table_name %>_url(<%= class_name %>.last)
28
+ assert_redirected_to <%= show_helper("#{class_name}.last") %>
29
29
  end
30
30
 
31
31
  test "should show <%= singular_table_name %>" do
@@ -40,15 +40,15 @@ class <%= controller_class_name %>ControllerTest < ActionDispatch::IntegrationTe
40
40
 
41
41
  test "should update <%= singular_table_name %>" do
42
42
  patch <%= show_helper %>, params: { <%= "#{singular_table_name}: { #{attributes_string} }" %> }
43
- assert_redirected_to <%= singular_table_name %>_url(<%= "@#{singular_table_name}" %>)
43
+ assert_redirected_to <%= show_helper %>
44
44
  end
45
45
 
46
46
  test "should destroy <%= singular_table_name %>" do
47
- assert_difference('<%= class_name %>.count', -1) do
47
+ assert_difference("<%= class_name %>.count", -1) do
48
48
  delete <%= show_helper %>
49
49
  end
50
50
 
51
- assert_redirected_to <%= index_helper %>_url
51
+ assert_redirected_to <%= index_helper(type: :url) %>
52
52
  end
53
53
  end
54
54
  <% end -%>
@@ -8,12 +8,12 @@ class <%= class_name.pluralize %>Test < ApplicationSystemTestCase
8
8
 
9
9
  test "visiting the index" do
10
10
  visit <%= plural_table_name %>_url
11
- assert_selector "h1", text: "<%= class_name.pluralize.titleize %>"
11
+ assert_selector "h1", text: "<%= human_name.pluralize %>"
12
12
  end
13
13
 
14
- test "creating a <%= human_name %>" do
14
+ test "should create <%= human_name.downcase %>" do
15
15
  visit <%= plural_table_name %>_url
16
- click_on "New <%= class_name.titleize %>"
16
+ click_on "New <%= human_name.downcase %>"
17
17
 
18
18
  <%- attributes_hash.each do |attr, value| -%>
19
19
  <%- if boolean?(attr) -%>
@@ -28,9 +28,9 @@ class <%= class_name.pluralize %>Test < ApplicationSystemTestCase
28
28
  click_on "Back"
29
29
  end
30
30
 
31
- test "updating a <%= human_name %>" do
32
- visit <%= plural_table_name %>_url
33
- click_on "Edit", match: :first
31
+ test "should update <%= human_name %>" do
32
+ visit <%= singular_table_name %>_url(@<%= singular_table_name %>)
33
+ click_on "Edit this <%= human_name.downcase %>", match: :first
34
34
 
35
35
  <%- attributes_hash.each do |attr, value| -%>
36
36
  <%- if boolean?(attr) -%>
@@ -45,11 +45,9 @@ class <%= class_name.pluralize %>Test < ApplicationSystemTestCase
45
45
  click_on "Back"
46
46
  end
47
47
 
48
- test "destroying a <%= human_name %>" do
49
- visit <%= plural_table_name %>_url
50
- page.accept_confirm do
51
- click_on "Destroy", match: :first
52
- end
48
+ test "should destroy <%= human_name %>" do
49
+ visit <%= singular_table_name %>_url(@<%= singular_table_name %>)
50
+ click_on "Destroy this <%= human_name.downcase %>", match: :first
53
51
 
54
52
  assert_text "<%= human_name %> was successfully destroyed"
55
53
  end
@@ -66,9 +66,8 @@ module Rails
66
66
  # printed by the generator.
67
67
  def run_generator(args = default_arguments, config = {})
68
68
  capture(:stdout) do
69
- args += ["--skip-bundle"] unless args.include? "--dev"
70
- args |= ["--skip-bootsnap"] unless args.include? "--no-skip-bootsnap"
71
- args |= ["--skip-webpack-install"] unless args.include? "--no-skip-webpack-install"
69
+ args += ["--skip-bundle"] unless args.include?("--no-skip-bundle") || args.include?("--dev")
70
+ args += ["--skip-bootsnap"] unless args.include?("--no-skip-bootsnap") || args.include?("--skip-bootsnap")
72
71
 
73
72
  generator_class.start(args, config.reverse_merge(destination_root: destination_root))
74
73
  end
@@ -82,7 +81,7 @@ module Rails
82
81
  # Create a Rails::Generators::GeneratedAttribute by supplying the
83
82
  # attribute type and, optionally, the attribute name:
84
83
  #
85
- # create_generated_attribute(:string, 'name')
84
+ # create_generated_attribute(:string, "name")
86
85
  def create_generated_attribute(attribute_type, name = "test", index = nil)
87
86
  Rails::Generators::GeneratedAttribute.parse([name, attribute_type, index].compact.join(":"))
88
87
  end
@@ -34,12 +34,9 @@ module Rails
34
34
  actions: "-a",
35
35
  orm: "-o",
36
36
  javascripts: "-j",
37
- javascript_engine: "-je",
38
37
  resource_controller: "-c",
39
38
  scaffold_controller: "-c",
40
39
  stylesheets: "-y",
41
- stylesheet_engine: "-se",
42
- scaffold_stylesheet: "-ss",
43
40
  template_engine: "-e",
44
41
  test_framework: "-t"
45
42
  },
@@ -60,9 +57,6 @@ module Rails
60
57
  resource_controller: :controller,
61
58
  resource_route: true,
62
59
  scaffold_controller: :scaffold_controller,
63
- stylesheets: true,
64
- stylesheet_engine: :css,
65
- scaffold_stylesheet: true,
66
60
  system_tests: nil,
67
61
  test_framework: nil,
68
62
  template_engine: :erb
@@ -70,7 +64,7 @@ module Rails
70
64
  }
71
65
 
72
66
  class << self
73
- def configure!(config) #:nodoc:
67
+ def configure!(config) # :nodoc:
74
68
  api_only! if config.api_only
75
69
  no_color! unless config.colorize_logging
76
70
  aliases.deep_merge! config.aliases
@@ -82,15 +76,15 @@ module Rails
82
76
  after_generate_callbacks.replace config.after_generate_callbacks
83
77
  end
84
78
 
85
- def templates_path #:nodoc:
79
+ def templates_path # :nodoc:
86
80
  @templates_path ||= []
87
81
  end
88
82
 
89
- def aliases #:nodoc:
83
+ def aliases # :nodoc:
90
84
  @aliases ||= DEFAULT_ALIASES.dup
91
85
  end
92
86
 
93
- def options #:nodoc:
87
+ def options # :nodoc:
94
88
  @options ||= DEFAULT_OPTIONS.dup
95
89
  end
96
90
 
@@ -135,14 +129,12 @@ module Rails
135
129
  # Returns an array of generator namespaces that are hidden.
136
130
  # Generator namespaces may be hidden for a variety of reasons.
137
131
  # Some are aliased such as "rails:migration" and can be
138
- # invoked with the shorter "migration", others are private to other generators
139
- # such as "css:scaffold".
132
+ # invoked with the shorter "migration".
140
133
  def hidden_namespaces
141
134
  @hidden_namespaces ||= begin
142
135
  orm = options[:rails][:orm]
143
136
  test = options[:rails][:test_framework]
144
137
  template = options[:rails][:template_engine]
145
- css = options[:rails][:stylesheet_engine]
146
138
 
147
139
  [
148
140
  "rails",
@@ -161,10 +153,6 @@ module Rails
161
153
  "#{template}:controller",
162
154
  "#{template}:scaffold",
163
155
  "#{template}:mailer",
164
- "#{css}:scaffold",
165
- "#{css}:assets",
166
- "css:assets",
167
- "css:scaffold",
168
156
  "action_text:install",
169
157
  "action_mailbox:install"
170
158
  ]
@@ -241,7 +229,7 @@ module Rails
241
229
  #
242
230
  # Notice that "rails:generators:webrat" could be loaded as well, what
243
231
  # Rails looks for is the first and last parts of the namespace.
244
- def find_by_namespace(name, base = nil, context = nil) #:nodoc:
232
+ def find_by_namespace(name, base = nil, context = nil) # :nodoc:
245
233
  lookups = []
246
234
  lookups << "#{base}:#{name}" if base
247
235
  lookups << "#{name}:#{context}" if context
@@ -265,8 +253,8 @@ module Rails
265
253
  invoke_fallbacks_for(name, base) || invoke_fallbacks_for(context, name)
266
254
  end
267
255
 
268
- # Receives a namespace, arguments and the behavior to invoke the generator.
269
- # It's used as the default entry point for generate, destroy and update
256
+ # Receives a namespace, arguments, and the behavior to invoke the generator.
257
+ # It's used as the default entry point for generate, destroy, and update
270
258
  # commands.
271
259
  def invoke(namespace, args = ARGV, config = {})
272
260
  names = namespace.to_s.split(":")
@@ -275,12 +263,17 @@ module Rails
275
263
  klass.start(args, config)
276
264
  run_after_generate_callback if config[:behavior] == :invoke
277
265
  else
278
- options = sorted_groups.flat_map(&:last)
279
- suggestion = Rails::Command::Spellchecker.suggest(namespace.to_s, from: options)
280
- suggestion_msg = "Maybe you meant #{suggestion.inspect}?" if suggestion
266
+ options = sorted_groups.flat_map(&:last)
267
+ error = Command::Base::CorrectableError.new("Could not find generator '#{namespace}'.", namespace, options)
268
+
269
+ if error.respond_to?(:detailed_message)
270
+ formatted_message = error.detailed_message
271
+ else
272
+ formatted_message = error.message
273
+ end
281
274
 
282
275
  puts <<~MSG
283
- Could not find generator '#{namespace}'. #{suggestion_msg}
276
+ #{formatted_message}
284
277
  Run `bin/rails generate --help` for more options.
285
278
  MSG
286
279
  end
data/lib/rails/info.rb CHANGED
@@ -21,7 +21,7 @@ module Rails
21
21
  end
22
22
  end
23
23
 
24
- class << self #:nodoc:
24
+ class << self # :nodoc:
25
25
  def property(name, value = nil)
26
26
  value ||= yield
27
27
  properties << [name, value] if value
@@ -34,9 +34,7 @@ class Rails::InfoController < Rails::ApplicationController # :nodoc:
34
34
 
35
35
  private
36
36
  def match_route
37
- _routes.routes.select { |route|
38
- yield route.path
39
- }.map { |route| route.path.spec.to_s }
37
+ _routes.routes.filter_map { |route| route.path.spec.to_s if yield route.path }
40
38
  end
41
39
 
42
40
  def with_leading_slash(path)
@@ -4,7 +4,7 @@ require "tsort"
4
4
 
5
5
  module Rails
6
6
  module Initializable
7
- def self.included(base) #:nodoc:
7
+ def self.included(base) # :nodoc:
8
8
  base.extend ClassMethods
9
9
  end
10
10
 
@@ -93,9 +93,7 @@ class Rails::MailersController < Rails::ApplicationController # :nodoc:
93
93
  request.query_parameters.merge(locale: locale).to_query
94
94
  end
95
95
 
96
- def set_locale
97
- I18n.with_locale(params[:locale] || I18n.default_locale) do
98
- yield
99
- end
96
+ def set_locale(&block)
97
+ I18n.with_locale(params[:locale] || I18n.default_locale, &block)
100
98
  end
101
99
  end