railties 6.0.4.3 → 6.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (161) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +234 -420
  3. data/MIT-LICENSE +1 -1
  4. data/RDOC_MAIN.rdoc +1 -1
  5. data/README.rdoc +1 -1
  6. data/lib/minitest/rails_plugin.rb +16 -1
  7. data/lib/rails/api/task.rb +1 -1
  8. data/lib/rails/application/bootstrap.rb +5 -5
  9. data/lib/rails/application/configuration.rb +72 -22
  10. data/lib/rails/application/default_middleware_stack.rb +5 -3
  11. data/lib/rails/application/finisher.rb +15 -2
  12. data/lib/rails/application/routes_reloader.rb +9 -2
  13. data/lib/rails/application.rb +45 -79
  14. data/lib/rails/backtrace_cleaner.rb +12 -7
  15. data/lib/rails/code_statistics.rb +3 -3
  16. data/lib/rails/code_statistics_calculator.rb +6 -6
  17. data/lib/rails/command/base.rb +1 -1
  18. data/lib/rails/command/behavior.rb +1 -1
  19. data/lib/rails/command/environment_argument.rb +1 -1
  20. data/lib/rails/command.rb +7 -1
  21. data/lib/rails/commands/credentials/USAGE +17 -2
  22. data/lib/rails/commands/credentials/credentials_command/diffing.rb +41 -0
  23. data/lib/rails/commands/credentials/credentials_command.rb +28 -4
  24. data/lib/rails/commands/db/system/change/change_command.rb +6 -1
  25. data/lib/rails/commands/dbconsole/dbconsole_command.rb +61 -58
  26. data/lib/rails/commands/encrypted/encrypted_command.rb +4 -4
  27. data/lib/rails/commands/generate/generate_command.rb +1 -1
  28. data/lib/rails/commands/notes/notes_command.rb +3 -13
  29. data/lib/rails/commands/rake/rake_command.rb +9 -8
  30. data/lib/rails/commands/secrets/USAGE +9 -3
  31. data/lib/rails/commands/server/server_command.rb +14 -41
  32. data/lib/rails/commands/test/test_command.rb +2 -2
  33. data/lib/rails/configuration.rb +40 -10
  34. data/lib/rails/engine/configuration.rb +1 -0
  35. data/lib/rails/engine/updater.rb +1 -1
  36. data/lib/rails/engine.rb +35 -32
  37. data/lib/rails/gem_version.rb +3 -3
  38. data/lib/rails/generators/actions/create_migration.rb +5 -0
  39. data/lib/rails/generators/actions.rb +50 -29
  40. data/lib/rails/generators/app_base.rb +39 -22
  41. data/lib/rails/generators/base.rb +14 -11
  42. data/lib/rails/generators/database.rb +3 -4
  43. data/lib/rails/generators/erb/scaffold/templates/_form.html.erb.tt +3 -3
  44. data/lib/rails/generators/generated_attribute.rb +3 -9
  45. data/lib/rails/generators/migration.rb +2 -1
  46. data/lib/rails/generators/model_helpers.rb +26 -2
  47. data/lib/rails/generators/named_base.rb +1 -1
  48. data/lib/rails/generators/rails/app/USAGE +2 -1
  49. data/lib/rails/generators/rails/app/app_generator.rb +89 -15
  50. data/lib/rails/generators/rails/app/templates/Gemfile.tt +11 -11
  51. data/lib/rails/generators/rails/app/templates/Rakefile.tt +1 -1
  52. data/lib/rails/generators/rails/app/templates/app/javascript/channels/consumer.js +1 -1
  53. data/lib/rails/generators/rails/app/templates/app/javascript/packs/application.js.tt +11 -11
  54. data/lib/rails/generators/rails/app/templates/app/views/layouts/application.html.erb.tt +2 -1
  55. data/lib/rails/generators/rails/app/templates/bin/rails.tt +5 -2
  56. data/lib/rails/generators/rails/app/templates/bin/rake.tt +5 -2
  57. data/lib/rails/generators/rails/app/templates/bin/setup.tt +4 -4
  58. data/lib/rails/generators/rails/app/templates/bin/spring.tt +13 -0
  59. data/lib/rails/generators/rails/app/templates/bin/yarn.tt +9 -3
  60. data/lib/rails/generators/rails/app/templates/config/application.rb.tt +14 -7
  61. data/lib/rails/generators/rails/app/templates/config/boot.rb.tt +2 -2
  62. data/lib/rails/generators/rails/app/templates/config/databases/jdbc.yml.tt +3 -4
  63. data/lib/rails/generators/rails/app/templates/config/databases/jdbcmysql.yml.tt +10 -9
  64. data/lib/rails/generators/rails/app/templates/config/databases/jdbcpostgresql.yml.tt +11 -10
  65. data/lib/rails/generators/rails/app/templates/config/databases/mysql.yml.tt +10 -9
  66. data/lib/rails/generators/rails/app/templates/config/databases/oracle.yml.tt +11 -10
  67. data/lib/rails/generators/rails/app/templates/config/databases/postgresql.yml.tt +11 -10
  68. data/lib/rails/generators/rails/app/templates/config/databases/sqlserver.yml.tt +10 -9
  69. data/lib/rails/generators/rails/app/templates/config/environment.rb.tt +1 -1
  70. data/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt +17 -3
  71. data/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt +15 -5
  72. data/lib/rails/generators/rails/app/templates/config/environments/test.rb.tt +12 -1
  73. data/lib/rails/generators/rails/app/templates/config/initializers/backtrace_silencers.rb.tt +4 -3
  74. data/lib/rails/generators/rails/app/templates/config/initializers/filter_parameter_logging.rb.tt +3 -1
  75. data/lib/rails/generators/rails/app/templates/config/initializers/new_framework_defaults_6_1.rb.tt +67 -0
  76. data/lib/rails/generators/rails/app/templates/config/initializers/permissions_policy.rb.tt +11 -0
  77. data/lib/rails/generators/rails/app/templates/config/puma.rb.tt +6 -1
  78. data/lib/rails/generators/rails/app/templates/config.ru.tt +2 -1
  79. data/lib/rails/generators/rails/app/templates/db/seeds.rb.tt +1 -1
  80. data/lib/rails/generators/rails/app/templates/gitattributes.tt +14 -0
  81. data/lib/rails/generators/rails/app/templates/gitignore.tt +0 -1
  82. data/lib/rails/generators/rails/app/templates/package.json.tt +1 -1
  83. data/lib/rails/generators/rails/app/templates/test/test_helper.rb.tt +5 -5
  84. data/lib/rails/generators/rails/assets/USAGE +2 -3
  85. data/lib/rails/generators/rails/benchmark/USAGE +19 -0
  86. data/lib/rails/generators/rails/benchmark/benchmark_generator.rb +29 -0
  87. data/lib/rails/generators/rails/benchmark/templates/benchmark.rb.tt +15 -0
  88. data/lib/rails/generators/rails/controller/USAGE +2 -2
  89. data/lib/rails/generators/rails/controller/controller_generator.rb +2 -40
  90. data/lib/rails/generators/rails/credentials/credentials_generator.rb +1 -1
  91. data/lib/rails/generators/rails/generator/USAGE +2 -2
  92. data/lib/rails/generators/rails/generator/templates/USAGE.tt +1 -1
  93. data/lib/rails/generators/rails/helper/USAGE +2 -3
  94. data/lib/rails/generators/rails/integration_test/USAGE +2 -2
  95. data/lib/rails/generators/rails/migration/USAGE +4 -4
  96. data/lib/rails/generators/rails/model/USAGE +15 -16
  97. data/lib/rails/generators/rails/plugin/plugin_generator.rb +25 -23
  98. data/lib/rails/generators/rails/plugin/templates/%name%.gemspec.tt +10 -19
  99. data/lib/rails/generators/rails/plugin/templates/Gemfile.tt +3 -10
  100. data/lib/rails/generators/rails/plugin/templates/Rakefile.tt +4 -18
  101. data/lib/rails/generators/rails/plugin/templates/app/controllers/%namespaced_name%/application_controller.rb.tt +0 -1
  102. data/lib/rails/generators/rails/plugin/templates/bin/rails.tt +3 -3
  103. data/lib/rails/generators/rails/plugin/templates/gitignore.tt +13 -11
  104. data/lib/rails/generators/rails/plugin/templates/lib/%namespaced_name%.rb.tt +1 -0
  105. data/lib/rails/generators/rails/plugin/templates/rails/boot.rb.tt +1 -1
  106. data/lib/rails/generators/rails/plugin/templates/test/%namespaced_name%_test.rb.tt +4 -4
  107. data/lib/rails/generators/rails/plugin/templates/test/integration/navigation_test.rb.tt +1 -1
  108. data/lib/rails/generators/rails/plugin/templates/test/test_helper.rb.tt +0 -3
  109. data/lib/rails/generators/rails/resource/USAGE +4 -4
  110. data/lib/rails/generators/rails/resource_route/resource_route_generator.rb +2 -27
  111. data/lib/rails/generators/rails/scaffold/USAGE +5 -5
  112. data/lib/rails/generators/rails/scaffold_controller/USAGE +2 -2
  113. data/lib/rails/generators/rails/scaffold_controller/scaffold_controller_generator.rb +6 -0
  114. data/lib/rails/generators/rails/scaffold_controller/templates/api_controller.rb.tt +1 -1
  115. data/lib/rails/generators/rails/scaffold_controller/templates/controller.rb.tt +1 -1
  116. data/lib/rails/generators/rails/system_test/USAGE +2 -2
  117. data/lib/rails/generators/rails/task/USAGE +3 -3
  118. data/lib/rails/generators/test_case.rb +1 -1
  119. data/lib/rails/generators/test_unit/controller/controller_generator.rb +2 -0
  120. data/lib/rails/generators/test_unit/controller/templates/functional_test.rb.tt +3 -3
  121. data/lib/rails/generators/test_unit/generator/templates/generator_test.rb.tt +2 -2
  122. data/lib/rails/generators/test_unit/integration/templates/integration_test.rb.tt +1 -1
  123. data/lib/rails/generators/test_unit/job/templates/unit_test.rb.tt +1 -1
  124. data/lib/rails/generators/test_unit/mailer/templates/functional_test.rb.tt +1 -1
  125. data/lib/rails/generators/test_unit/model/templates/fixtures.yml.tt +1 -1
  126. data/lib/rails/generators/test_unit/model/templates/unit_test.rb.tt +1 -1
  127. data/lib/rails/generators/test_unit/plugin/templates/%file_name%_test.rb.tt +1 -1
  128. data/lib/rails/generators/test_unit/plugin/templates/test_helper.rb +2 -2
  129. data/lib/rails/generators/test_unit/scaffold/templates/api_functional_test.rb.tt +1 -1
  130. data/lib/rails/generators/test_unit/scaffold/templates/functional_test.rb.tt +1 -1
  131. data/lib/rails/generators/testing/assertions.rb +2 -2
  132. data/lib/rails/generators/testing/behaviour.rb +1 -1
  133. data/lib/rails/generators.rb +29 -15
  134. data/lib/rails/info.rb +1 -1
  135. data/lib/rails/info_controller.rb +1 -1
  136. data/lib/rails/mailers_controller.rb +1 -0
  137. data/lib/rails/paths.rb +14 -6
  138. data/lib/rails/railtie/configuration.rb +3 -2
  139. data/lib/rails/railtie.rb +31 -10
  140. data/lib/rails/source_annotation_extractor.rb +1 -15
  141. data/lib/rails/tasks/engine.rake +1 -4
  142. data/lib/rails/tasks/framework.rake +7 -1
  143. data/lib/rails/tasks/misc.rake +1 -1
  144. data/lib/rails/tasks/statistics.rake +1 -1
  145. data/lib/rails/tasks/yarn.rake +14 -2
  146. data/lib/rails/tasks.rb +0 -4
  147. data/lib/rails/templates/rails/mailers/email.html.erb +1 -0
  148. data/lib/rails/templates/rails/welcome/index.html.erb +1 -1
  149. data/lib/rails/test_unit/reporter.rb +2 -1
  150. data/lib/rails/test_unit/runner.rb +12 -3
  151. data/lib/rails/test_unit/testing.rake +6 -0
  152. data/lib/rails.rb +5 -8
  153. metadata +24 -30
  154. data/lib/rails/generators/rails/app/templates/config/databases/frontbase.yml.tt +0 -50
  155. data/lib/rails/generators/rails/app/templates/config/databases/ibm_db.yml.tt +0 -86
  156. data/lib/rails/generators/rails/app/templates/config/initializers/new_framework_defaults_6_0.rb.tt +0 -45
  157. data/lib/rails/generators/rails/plugin/templates/rails/application.rb.tt +0 -23
  158. data/lib/rails/tasks/annotations.rake +0 -22
  159. data/lib/rails/tasks/dev.rake +0 -11
  160. data/lib/rails/tasks/initializers.rake +0 -9
  161. data/lib/rails/tasks/routes.rake +0 -9
