railties 5.2.4.1 → 6.0.1

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 +303 -132
  3. data/MIT-LICENSE +1 -1
  4. data/RDOC_MAIN.rdoc +38 -31
  5. data/README.rdoc +2 -2
  6. data/lib/minitest/rails_plugin.rb +7 -11
  7. data/lib/rails.rb +5 -0
  8. data/lib/rails/all.rb +4 -0
  9. data/lib/rails/api/generator.rb +2 -1
  10. data/lib/rails/api/task.rb +17 -0
  11. data/lib/rails/app_loader.rb +2 -2
  12. data/lib/rails/app_updater.rb +3 -1
  13. data/lib/rails/application.rb +72 -30
  14. data/lib/rails/application/bootstrap.rb +2 -10
  15. data/lib/rails/application/configuration.rb +113 -13
  16. data/lib/rails/application/default_middleware_stack.rb +3 -0
  17. data/lib/rails/application/dummy_erb_compiler.rb +18 -0
  18. data/lib/rails/application/finisher.rb +54 -0
  19. data/lib/rails/autoloaders.rb +48 -0
  20. data/lib/rails/backtrace_cleaner.rb +5 -17
  21. data/lib/rails/code_statistics.rb +3 -3
  22. data/lib/rails/command.rb +11 -10
  23. data/lib/rails/command/base.rb +12 -8
  24. data/lib/rails/command/behavior.rb +7 -48
  25. data/lib/rails/command/environment_argument.rb +8 -15
  26. data/lib/rails/command/spellchecker.rb +58 -0
  27. data/lib/rails/commands/console/console_command.rb +6 -0
  28. data/lib/rails/commands/credentials/USAGE +19 -1
  29. data/lib/rails/commands/credentials/credentials_command.rb +52 -19
  30. data/lib/rails/commands/db/system/change/change_command.rb +20 -0
  31. data/lib/rails/commands/dbconsole/dbconsole_command.rb +20 -8
  32. data/lib/rails/commands/dev/dev_command.rb +19 -0
  33. data/lib/rails/commands/encrypted/USAGE +1 -1
  34. data/lib/rails/commands/encrypted/encrypted_command.rb +2 -2
  35. data/lib/rails/commands/help/help_command.rb +1 -1
  36. data/lib/rails/commands/initializers/initializers_command.rb +23 -0
  37. data/lib/rails/commands/new/new_command.rb +2 -2
  38. data/lib/rails/commands/notes/notes_command.rb +39 -0
  39. data/lib/rails/commands/plugin/plugin_command.rb +1 -1
  40. data/lib/rails/commands/routes/routes_command.rb +37 -0
  41. data/lib/rails/commands/runner/runner_command.rb +13 -9
  42. data/lib/rails/commands/secrets/USAGE +3 -3
  43. data/lib/rails/commands/secrets/secrets_command.rb +3 -3
  44. data/lib/rails/commands/server/server_command.rb +113 -50
  45. data/lib/rails/configuration.rb +1 -7
  46. data/lib/rails/engine.rb +24 -16
  47. data/lib/rails/engine/configuration.rb +5 -2
  48. data/lib/rails/gem_version.rb +4 -4
  49. data/lib/rails/generators.rb +11 -10
  50. data/lib/rails/generators/actions.rb +52 -39
  51. data/lib/rails/generators/app_base.rb +53 -93
  52. data/lib/rails/generators/app_name.rb +50 -0
  53. data/lib/rails/generators/base.rb +0 -4
  54. data/lib/rails/generators/database.rb +58 -0
  55. data/lib/rails/generators/erb/mailer/mailer_generator.rb +1 -1
  56. data/lib/rails/generators/erb/scaffold/templates/_form.html.erb.tt +6 -3
  57. data/lib/rails/generators/erb/scaffold/templates/index.html.erb.tt +1 -1
  58. data/lib/rails/generators/erb/scaffold/templates/show.html.erb.tt +9 -1
  59. data/lib/rails/generators/generated_attribute.rb +53 -27
  60. data/lib/rails/generators/migration.rb +1 -2
  61. data/lib/rails/generators/model_helpers.rb +8 -1
  62. data/lib/rails/generators/named_base.rb +1 -5
  63. data/lib/rails/generators/rails/app/app_generator.rb +37 -71
  64. data/lib/rails/generators/rails/app/templates/Gemfile.tt +7 -10
  65. data/lib/rails/generators/rails/app/templates/app/assets/config/manifest.js.tt +0 -3
  66. data/lib/rails/generators/rails/app/templates/app/{assets/javascripts/cable.js.tt → javascript/channels/consumer.js} +2 -9
  67. data/lib/rails/generators/rails/app/templates/app/javascript/channels/index.js +5 -0
  68. data/lib/rails/generators/rails/app/templates/app/javascript/packs/application.js.tt +23 -0
  69. data/lib/rails/generators/rails/app/templates/app/jobs/application_job.rb.tt +5 -0
  70. data/lib/rails/generators/rails/app/templates/app/views/layouts/application.html.erb.tt +4 -4
  71. data/lib/rails/generators/rails/app/templates/bin/setup.tt +7 -7
  72. data/lib/rails/generators/rails/app/templates/config/application.rb.tt +2 -0
  73. data/lib/rails/generators/rails/app/templates/config/cable.yml.tt +1 -1
  74. data/lib/rails/generators/rails/app/templates/config/databases/frontbase.yml.tt +2 -2
  75. data/lib/rails/generators/rails/app/templates/config/databases/ibm_db.yml.tt +2 -2
  76. data/lib/rails/generators/rails/app/templates/config/databases/jdbc.yml.tt +2 -2
  77. data/lib/rails/generators/rails/app/templates/config/databases/jdbcmysql.yml.tt +3 -3
  78. data/lib/rails/generators/rails/app/templates/config/databases/jdbcpostgresql.yml.tt +3 -3
  79. data/lib/rails/generators/rails/app/templates/config/databases/jdbcsqlite3.yml.tt +1 -1
  80. data/lib/rails/generators/rails/app/templates/config/databases/mysql.yml.tt +4 -4
  81. data/lib/rails/generators/rails/app/templates/config/databases/oracle.yml.tt +2 -2
  82. data/lib/rails/generators/rails/app/templates/config/databases/postgresql.yml.tt +6 -6
  83. data/lib/rails/generators/rails/app/templates/config/databases/sqlite3.yml.tt +1 -1
  84. data/lib/rails/generators/rails/app/templates/config/databases/sqlserver.yml.tt +2 -2
  85. data/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt +5 -2
  86. data/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt +28 -12
  87. data/lib/rails/generators/rails/app/templates/config/environments/test.rb.tt +13 -6
  88. data/lib/rails/generators/rails/app/templates/config/initializers/assets.rb.tt +1 -1
  89. data/lib/rails/generators/rails/app/templates/config/initializers/content_security_policy.rb.tt +7 -0
  90. data/lib/rails/generators/rails/app/templates/config/initializers/new_framework_defaults_6_0.rb.tt +45 -0
  91. data/lib/rails/generators/rails/app/templates/config/locales/en.yml +1 -1
  92. data/lib/rails/generators/rails/app/templates/config/puma.rb.tt +4 -3
  93. data/lib/rails/generators/rails/app/templates/config/routes.rb.tt +1 -1
  94. data/lib/rails/generators/rails/app/templates/config/spring.rb.tt +6 -6
  95. data/lib/rails/generators/rails/app/templates/gitignore.tt +3 -7
  96. data/lib/rails/generators/rails/app/templates/package.json.tt +7 -1
  97. data/lib/rails/generators/rails/app/templates/public/robots.txt +1 -1
  98. data/lib/rails/generators/rails/app/templates/ruby-version.tt +1 -1
  99. data/lib/rails/generators/rails/app/templates/test/channels/application_cable/connection_test.rb.tt +11 -0
  100. data/lib/rails/generators/rails/app/templates/test/test_helper.rb.tt +7 -0
  101. data/lib/rails/generators/rails/assets/USAGE +1 -4
  102. data/lib/rails/generators/rails/assets/assets_generator.rb +0 -1
  103. data/lib/rails/generators/rails/controller/controller_generator.rb +11 -1
  104. data/lib/rails/generators/rails/credentials/credentials_generator.rb +7 -8
  105. data/lib/rails/generators/rails/db/system/change/change_generator.rb +65 -0
  106. data/lib/rails/generators/rails/encrypted_file/encrypted_file_generator.rb +4 -5
  107. data/lib/rails/generators/rails/helper/helper_generator.rb +5 -0
  108. data/lib/rails/generators/rails/plugin/plugin_generator.rb +9 -33
  109. data/lib/rails/generators/rails/plugin/templates/app/controllers/%namespaced_name%/application_controller.rb.tt +1 -1
  110. data/lib/rails/generators/rails/plugin/templates/app/helpers/%namespaced_name%/application_helper.rb.tt +1 -1
  111. data/lib/rails/generators/rails/plugin/templates/app/jobs/%namespaced_name%/application_job.rb.tt +1 -1
  112. data/lib/rails/generators/rails/plugin/templates/app/mailers/%namespaced_name%/application_mailer.rb.tt +1 -1
  113. data/lib/rails/generators/rails/plugin/templates/app/models/%namespaced_name%/application_record.rb.tt +1 -1
  114. data/lib/rails/generators/rails/plugin/templates/gitignore.tt +2 -1
  115. data/lib/rails/generators/rails/plugin/templates/lib/%namespaced_name%/engine.rb.tt +1 -1
  116. data/lib/rails/generators/rails/plugin/templates/lib/%namespaced_name%/railtie.rb.tt +1 -1
  117. data/lib/rails/generators/rails/plugin/templates/test/test_helper.rb.tt +1 -2
  118. data/lib/rails/generators/rails/scaffold_controller/scaffold_controller_generator.rb +14 -0
  119. data/lib/rails/generators/rails/scaffold_controller/templates/api_controller.rb.tt +1 -1
  120. data/lib/rails/generators/rails/scaffold_controller/templates/controller.rb.tt +1 -1
  121. data/lib/rails/generators/resource_helpers.rb +1 -6
  122. data/lib/rails/generators/test_unit/integration/integration_generator.rb +6 -0
  123. data/lib/rails/generators/test_unit/job/job_generator.rb +5 -0
  124. data/lib/rails/generators/test_unit/mailer/mailer_generator.rb +1 -1
  125. data/lib/rails/generators/test_unit/model/templates/fixtures.yml.tt +2 -2
  126. data/lib/rails/generators/test_unit/scaffold/scaffold_generator.rb +8 -3
  127. data/lib/rails/generators/test_unit/system/system_generator.rb +5 -0
  128. data/lib/rails/generators/testing/behaviour.rb +3 -0
  129. data/lib/rails/info.rb +3 -3
  130. data/lib/rails/info_controller.rb +1 -1
  131. data/lib/rails/mailers_controller.rb +7 -4
  132. data/lib/rails/paths.rb +19 -9
  133. data/lib/rails/railtie.rb +1 -1
  134. data/lib/rails/ruby_version_check.rb +3 -3
  135. data/lib/rails/secrets.rb +0 -1
  136. data/lib/rails/source_annotation_extractor.rb +138 -117
  137. data/lib/rails/tasks.rb +1 -0
  138. data/lib/rails/tasks/annotations.rake +9 -9
  139. data/lib/rails/tasks/dev.rake +5 -4
  140. data/lib/rails/tasks/framework.rake +5 -1
  141. data/lib/rails/tasks/initializers.rake +5 -4
  142. data/lib/rails/tasks/log.rake +0 -1
  143. data/lib/rails/tasks/routes.rake +4 -26
  144. data/lib/rails/tasks/statistics.rake +4 -0
  145. data/lib/rails/tasks/yarn.rake +1 -1
  146. data/lib/rails/tasks/zeitwerk.rake +66 -0
  147. data/lib/rails/templates/rails/welcome/index.html.erb +2 -2
  148. data/lib/rails/test_help.rb +11 -9
  149. data/lib/rails/test_unit/reporter.rb +1 -1
  150. data/lib/rails/test_unit/runner.rb +5 -5
  151. data/lib/rails/test_unit/testing.rake +1 -1
  152. metadata +34 -22
  153. data/lib/rails/generators/js/assets/assets_generator.rb +0 -15
  154. data/lib/rails/generators/js/assets/templates/javascript.js +0 -2
  155. data/lib/rails/generators/rails/app/templates/app/assets/javascripts/application.js.tt +0 -22
  156. data/lib/rails/generators/rails/app/templates/bin/bundle.tt +0 -2
  157. data/lib/rails/generators/rails/app/templates/bin/update.tt +0 -34
  158. data/lib/rails/generators/rails/app/templates/config/initializers/new_framework_defaults_5_2.rb.tt +0 -38
  159. data/lib/rails/generators/rails/assets/templates/javascript.js +0 -2
@@ -1,11 +1,17 @@
1
+ # The test environment is used exclusively to run your application's
2
+ # test suite. You never need to work with it otherwise. Remember that
3
+ # your test database is "scratch space" for the test suite and is wiped
4
+ # and recreated between test runs. Don't rely on the data there!
5
+
1
6
  Rails.application.configure do
2
7
  # Settings specified here will take precedence over those in config/application.rb.
3
8
 
4
- # The test environment is used exclusively to run your application's
5
- # test suite. You never need to work with it otherwise. Remember that
6
- # your test database is "scratch space" for the test suite and is wiped
7
- # and recreated between test runs. Don't rely on the data there!
9
+ <%-# Spring executes the reloaders when files change. %>
10
+ <%- if spring_install? -%>
11
+ config.cache_classes = false
12
+ <%- else -%>
8
13
  config.cache_classes = true
14
+ <%- end -%>
9
15
 
10
16
  # Do not eager load code on boot. This avoids loading your whole application
11
17
  # just for the purpose of running a single test. If you are using a tool that
@@ -21,6 +27,7 @@ Rails.application.configure do
21
27
  # Show full error reports and disable caching.
22
28
  config.consider_all_requests_local = true
23
29
  config.action_controller.perform_caching = false
30
+ config.cache_store = :null_store
24
31
 