@@ -1,4 +1,6 @@
1
1
  # Be sure to restart your server when you modify this file.
2
2
 
3
3
  # Configure sensitive parameters which will be filtered from the log file.
4
- Rails.application.config.filter_parameters += [:password]
4
+ Rails.application.config.filter_parameters += [
5
+ :passw, :secret, :token, :_key, :crypt, :salt, :certificate, :otp, :ssn
6
+ ]
@@ -0,0 +1,67 @@
1
+ # Be sure to restart your server when you modify this file.
2
+ #
3
+ # This file contains migration options to ease your Rails 6.1 upgrade.
4
+ #
5
+ # Once upgraded flip defaults one by one to migrate to the new default.
6
+ #
7
+ # Read the Guide for Upgrading Ruby on Rails for more info on each option.
8
+
9
+ # Support for inversing belongs_to -> has_many Active Record associations.
10
+ # Rails.application.config.active_record.has_many_inversing = true
11
+
12
+ # Track Active Storage variants in the database.
13
+ # Rails.application.config.active_storage.track_variants = true
14
+
15
+ # Apply random variation to the delay when retrying failed jobs.
16
+ # Rails.application.config.active_job.retry_jitter = 0.15
17
+
18
+ # Stop executing `after_enqueue`/`after_perform` callbacks if
19
+ # `before_enqueue`/`before_perform` respectively halts with `throw :abort`.
20
+ # Rails.application.config.active_job.skip_after_callbacks_if_terminated = true
21
+
22
+ # Specify cookies SameSite protection level: either :none, :lax, or :strict.
23
+ #
24
+ # This change is not backwards compatible with earlier Rails versions.
25
+ # It's best enabled when your entire app is migrated and stable on 6.1.
26
+ # Rails.application.config.action_dispatch.cookies_same_site_protection = :lax
27
+
28
+ # Generate CSRF tokens that are encoded in URL-safe Base64.
29
+ #
30
+ # This change is not backwards compatible with earlier Rails versions.
31
+ # It's best enabled when your entire app is migrated and stable on 6.1.
32
+ # Rails.application.config.action_controller.urlsafe_csrf_tokens = true
33
+
34
+ # Specify whether `ActiveSupport::TimeZone.utc_to_local` returns a time with an
35
+ # UTC offset or a UTC time.
36
+ # ActiveSupport.utc_to_local_returns_utc_offset_times = true
37
+
38
+ # Change the default HTTP status code to `308` when redirecting non-GET/HEAD
39
+ # requests to HTTPS in `ActionDispatch::SSL` middleware.
40
+ # Rails.application.config.action_dispatch.ssl_default_redirect_status = 308
41
+
42
+ # Use new connection handling API. For most applications this won't have any
43
+ # effect. For applications using multiple databases, this new API provides
44
+ # support for granular connection swapping.
45
+ # Rails.application.config.active_record.legacy_connection_handling = false
46
+
47
+ # Make `form_with` generate non-remote forms by default.
48
+ # Rails.application.config.action_view.form_with_generates_remote_forms = false
49
+
50
+ # Set the default queue name for the analysis job to the queue adapter default.
51
+ # Rails.application.config.active_storage.queues.analysis = nil
52
+
53
+ # Set the default queue name for the purge job to the queue adapter default.
54
+ # Rails.application.config.active_storage.queues.purge = nil
55
+
56
+ # Set the default queue name for the incineration job to the queue adapter default.
57
+ # Rails.application.config.action_mailbox.queues.incineration = nil
58
+
59
+ # Set the default queue name for the routing job to the queue adapter default.
60
+ # Rails.application.config.action_mailbox.queues.routing = nil
61
+
62
+ # Set the default queue name for the mail deliver job to the queue adapter default.
63
+ # Rails.application.config.action_mailer.deliver_later_queue_name = nil
64
+
65
+ # Generate a `Link` header that gives a hint to modern browsers about
66
+ # preloading assets when using `javascript_include_tag` and `stylesheet_link_tag`.
67
+ # Rails.application.config.action_view.preload_links_header = true
@@ -0,0 +1,11 @@
1
+ # Define an application-wide HTTP permissions policy. For further
2
+ # information see https://developers.google.com/web/updates/2018/06/feature-policy
3
+ #
4
+ # Rails.application.config.permissions_policy do |f|
5
+ # f.camera :none
6
+ # f.gyroscope :none
7
+ # f.microphone :none
8
+ # f.usb :none
9
+ # f.fullscreen :self
10
+ # f.payment :self, "https://secure.example.com"
11
+ # end
@@ -8,9 +8,14 @@ max_threads_count = ENV.fetch("RAILS_MAX_THREADS") { 5 }
8
8
  min_threads_count = ENV.fetch("RAILS_MIN_THREADS") { max_threads_count }