25
32
  # Raise exceptions instead of rendering exception templates.
26
33
  config.action_dispatch.show_exceptions = false
@@ -29,7 +36,7 @@ Rails.application.configure do
29
36
  config.action_controller.allow_forgery_protection = false
30
37
 
31
38
  <%- unless skip_active_storage? -%>
32
- # Store uploaded files on the local file system in a temporary directory
39
+ # Store uploaded files on the local file system in a temporary directory.
33
40
  config.active_storage.service = :test
34
41
 
35
42
  <%- end -%>
@@ -45,6 +52,6 @@ Rails.application.configure do
45
52
  # Print deprecation notices to the stderr.
46
53
  config.active_support.deprecation = :stderr
47
54
 
48
- # Raises error for missing translations
55
+ # Raises error for missing translations.
49
56
  # config.action_view.raise_on_missing_translations = true
50
57
  end
@@ -5,7 +5,7 @@ Rails.application.config.assets.version = '1.0'
5
5
 
6
6
  # Add additional assets to the asset load path.
7
7
  # Rails.application.config.assets.paths << Emoji.images_path
8
- <%- unless options[:skip_yarn] -%>
8
+ <%- unless options[:skip_javascript] -%>
9
9
  # Add Yarn node_modules folder to the asset load path.
10
10
  Rails.application.config.assets.paths << Rails.root.join('node_modules')