9
9
  threads min_threads_count, max_threads_count
10
10
 
11
+ # Specifies the `worker_timeout` threshold that Puma will use to wait before
12
+ # terminating a worker in development environments.
13
+ #
14
+ worker_timeout 3600 if ENV.fetch("RAILS_ENV", "development") == "development"
15
+
11
16
  # Specifies the `port` that Puma will listen on to receive requests; default is 3000.
12
17
  #
13
- port ENV.fetch("PORT") { 3000 }
18
+ port ENV.fetch("PORT") { 3000 }
14
19
 
15
20
  # Specifies the `environment` that Puma will run in.
16
21
  #
@@ -1,5 +1,6 @@
1
1
  # This file is used by Rack-based servers to start the application.
2
2
 
3
- require_relative 'config/environment'
3
+ require_relative "config/environment"
4
4
 
5
5
  run Rails.application
6
+ Rails.application.load_server
@@ -1,5 +1,5 @@
1
1
  # This file should contain all the record creation needed to seed the database with its default values.
2
- # The data can then be loaded with the rails db:seed command (or created alongside the database with db:setup).
2
+ # The data can then be loaded with the bin/rails db:seed command (or created alongside the database with db:setup).
3
3
  #
4
4
  # Examples:
5
5
  #
@@ -0,0 +1,14 @@
1
+ # See https://git-scm.com/docs/gitattributes for more about git attribute files.
2
+
3
+ <% unless options[:skip_active_record] -%>
4
+ # Mark the database schema as having been generated.
5
+ db/schema.rb linguist-generated
6
+ <% end -%>
7
+
8
+ <% unless options[:skip_javascript] -%>
9
+ # Mark the yarn lockfile as having been generated.
10
+ yarn.lock linguist-generated
11
+ <% end -%>
12
+
13
+ # Mark any vendored files as having been vendored.
14
+ vendor/* linguist-vendored
@@ -10,7 +10,6 @@
10
10
  <% if sqlite3? -%>
11
11
  # Ignore the default SQLite database.
12
12
  /db/*.sqlite3
13
- /db/*.sqlite3-journal
14
13
  /db/*.sqlite3-*
15
14
 
16
15
  <% end -%>
@@ -1,5 +1,5 @@
1
1
  {
2
- "name": "<%= app_name %>",
2
+ "name": "<%= app_name.underscore.dasherize %>",
3
3
  "private": true,
4
4
  "dependencies": {
5
5
  "@rails/ujs": "^6.0.0"<% unless options[:skip_turbolinks] %>,
@@ -1,13 +1,13 @@
1
1
  ENV['RAILS_ENV'] ||= 'test'
2
- require_relative '../config/environment'
3
- require 'rails/test_help'
2
+ require_relative "../config/environment"
3
+ require "rails/test_help"
4
4
 
5
5
  class ActiveSupport::TestCase
6
6
  # Run tests in parallel with specified workers
7
- <% if defined?(JRUBY_VERSION) || Gem.win_platform? -%>
8
- parallelize(workers: :number_of_processors, with: :threads)
9
- <%- else -%>
7
+ <% if Process.respond_to?(:fork) && !Gem.win_platform? -%>
10
8
  parallelize(workers: :number_of_processors)
9
+ <%- else -%>
10
+ parallelize(workers: :number_of_processors, with: :threads)
11
11
  <% end -%>
12
12
 
13
13
  <% unless options[:skip_active_record] -%>
@@ -1,5 +1,5 @@
1
1
  Description:
2
- Stubs out new asset placeholders. Pass the asset name, either CamelCased
2
+ Generates new asset placeholders. Pass the asset name, either CamelCased
3
3
  or under_scored.
4
4
 
5
5
  To create an asset within a folder, specify the asset's name as a
@@ -10,8 +10,7 @@ Description:
10
10
  If Sass 3 is available, stylesheets will be generated with the .scss extension.
11
11
 
12
12
  Example:
13
- `rails generate assets posts`
13
+ `bin/rails generate assets posts`
14
14
 
15
15
  Posts assets.
16
16
  Stylesheet: app/assets/stylesheets/posts.css
17
-
@@ -0,0 +1,19 @@
1
+ Description:
2
+ Generate benchmarks to compare performance optimizations.
3
+
4
+ Makes use of the `benchmark-ips` gem as it provides a number of benefits like:
5
+ - Simple significance test
6
+ - Automatic warmup
7
+ - No need to specify the number of iterations
8
+
9
+ Example:
10
+ `bin/rails generate benchmark opt_compare`
11
+
12
+ This will create:
13
+ script/benchmarks/opt_compare.rb
14
+
15
+ You can run the generated benchmark file using:
16
+ `ruby script/benchmarks/opt_compare.rb`
17
+
18
+ You can specify different reports:
19
+ `bin/rails generate benchmark opt_compare patch1 patch2 patch3`
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "rails/generators/named_base"
4
+
5
+ module Rails
6
+ module Generators
7
+ class BenchmarkGenerator < NamedBase
8
+ IPS_GEM_NAME = "benchmark-ips"
9
+
10
+ argument :reports, type: :array, default: ["before", "after"]
11
+
12
+ def generate_layout
13
+ add_ips_to_gemfile unless ips_installed?
14
+ template("benchmark.rb.tt", "script/benchmarks/#{file_name}.rb")
15
+ end
16
+
17
+ private
18
+ def add_ips_to_gemfile
19
+ gem(IPS_GEM_NAME, group: [:development, :test])
20
+ end
21
+
22
+ def ips_installed?
23
+ in_root do
24
+ return File.read("Gemfile").match?(/gem.*\b#{IPS_GEM_NAME}\b.*/)
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "../../config/environment"
4
+
5
+ # Any benchmarking setup goes here...
6
+
7
+
8
+
9
+ Benchmark.ips do |x|
10
+ <%- reports.each do |report| -%>
11
+ x.report("<%= report %>") { }
12
+ <%- end -%>
13
+
14
+ x.compare!
15
+ end
@@ -1,5 +1,5 @@
1
1
  Description:
2
- Stubs out a new controller and its views. Pass the controller name, either
2
+ Generates a new controller and its views. Pass the controller name, either
3
3
  CamelCased or under_scored, and a list of views as arguments.
4
4
 
5
5
  To create a controller within a module, specify the controller name as a
@@ -9,7 +9,7 @@ Description:
9
9
  template engine, assets, and test framework generators.
10
10
 
11
11
  Example:
12
- `rails generate controller CreditCards open debit credit close`
12
+ `bin/rails generate controller CreditCards open debit credit close`
13
13
 
14
14
  CreditCards controller with URLs like /credit_cards/debit.
15
15
  Controller: app/controllers/credit_cards_controller.rb
@@ -17,7 +17,8 @@ module Rails
17
17
  def add_routes
18
18
  return if options[:skip_routes]
19
19
  return if actions.empty?
20
- route generate_routing_code
20
+ routing_code = actions.map { |action| "get '#{file_name}/#{action}'" }.join("\n")
21
+ route routing_code, namespace: regular_class_path
21
22
  end
22
23
 
23
24
  hook_for :template_engine, :test_framework, :helper, :assets do |generator|
@@ -32,45 +33,6 @@ module Rails
32
33
  def remove_possible_suffix(name)
33
34
  name.sub(/_?controller$/i, "")