11
11
  <%- end -%>
@@ -11,6 +11,10 @@
11
11
  # policy.object_src :none
12
12
  # policy.script_src :self, :https
13
13
  # policy.style_src :self, :https
14
+ <%- unless options[:skip_javascript] -%>
15
+ # # If you are using webpack-dev-server then specify webpack-dev-server host
16
+ # policy.connect_src :self, :https, "http://localhost:3035", "ws://localhost:3035" if Rails.env.development?
17
+ <%- end -%>
14
18
 
15
19
  # # Specify URI for violation reports
16
20
  # # policy.report_uri "/csp-violation-report-endpoint"
@@ -19,6 +23,9 @@
19
23
  # If you are using UJS then enable automatic nonce generation
20
24
  # Rails.application.config.content_security_policy_nonce_generator = -> request { SecureRandom.base64(16) }
21
25
 
26
+ # Set the nonce only to specific directives
27
+ # Rails.application.config.content_security_policy_nonce_directives = %w(script-src)
28
+
22
29
  # Report CSP violations to a specified URI
23
30
  # For further information see the following documentation:
24
31
  # https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy-Report-Only
@@ -0,0 +1,45 @@
1
+ # Be sure to restart your server when you modify this file.
2
+ #
3
+ # This file contains migration options to ease your Rails 6.0 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
+ # Don't force requests from old versions of IE to be UTF-8 encoded.
10
+ # Rails.application.config.action_view.default_enforce_utf8 = false
11
+
12
+ # Embed purpose and expiry metadata inside signed and encrypted
13
+ # cookies for increased security.
14
+ #
15
+ # This option is not backwards compatible with earlier Rails versions.
16
+ # It's best enabled when your entire app is migrated and stable on 6.0.
17
+ # Rails.application.config.action_dispatch.use_cookies_with_metadata = true
18
+
19
+ # Change the return value of `ActionDispatch::Response#content_type` to Content-Type header without modification.
20
+ # Rails.application.config.action_dispatch.return_only_media_type_on_content_type = false
21
+
22
+ # Return false instead of self when enqueuing is aborted from a callback.
23
+ # Rails.application.config.active_job.return_false_on_aborted_enqueue = true
24
+
25
+ # Send Active Storage analysis and purge jobs to dedicated queues.
26
+ # Rails.application.config.active_storage.queues.analysis = :active_storage_analysis
27
+ # Rails.application.config.active_storage.queues.purge = :active_storage_purge
28
+
29
+ # When assigning to a collection of attachments declared via `has_many_attached`, replace existing
30
+ # attachments instead of appending. Use #attach to add new attachments without replacing existing ones.
31
+ # Rails.application.config.active_storage.replace_on_assign_to_many = true
32
+
33
+ # Use ActionMailer::MailDeliveryJob for sending parameterized and normal mail.
34
+ #
35
+ # The default delivery jobs (ActionMailer::Parameterized::DeliveryJob, ActionMailer::DeliveryJob),
36
+ # will be removed in Rails 6.1. This setting is not backwards compatible with earlier Rails versions.
37
+ # If you send mail in the background, job workers need to have a copy of
38
+ # MailDeliveryJob to ensure all delivery jobs are processed properly.
39
+ # Make sure your entire app is migrated and stable on 6.0 before using this setting.
40
+ # Rails.application.config.action_mailer.delivery_job = "ActionMailer::MailDeliveryJob"
41
+
42
+ # Enable the same cache key to be reused when the object being cached of type
43
+ # `ActiveRecord::Relation` changes by moving the volatile information (max updated at and count)
44
+ # of the relation's cache key into the cache version to support recycling cache key.
45
+ # Rails.application.config.active_record.collection_cache_versioning = true
@@ -27,7 +27,7 @@
27
27
  # 'true': 'foo'
28
28
  #
29
29
  # To learn more, please read the Rails Internationalization guide
30
- # available at http://guides.rubyonrails.org/i18n.html.
30
+ # available at https://guides.rubyonrails.org/i18n.html.
31
31
 
32
32
  en:
33
33
  hello: "Hello world"
@@ -4,8 +4,9 @@
4
4
  # the maximum value specified for Puma. Default is set to 5 threads for minimum
5
5
  # and maximum; this matches the default thread size of Active Record.
6
6
  #
7
- threads_count = ENV.fetch("RAILS_MAX_THREADS") { 5 }
8
- threads threads_count, threads_count
7
+ max_threads_count = ENV.fetch("RAILS_MAX_THREADS") { 5 }
8
+ min_threads_count = ENV.fetch("RAILS_MIN_THREADS") { max_threads_count }
9
+ threads min_threads_count, max_threads_count
9
10
 
10
11
  # Specifies the `port` that Puma will listen on to receive requests; default is 3000.
11
12
  #
@@ -19,7 +20,7 @@ environment ENV.fetch("RAILS_ENV") { "development" }
19
20
  pidfile ENV.fetch("PIDFILE") { "tmp/pids/server.pid" }
20
21
 
21
22
  # Specifies the number of `workers` to boot in clustered mode.
22
- # Workers are forked webserver processes. If using threads and workers together
23
+ # Workers are forked web server processes. If using threads and workers together
23
24
  # the concurrency of the application would be max `threads` * `workers`.
24
25
  # Workers do not work on JRuby or Windows (both of which do not support
25
26
  # processes).
@@ -1,3 +1,3 @@
1
1
  Rails.application.routes.draw do
2
- # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
2
+ # For details on the DSL available within this file, see https://guides.rubyonrails.org/routing.html
3
3
  end
@@ -1,6 +1,6 @@
1
- %w[
2
- .ruby-version
3
- .rbenv-vars
4
- tmp/restart.txt
5
- tmp/caching-dev.txt
6
- ].each { |path| Spring.watch(path) }
1
+ Spring.watch(
2
+ ".ruby-version",
3
+ ".rbenv-vars",
4
+ "tmp/restart.txt",
5
+ "tmp/caching-dev.txt"
6
+ )
@@ -11,6 +11,7 @@
11
11
  # Ignore the default SQLite database.