34
35
  end
35
-
36
- # This method creates nested route entry for namespaced resources.
37
- # For eg. rails g controller foo/bar/baz index show
38
- # Will generate -
39
- # namespace :foo do
40
- # namespace :bar do
41
- # get 'baz/index'
42
- # get 'baz/show'
43
- # end
44
- # end
45
- def generate_routing_code
46
- depth = 0
47
- lines = []
48
-
49
- # Create 'namespace' ladder
50
- # namespace :foo do
51
- # namespace :bar do
52
- regular_class_path.each do |ns|
53
- lines << indent("namespace :#{ns} do\n", depth * 2)
54
- depth += 1
55
- end
56
-
57
- # Create route
58
- # get 'baz/index'
59
- # get 'baz/show'
60
- actions.each do |action|
61
- lines << indent(%{get '#{file_name}/#{action}'\n}, depth * 2)
62
- end
63
-
64
- # Create `end` ladder
65
- # end
66
- # end
67
- until depth.zero?
68
- depth -= 1
69
- lines << indent("end\n", depth * 2)
70
- end
71
-
72
- lines.join
73
- end
74
36
  end
75
37
  end
76
38
  end
@@ -20,7 +20,7 @@ module Rails
20
20
 
21
21
  add_credentials_file_silently(template)