12
12
  /db/*.sqlite3
13
13
  /db/*.sqlite3-journal
14
+ /db/*.sqlite3-*
14
15
 
15
16
  <% end -%>
16
17
  # Ignore all logfiles and tempfiles.
@@ -22,19 +23,14 @@
22
23
  <% end -%>
23
24
 
24
25
  <% unless skip_active_storage? -%>
25
- # Ignore uploaded files in development
26
+ # Ignore uploaded files in development.
26
27
  /storage/*
27
28
  <% if keeps? -%>
28
29
  !/storage/.keep
29
30
  <% end -%>
30
- <% end -%>
31
-
32
- <% unless options.skip_yarn? -%>
33
- /node_modules
34
- /yarn-error.log
35
-
36
31
  <% end -%>
37
32
  <% unless options.api? -%>
33
+
38
34
  /public/assets
39
35
  <% end -%>
40
36
  .byebug_history
@@ -1,5 +1,11 @@
1
1
  {
2
2
  "name": "<%= app_name %>",
3
3
  "private": true,
4
- "dependencies": {}
4
+ "dependencies": {
5
+ "@rails/ujs": "^6.0.0"<% unless options[:skip_turbolinks] %>,
6
+ "turbolinks": "^5.2.0"<% end -%><% unless skip_active_storage? %>,
7
+ "@rails/activestorage": "^6.0.0"<% end -%><% unless options[:skip_action_cable] %>,
8
+ "@rails/actioncable": "^6.0.0"<% end %>
9
+ },
10
+ "version": "0.1.0"
5
11
  }
@@ -1 +1 @@
1
- # See http://www.robotstxt.org/robotstxt.html for documentation on how to use the robots.txt file
1
+ # See https://www.robotstxt.org/robotstxt.html for documentation on how to use the robots.txt file
@@ -1 +1 @@
1
- <%= ENV["RBENV_VERSION"] || ENV["rvm_ruby_string"] || "#{RUBY_ENGINE}-#{defined?(JRUBY_VERSION) ? JRUBY_VERSION : RUBY_VERSION}" -%>
1
+ <%= ENV["RBENV_VERSION"] || ENV["rvm_ruby_string"] || "#{RUBY_ENGINE}-#{RUBY_ENGINE_VERSION}" %>
@@ -0,0 +1,11 @@
1
+ require "test_helper"
2
+
3
+ class ApplicationCable::ConnectionTest < ActionCable::Connection::TestCase
4
+ # test "connects with cookies" do
5
+ # cookies.signed[:user_id] = 42
6
+ #
7
+ # connect
8
+ #
9
+ # assert_equal connection.user_id, "42"
10
+ # end
11
+ end
@@ -3,6 +3,13 @@ require_relative '../config/environment'
3
3
  require 'rails/test_help'
4
4
 
5
5
  class ActiveSupport::TestCase
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 -%>
10
+ parallelize(workers: :number_of_processors)
11
+ <% end -%>
12
+
6
13
  <% unless options[:skip_active_record] -%>
7
14
  # Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order.
8
15
  fixtures :all
@@ -5,16 +5,13 @@ Description:
5
5
  To create an asset within a folder, specify the asset's name as a
6
6
  path like 'parent/name'.
7
7
 
8
- This generates a JavaScript stub in app/assets/javascripts and a stylesheet
9
- stub in app/assets/stylesheets.
8
+ This generates a stylesheet stub in app/assets/stylesheets.
10
9
 
11
- If CoffeeScript is available, JavaScripts will be generated with the .coffee extension.
12
10
  If Sass 3 is available, stylesheets will be generated with the .scss extension.
13
11
 
14
12
  Example:
15
13
  `rails generate assets posts`
16
14
 
17
15
  Posts assets.
18
- JavaScript: app/assets/javascripts/posts.js
19
16
  Stylesheet: app/assets/stylesheets/posts.css
20
17
 
@@ -10,7 +10,6 @@ module Rails
10
10
  class_option :stylesheet_engine, desc: "Engine for Stylesheets"
11
11
 
12
12
  private
13
-
14
13
  def asset_name
15
14
  file_name
16
15
  end
@@ -20,10 +20,20 @@ module Rails
20
20
  route generate_routing_code
21
21
  end
22
22
 
23
- hook_for :template_engine, :test_framework, :helper, :assets
23
+ hook_for :template_engine, :test_framework, :helper, :assets do |generator|
24
+ invoke generator, [ remove_possible_suffix(name), actions ]
25
+ end
24
26
 
25
27
  private
26
28
 
29
+ def file_name
30
+ @_file_name ||= remove_possible_suffix(super)
31
+ end
32
+
33
+ def remove_possible_suffix(name)
34
+ name.sub(/_?controller$/i, "")
35
+ end
36
+
27
37
  # This method creates nested route entry for namespaced resources.
28
38
  # For eg. rails g controller foo/bar/baz index show
29
39
  # Will generate -
@@ -2,7 +2,6 @@
2
2
 
3
3
  require "rails/generators/base"
4
4
  require "rails/generators/rails/master_key/master_key_generator"
5
- require "active_support/core_ext/string/strip"
6
5
  require "active_support/encrypted_configuration"
7
6
 
8
7
  module Rails
@@ -21,7 +20,7 @@ module Rails
21
20
 
22
21
  add_credentials_file_silently(template)
23
22
 
24
- say "You can edit encrypted credentials with `bin/rails credentials:edit`."
23
+ say "You can edit encrypted credentials with `rails credentials:edit`."
25
24
  say ""
26
25
  end
27
26
  end
@@ -43,13 +42,13 @@ module Rails
43
42
  end
44
43
 
45
44
  def credentials_template
46
- <<-YAML.strip_heredoc
47
- # aws:
48
- # access_key_id: 123
49
- # secret_access_key: 345
45
+ <<~YAML
46
+ # aws:
47
+ # access_key_id: 123
48
+ # secret_access_key: 345
50
49
 
51
- # Used as the base secret for all MessageVerifiers in Rails, including the one protecting cookies.
52
- secret_key_base: #{SecureRandom.hex(64)}
50
+ # Used as the base secret for all MessageVerifiers in Rails, including the one protecting cookies.
51
+ secret_key_base: #{SecureRandom.hex(64)}
53
52
  YAML
54
53
  end
55
54
  end
@@ -0,0 +1,65 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "rails/generators/base"
4
+
5
+ module Rails
6
+ module Generators
7
+ module Db
8
+ module System
9
+ class ChangeGenerator < Base # :nodoc:
10
+ include Database
11
+ include AppName
12
+
13
+ class_option :to, required: true,
14
+ desc: "The database system to switch to."
15
+
16
+ def self.default_generator_root
17
+ path = File.expand_path(File.join(base_name, "app"), base_root)
18
+ path if File.exist?(path)
19
+ end
20
+
21
+ def initialize(*)
22
+ super
23
+
24
+ unless DATABASES.include?(options[:to])
25
+ raise Error, "Invalid value for --to option. Supported preconfigurations are: #{DATABASES.join(", ")}."
26
+ end
27
+
28
+ opt = options.dup
29
+ opt[:database] ||= opt[:to]
30
+ self.options = opt.freeze
31
+ end
32
+
33
+ def edit_database_config
34
+ template("config/databases/#{options[:database]}.yml", "config/database.yml")
35
+ end
36
+
37
+ def edit_gemfile
38
+ name, version = gem_for_database
39
+ gsub_file("Gemfile", all_database_gems_regex, name)
40
+ gsub_file("Gemfile", gem_entry_regex_for(name), gem_entry_for(name, *version))
41
+ end
42
+
43
+ private
44
+ def all_database_gems
45
+ DATABASES.map { |database| gem_for_database(database) }
46
+ end
47
+
48
+ def all_database_gems_regex
49
+ all_database_gem_names = all_database_gems.map(&:first)
50
+ /(\b#{all_database_gem_names.join('\b|\b')}\b)/
51
+ end
52
+
53
+ def gem_entry_regex_for(gem_name)
54
+ /^gem.*\b#{gem_name}\b.*/
55
+ end
56
+
57
+ def gem_entry_for(*gem_name_and_version)
58
+ gem_name_and_version.map! { |segment| "'#{segment}'" }
59
+ "gem #{gem_name_and_version.join(", ")}"
60
+ end
61
+ end
62
+ end
63
+ end
64
+ end
65
+ end
@@ -1,7 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "rails/generators/base"
4
- require "active_support/core_ext/string/strip"
5
4
  require "active_support/encrypted_file"
6
5
 
7
6
  module Rails
@@ -16,10 +15,10 @@ module Rails
16
15
 
17
16
  private
18
17
  def encrypted_file_template
19
- <<-YAML.strip_heredoc
20
- # aws:
21
- # access_key_id: 123
22
- # secret_access_key: 345
18
+ <<~YAML
19
+ # aws:
20
+ # access_key_id: 123
21
+ # secret_access_key: 345
23
22
 
24
23
  YAML
25
24
  end
@@ -10,6 +10,11 @@ module Rails
10
10
  end
11
11
 
12
12
  hook_for :test_framework
13
+
14
+ private
15
+ def file_name
16
+ @_file_name ||= super.sub(/_helper\z/i, "")
17
+ end
13
18
  end
14
19
  end
15
20
  end
@@ -88,7 +88,7 @@ task default: :test
88
88
 
89
89
  PASSTHROUGH_OPTIONS = [
90
90
  :skip_active_record, :skip_active_storage, :skip_action_mailer, :skip_javascript, :skip_action_cable, :skip_sprockets, :database,
91
- :javascript, :skip_yarn, :api, :quiet, :pretend, :skip
91
+ :api, :quiet, :pretend, :skip
92
92
  ]
93
93
 
94
94
  def generate_test_dummy(force = false)