22
22
 
23
- say "You can edit encrypted credentials with `rails credentials:edit`."
23
+ say "You can edit encrypted credentials with `bin/rails credentials:edit`."
24
24
  say ""
25
25
  end
26
26
  end
@@ -1,9 +1,9 @@
1
1
  Description:
2
- Stubs out a new generator at lib/generators. Pass the generator name as an argument,
2
+ Generates a new generator at lib/generators. Pass the generator name as an argument,
3
3
  either CamelCased or snake_cased.
4
4
 
5
5
  Example:
6
- `rails generate generator Awesome`
6
+ `bin/rails generate generator Awesome`
7
7
 
8
8
  creates a standard awesome generator:
9
9
  lib/generators/awesome/
@@ -2,7 +2,7 @@ Description:
2
2
  Explain the generator
3
3
 
4
4
  Example:
5
- rails generate <%= file_name %> Thing
5
+ bin/rails generate <%= file_name %> Thing
6
6
 
7
7
  This will create:
8
8
  what/will/it/create
@@ -1,13 +1,12 @@
1
1
  Description:
2
- Stubs out a new helper. Pass the helper name, either CamelCased
2
+ Generates a new helper. Pass the helper name, either CamelCased
3
3
  or under_scored.
4
4
 
5
5
  To create a helper within a module, specify the helper name as a
6
6
  path like 'parent_module/helper_name'.
7
7
 
8
8
  Example:
9
- `rails generate helper CreditCard`
9
+ `bin/rails generate helper CreditCard`
10
10
 
11
11
  Credit card helper.
12
12
  Helper: app/helpers/credit_card_helper.rb
13
-
@@ -1,10 +1,10 @@
1
1
  Description:
2
- Stubs out a new integration test. Pass the name of the test, either
2
+ Generates a new integration test. Pass the name of the test, either
3
3
  CamelCased or under_scored, as an argument.
4
4
 
5
5
  This generator invokes the current integration tool, which defaults to
6
6
  TestUnit.
7
7
 
8
8
  Example:
9
- `rails generate integration_test GeneralStories` creates a GeneralStories
9
+ `bin/rails generate integration_test GeneralStories` creates a GeneralStories
10
10
  integration test in test/integration/general_stories_test.rb
@@ -1,5 +1,5 @@
1
1
  Description:
2
- Stubs out a new database migration. Pass the migration name, either
2
+ Generates a new database migration. Pass the migration name, either
3
3
  CamelCased or under_scored, and an optional list of attribute pairs as arguments.
4
4
 
5
5
  A migration class is generated in db/migrate prefixed by a timestamp of the current date and time.
@@ -8,12 +8,12 @@ Description:
8
8
  column lines from supplied attributes: AddColumnsToTable or RemoveColumnsFromTable
9
9
 
10
10
  Example:
11
- `rails generate migration AddSslFlag`
11
+ `bin/rails generate migration AddSslFlag`
12
12
 
13
13
  If the current date is May 14, 2008 and the current time 09:09:12, this creates the AddSslFlag migration
14
14
  db/migrate/20080514090912_add_ssl_flag.rb
15
15
 
16
- `rails generate migration AddTitleBodyToPost title:string body:text published:boolean`
16
+ `bin/rails generate migration AddTitleBodyToPost title:string body:text published:boolean`
17
17
 
18
18
  This will create the AddTitleBodyToPost in db/migrate/20080514090912_add_title_body_to_post.rb with this in the Change migration:
19
19
 
@@ -25,7 +25,7 @@ Migration names containing JoinTable will generate join tables for use with
25
25
  has_and_belongs_to_many associations.
26
26
 
27
27
  Example:
28
- `rails g migration CreateMediaJoinTable artists musics:uniq`
28
+ `bin/rails g migration CreateMediaJoinTable artists musics:uniq`
29
29
 