@@ -98,6 +98,7 @@ task default: :test
98
98
  opts[:skip_listen] = true
99
99
  opts[:skip_git] = true
100
100
  opts[:skip_turbolinks] = true
101
+ opts[:skip_webpack_install] = true
101
102
  opts[:dummy_app] = true
102
103
 
103
104
  invoke Rails::Generators::AppGenerator,
@@ -113,7 +114,7 @@ task default: :test
113
114
  end
114
115
 
115
116
  def test_dummy_assets
116
- template "rails/javascripts.js", "#{dummy_path}/app/assets/javascripts/application.js", force: true
117
+ template "rails/javascripts.js", "#{dummy_path}/app/javascript/packs/application.js", force: true
117
118
  template "rails/stylesheets.css", "#{dummy_path}/app/assets/stylesheets/application.css", force: true
118
119
  template "rails/dummy_manifest.js", "#{dummy_path}/app/assets/config/manifest.js", force: true
119
120
  end
@@ -143,17 +144,6 @@ task default: :test
143
144
  end
144
145
  end
145
146
 
146
- def javascripts
147
- return if options.skip_javascript?
148
-
149
- if mountable?
150
- template "rails/javascripts.js",
151
- "app/assets/javascripts/#{namespaced_name}/application.js"
152
- elsif full?
153
- empty_directory_with_keep_file "app/assets/javascripts/#{namespaced_name}"
154
- end
155
- end
156
-
157
147
  def bin(force = false)
158
148
  bin_file = engine? ? "bin/rails.tt" : "bin/test.tt"
159
149
  template bin_file, force: force do |content|
@@ -235,10 +225,6 @@ task default: :test
235
225
  build(:stylesheets) unless api?
236
226
  end
237
227
 
238
- def create_javascript_files
239
- build(:javascripts) unless api?
240
- end
241
-
242
228
  def create_bin_files
243
229
  build(:bin)
244
230
  end
@@ -262,16 +248,6 @@ task default: :test
262
248
 
263
249
  public_task :apply_rails_template
264
250
 
265
- def run_after_bundle_callbacks
266
- unless @after_bundle_callbacks.empty?
267
- ActiveSupport::Deprecation.warn("`after_bundle` is deprecated and will be removed in the next version of Rails. ")
268
- end
269
-
270
- @after_bundle_callbacks.each do |callback|
271
- callback.call
272
- end
273
- end
274
-
275
251
  def name
276
252
  @name ||= begin
277
253
  # same as ActiveSupport::Inflector#underscore except not replacing '-'
@@ -348,9 +324,9 @@ task default: :test
348
324
  def wrap_in_modules(unwrapped_code)
349
325
  unwrapped_code = "#{unwrapped_code}".strip.gsub(/\s$\n/, "")
350
326
  modules.reverse.inject(unwrapped_code) do |content, mod|
351
- str = "module #{mod}\n"
352
- str += content.lines.map { |line| " #{line}" }.join
353
- str += content.present? ? "\nend" : "end"
327
+ str = +"module #{mod}\n"
328
+ str << content.lines.map { |line| " #{line}" }.join
329
+ str << (content.present? ? "\nend" : "end")
354
330
  end
355
331
  end
356
332
 
@@ -385,11 +361,11 @@ task default: :test
385
361
  end
386
362
 
387
363
  def valid_const?
388
- if original_name =~ /-\d/
364
+ if /-\d/.match?(original_name)
389
365
  raise Error, "Invalid plugin name #{original_name}. Please give a name which does not contain a namespace starting with numeric characters."
390
- elsif original_name =~ /[^\w-]+/
366
+ elsif /[^\w-]+/.match?(original_name)
391
367
  raise Error, "Invalid plugin name #{original_name}. Please give a name which uses only alphabetic, numeric, \"_\" or \"-\" characters."
392
- elsif camelized =~ /^\d/
368
+ elsif /^\d/.match?(camelized)
393
369
  raise Error, "Invalid plugin name #{original_name}. Please give a name which does not start with numbers."
394
370
  elsif RESERVED_NAMES.include?(name)
395
371
  raise Error, "Invalid plugin name #{original_name}. Please give a " \