30
30
  will create the migration
31
31
 
@@ -1,5 +1,5 @@
1
1
  Description:
2
- Stubs out a new model. Pass the model name, either CamelCased or
2
+ Generates a new model. Pass the model name, either CamelCased or
3
3
  under_scored, and an optional list of attribute pairs as arguments.
4
4
 
5
5
  Attribute pairs are field:type arguments specifying the
@@ -29,7 +29,7 @@ Available field types:
29
29
  Just after the field name you can specify a type like text or boolean.
30
30
  It will generate the column with the associated SQL type. For instance:
31
31
 
32
- `rails generate model post title:string body:text`
32
+ `bin/rails generate model post title:string body:text`
33
33
 
34
34
  will generate a title column with a varchar type and a body column with a text
35
35
  type. If no type is specified the string type will be used by default.
@@ -49,47 +49,47 @@ Available field types:
49
49
 
50
50
  You can also consider `references` as a kind of type. For instance, if you run:
51
51
 
52
- `rails generate model photo title:string album:references`
52
+ `bin/rails generate model photo title:string album:references`
53
53
 
54
54
  It will generate an `album_id` column. You should generate these kinds of fields when
55
55
  you will use a `belongs_to` association, for instance. `references` also supports
56
56
  polymorphism, you can enable polymorphism like this:
57
57
 
58
- `rails generate model product supplier:references{polymorphic}`
58
+ `bin/rails generate model product supplier:references{polymorphic}`
59
59
 
60
60
  For integer, string, text and binary fields, an integer in curly braces will
61
61
  be set as the limit:
62
62
 
63
- `rails generate model user pseudo:string{30}`
63
+ `bin/rails generate model user pseudo:string{30}`
64
64
 
65
65
  For decimal, two integers separated by a comma in curly braces will be used
66
66
  for precision and scale:
67
67
 
68
- `rails generate model product 'price:decimal{10,2}'`
68
+ `bin/rails generate model product 'price:decimal{10,2}'`
69
69
 
70
70
  You can add a `:uniq` or `:index` suffix for unique or standard indexes
71
71
  respectively:
72
72
 
73
- `rails generate model user pseudo:string:uniq`
74
- `rails generate model user pseudo:string:index`
73
+ `bin/rails generate model user pseudo:string:uniq`
74
+ `bin/rails generate model user pseudo:string:index`
75
75
 
76
76
  You can combine any single curly brace option with the index options:
77
77
 
78
- `rails generate model user username:string{30}:uniq`
79
- `rails generate model product supplier:references{polymorphic}:index`
78
+ `bin/rails generate model user username:string{30}:uniq`
79
+ `bin/rails generate model product supplier:references{polymorphic}:index`
80
80
 
81
81
  If you require a `password_digest` string column for use with
82
82
  has_secure_password, you can specify `password:digest`:
83
83
 
84
- `rails generate model user password:digest`
84
+ `bin/rails generate model user password:digest`
85
85
 
86
86
  If you require a `token` string column for use with
87
87
  has_secure_token, you can specify `auth_token:token`:
88
88
 
89
- `rails generate model user auth_token:token`
89
+ `bin/rails generate model user auth_token:token`
90
90
 
91
91
  Examples:
92
- `rails generate model account`
92
+ `bin/rails generate model account`
93
93
 
94
94
  For Active Record and TestUnit it creates:
95
95
 
@@ -98,11 +98,11 @@ Examples:
98
98
  Fixtures: test/fixtures/accounts.yml
99
99
  Migration: db/migrate/XXX_create_accounts.rb
100
100
 
101
- `rails generate model post title:string body:text published:boolean`
101
+ `bin/rails generate model post title:string body:text published:boolean`
102
102
 
103
103
  Creates a Post model with a string title, text body, and published flag.
104
104
 
105
- `rails generate model admin/account`
105
+ `bin/rails generate model admin/account`
106
106
 
107
107
  For Active Record and TestUnit it creates:
108
108
 
@@ -111,4 +111,3 @@ Examples:
111
111
  Test: test/models/admin/account_test.rb
112
112
  Fixtures: test/fixtures/admin/accounts.yml
113
113
  Migration: db/migrate/XXX_create_admin_accounts.rb
114
-
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "active_support/core_ext/hash/except"
3
4
  require "rails/generators/rails/app/app_generator"
4
5
  require "date"
5
6
 
@@ -24,10 +25,14 @@ module Rails
24
25
  directory "app"
25
26
  empty_directory_with_keep_file "app/assets/images/#{namespaced_name}"
26
27
  end
28
+
29
+ remove_dir "app/mailers" if options[:skip_action_mailer]
30
+ remove_dir "app/jobs" if options[:skip_active_job]
27
31
  elsif full?
28
32
  empty_directory_with_keep_file "app/models"
29
33
  empty_directory_with_keep_file "app/controllers"
30
- empty_directory_with_keep_file "app/mailers"
34
+ empty_directory_with_keep_file "app/mailers" unless options[:skip_action_mailer]
35
+ empty_directory_with_keep_file "app/jobs" unless options[:skip_active_job]
31
36
 
32
37
  unless api?
33
38
  empty_directory_with_keep_file "app/assets/images/#{namespaced_name}"
@@ -57,6 +62,12 @@ module Rails
57
62
  template "gitignore", ".gitignore"
58
63
  end
59
64
 
65
+ def version_control
66
+ if !options[:skip_git] && !options[:pretend]
67
+ run "git init", capture: options[:quiet], abort_on_failure: false
68
+ end
69
+ end
70
+
60
71
  def lib
61
72
  template "lib/%namespaced_name%.rb"
62
73
  template "lib/tasks/%namespaced_name%_tasks.rake"
@@ -86,15 +97,13 @@ task default: :test
86
97
  end
87
98
  end
88
99
 
89
- PASSTHROUGH_OPTIONS = [
90
- :skip_active_record, :skip_active_storage, :skip_action_mailer, :skip_javascript, :skip_action_cable, :skip_sprockets, :database,
91
- :api, :quiet, :pretend, :skip
92
- ]
100
+ DUMMY_IGNORE_OPTIONS = %i[dev edge master template]
93
101
 
94
102
  def generate_test_dummy(force = false)
95
- opts = (options.dup || {}).keep_if { |k, _| PASSTHROUGH_OPTIONS.map(&:to_s).include?(k) }
103
+ opts = options.transform_keys(&:to_sym).except(*DUMMY_IGNORE_OPTIONS)
96
104
  opts[:force] = force
97
105
  opts[:skip_bundle] = true
106
+ opts[:skip_spring] = true
98
107
  opts[:skip_listen] = true
99
108
  opts[:skip_git] = true
100
109
  opts[:skip_turbolinks] = true
@@ -107,7 +116,11 @@ task default: :test
107
116
 
108
117
  def test_dummy_config
109
118
  template "rails/boot.rb", "#{dummy_path}/config/boot.rb", force: true
110
- template "rails/application.rb", "#{dummy_path}/config/application.rb", force: true
119
+
120
+ insert_into_file "#{dummy_path}/config/application.rb", <<~RUBY, after: /^Bundler\.require.+\n/
121
+ require #{namespaced_name.inspect}
122
+ RUBY
123
+
111
124
  if mountable?
112
125
  template "rails/routes.rb", "#{dummy_path}/config/routes.rb", force: true
113
126
  end
@@ -121,6 +134,7 @@ task default: :test
121
134
 
122
135
  def test_dummy_clean
123
136
  inside dummy_path do
137
+ remove_file ".ruby-version"
124
138
  remove_file "db/seeds.rb"
125
139
  remove_file "Gemfile"
126
140
  remove_file "lib/tasks"
@@ -176,7 +190,7 @@ task default: :test
176
190
  desc: "Generate a rails engine with bundled Rails application for testing"
177
191
 
178
192
  class_option :mountable, type: :boolean, default: false,
179
- desc: "Generate mountable isolated application"
193
+ desc: "Generate mountable isolated engine"
180
194
 
181
195
  class_option :skip_gemspec, type: :boolean, default: false,
182
196
  desc: "Skip gemspec file"
@@ -203,6 +217,7 @@ task default: :test
203
217
  build(:license)
204
218
  build(:gitignore) unless options[:skip_git]
205
219
  build(:gemfile) unless options[:skip_gemfile]
220
+ build(:version_control)
206
221
  end
207
222
 
208
223
  def create_app_files
@@ -275,7 +290,6 @@ task default: :test
275
290
  say_status :vendor_app, dummy_path
276
291
  mute do
277
292
  build(:generate_test_dummy)
278
- store_application_definition!
279
293
  build(:test_dummy_config)
280
294
  build(:test_dummy_assets)
281
295
  build(:test_dummy_clean)
@@ -375,25 +389,13 @@ task default: :test
375
389
  end
376
390
  end
377
391
 
378
- def application_definition
379
- @application_definition ||= begin
380
-
381
- dummy_application_path = File.expand_path("#{dummy_path}/config/application.rb", destination_root)
382
- unless options[:pretend] || !File.exist?(dummy_application_path)
383
- contents = File.read(dummy_application_path)
384
- contents[(contents.index(/module ([\w]+)\n(.*)class Application/m))..-1]
385
- end
386
- end
387
- end
388
- alias :store_application_definition! :application_definition
389
-
390
392
  def get_builder_class
391
393
  defined?(::PluginBuilder) ? ::PluginBuilder : Rails::PluginBuilder
392
394
  end
393
395
 
394
396
  def rakefile_test_tasks
395
397
  <<-RUBY
396
- require 'rake/testtask'
398
+ require "rake/testtask"
397
399
 
398
400
  Rake::TestTask.new(:test) do |t|
399
401
  t.libs << 'test'
@@ -422,7 +424,7 @@ end
422
424
 
423
425
  def relative_path
424
426
  return unless inside_application?
425
- app_path.sub(/^#{rails_app_path}\//, "")
427
+ app_path.delete_prefix("#{rails_app_path}/")
426
428
  end
427
429
  end
428
430
  end