railties 7.1.3.4 → 7.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (130) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +177 -742
  3. data/lib/minitest/rails_plugin.rb +5 -2
  4. data/lib/rails/all.rb +1 -3
  5. data/lib/rails/api/task.rb +6 -4
  6. data/lib/rails/application/bootstrap.rb +5 -6
  7. data/lib/rails/application/configuration.rb +73 -38
  8. data/lib/rails/application/dummy_config.rb +2 -2
  9. data/lib/rails/application/finisher.rb +7 -0
  10. data/lib/rails/application.rb +15 -86
  11. data/lib/rails/backtrace_cleaner.rb +18 -3
  12. data/lib/rails/cli.rb +0 -1
  13. data/lib/rails/command.rb +1 -1
  14. data/lib/rails/commands/app/update_command.rb +93 -0
  15. data/lib/rails/commands/boot/boot_command.rb +14 -0
  16. data/lib/rails/commands/console/console_command.rb +2 -21
  17. data/lib/rails/commands/console/irb_console.rb +137 -0
  18. data/lib/rails/commands/credentials/credentials_command.rb +2 -2
  19. data/lib/rails/commands/dbconsole/dbconsole_command.rb +21 -30
  20. data/lib/rails/commands/devcontainer/devcontainer_command.rb +39 -0
  21. data/lib/rails/commands/rake/rake_command.rb +1 -1
  22. data/lib/rails/commands/runner/runner_command.rb +14 -3
  23. data/lib/rails/commands/server/server_command.rb +5 -3
  24. data/lib/rails/commands/test/test_command.rb +2 -0
  25. data/lib/rails/configuration.rb +10 -1
  26. data/lib/rails/console/app.rb +5 -32
  27. data/lib/rails/console/helpers.rb +5 -16
  28. data/lib/rails/console/methods.rb +23 -0
  29. data/lib/rails/engine.rb +5 -5
  30. data/lib/rails/gem_version.rb +3 -3
  31. data/lib/rails/generators/app_base.rb +70 -49
  32. data/lib/rails/generators/base.rb +5 -1
  33. data/lib/rails/generators/database.rb +227 -69
  34. data/lib/rails/generators/erb/scaffold/templates/edit.html.erb.tt +2 -0
  35. data/lib/rails/generators/erb/scaffold/templates/index.html.erb.tt +2 -0
  36. data/lib/rails/generators/erb/scaffold/templates/new.html.erb.tt +2 -0
  37. data/lib/rails/generators/generated_attribute.rb +26 -1
  38. data/lib/rails/generators/migration.rb +3 -3
  39. data/lib/rails/generators/rails/app/app_generator.rb +53 -24
  40. data/lib/rails/generators/rails/app/templates/Dockerfile.tt +22 -15
  41. data/lib/rails/generators/rails/app/templates/Gemfile.tt +16 -16
  42. data/lib/rails/generators/rails/app/templates/app/controllers/application_controller.rb.tt +4 -0
  43. data/lib/rails/generators/rails/app/templates/app/views/layouts/application.html.erb.tt +8 -1
  44. data/lib/rails/generators/rails/app/templates/app/views/pwa/manifest.json.erb.tt +22 -0
  45. data/lib/rails/generators/rails/app/templates/app/views/pwa/service-worker.js +26 -0
  46. data/lib/rails/generators/rails/app/templates/bin/brakeman.tt +6 -0
  47. data/lib/rails/generators/rails/app/templates/bin/rubocop.tt +7 -0
  48. data/lib/rails/generators/rails/app/templates/bin/setup.tt +6 -2
  49. data/lib/rails/generators/rails/app/templates/config/application.rb.tt +1 -1
  50. data/lib/rails/generators/rails/app/templates/config/databases/mysql.yml.tt +3 -3
  51. data/lib/rails/generators/rails/app/templates/config/databases/postgresql.yml.tt +7 -0
  52. data/lib/rails/generators/rails/app/templates/config/databases/sqlite3.yml.tt +8 -1
  53. data/lib/rails/generators/rails/app/templates/config/databases/trilogy.yml.tt +3 -3
  54. data/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt +14 -7
  55. data/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt +5 -0
  56. data/lib/rails/generators/rails/app/templates/config/environments/test.rb.tt +8 -5
  57. data/lib/rails/generators/rails/app/templates/config/initializers/filter_parameter_logging.rb.tt +1 -1
  58. data/lib/rails/generators/rails/app/templates/config/initializers/new_framework_defaults_7_2.rb.tt +70 -0
  59. data/lib/rails/generators/rails/app/templates/config/puma.rb.tt +24 -26
  60. data/lib/rails/generators/rails/app/templates/config/routes.rb.tt +4 -0
  61. data/lib/rails/generators/rails/app/templates/docker-entrypoint.tt +5 -0
  62. data/lib/rails/generators/rails/app/templates/dockerignore.tt +13 -0
  63. data/lib/rails/generators/rails/app/templates/github/ci.yml.tt +138 -0
  64. data/lib/rails/generators/rails/app/templates/github/dependabot.yml +12 -0
  65. data/lib/rails/generators/rails/app/templates/gitignore.tt +3 -3
  66. data/lib/rails/generators/rails/app/templates/public/406-unsupported-browser.html +66 -0
  67. data/lib/rails/generators/rails/app/templates/public/icon.png +0 -0
  68. data/lib/rails/generators/rails/app/templates/public/icon.svg +3 -0
  69. data/lib/rails/generators/rails/app/templates/rubocop.yml.tt +8 -0
  70. data/lib/rails/generators/rails/app/templates/test/application_system_test_case.rb.tt +1 -1
  71. data/lib/rails/generators/rails/controller/controller_generator.rb +1 -1
  72. data/lib/rails/generators/rails/db/system/change/change_generator.rb +131 -20
  73. data/lib/rails/generators/rails/devcontainer/devcontainer_generator.rb +166 -0
  74. data/lib/rails/generators/rails/devcontainer/templates/devcontainer/Dockerfile.tt +3 -0
  75. data/lib/rails/generators/rails/devcontainer/templates/devcontainer/compose.yaml.tt +47 -0
  76. data/lib/rails/generators/rails/devcontainer/templates/devcontainer/devcontainer.json.tt +37 -0
  77. data/lib/rails/generators/rails/migration/migration_generator.rb +4 -0
  78. data/lib/rails/generators/rails/plugin/plugin_generator.rb +38 -7
  79. data/lib/rails/generators/rails/plugin/templates/%name%.gemspec.tt +2 -2
  80. data/lib/rails/generators/rails/plugin/templates/Gemfile.tt +5 -1
  81. data/lib/rails/generators/rails/plugin/templates/app/views/layouts/%namespaced_name%/application.html.erb.tt +2 -0
  82. data/lib/rails/generators/rails/plugin/templates/bin/rubocop.tt +7 -0
  83. data/lib/rails/generators/rails/plugin/templates/github/ci.yml.tt +103 -0
  84. data/lib/rails/generators/rails/plugin/templates/github/dependabot.yml +12 -0
  85. data/lib/rails/generators/rails/plugin/templates/rubocop.yml.tt +8 -0
  86. data/lib/rails/generators/rails/plugin/templates/test/application_system_test_case.rb.tt +1 -1
  87. data/lib/rails/generators/test_unit/mailer/templates/functional_test.rb.tt +6 -4
  88. data/lib/rails/generators/test_unit/mailer/templates/preview.rb.tt +3 -2
  89. data/lib/rails/generators/test_unit/scaffold/scaffold_generator.rb +15 -1
  90. data/lib/rails/generators/test_unit/scaffold/templates/api_functional_test.rb.tt +2 -2
  91. data/lib/rails/generators/test_unit/scaffold/templates/functional_test.rb.tt +2 -2
  92. data/lib/rails/generators/test_unit/scaffold/templates/system_test.rb.tt +2 -0
  93. data/lib/rails/generators/test_unit/system/templates/application_system_test_case.rb.tt +1 -1
  94. data/lib/rails/generators/testing/assertions.rb +20 -0
  95. data/lib/rails/generators/testing/behavior.rb +7 -6
  96. data/lib/rails/generators.rb +1 -1
  97. data/lib/rails/health_controller.rb +1 -1
  98. data/lib/rails/info.rb +2 -2
  99. data/lib/rails/mailers_controller.rb +14 -1
  100. data/lib/rails/paths.rb +2 -2
  101. data/lib/rails/pwa_controller.rb +15 -0
  102. data/lib/rails/rack/logger.rb +15 -7
  103. data/lib/rails/railtie/configurable.rb +2 -2
  104. data/lib/rails/railtie.rb +2 -3
  105. data/lib/rails/tasks/framework.rake +0 -26
  106. data/lib/rails/tasks/tmp.rake +1 -1
  107. data/lib/rails/templates/layouts/application.html.erb +1 -1
  108. data/lib/rails/templates/rails/mailers/email.html.erb +12 -8
  109. data/lib/rails/templates/rails/welcome/index.html.erb +4 -2
  110. data/lib/rails/test_help.rb +2 -4
  111. data/lib/rails/test_unit/reporter.rb +8 -2
  112. data/lib/rails/test_unit/runner.rb +26 -2
  113. data/lib/rails/test_unit/test_parser.rb +45 -0
  114. data/lib/rails.rb +7 -4
  115. metadata +42 -32
  116. data/lib/rails/app_updater.rb +0 -40
  117. data/lib/rails/commands/secrets/USAGE +0 -61
  118. data/lib/rails/commands/secrets/secrets_command.rb +0 -47
  119. data/lib/rails/generators/rails/app/templates/config/databases/jdbc.yml.tt +0 -68
  120. data/lib/rails/generators/rails/app/templates/config/databases/jdbcmysql.yml.tt +0 -54
  121. data/lib/rails/generators/rails/app/templates/config/databases/jdbcpostgresql.yml.tt +0 -70
  122. data/lib/rails/generators/rails/app/templates/config/databases/jdbcsqlite3.yml.tt +0 -24
  123. data/lib/rails/generators/rails/app/templates/config/databases/oracle.yml.tt +0 -62
  124. data/lib/rails/generators/rails/app/templates/config/databases/sqlserver.yml.tt +0 -53
  125. data/lib/rails/generators/rails/app/templates/config/initializers/new_framework_defaults_7_1.rb.tt +0 -284
  126. data/lib/rails/generators/rails/app/templates/public/apple-touch-icon-precomposed.png +0 -0
  127. data/lib/rails/generators/rails/app/templates/public/apple-touch-icon.png +0 -0
  128. data/lib/rails/generators/rails/app/templates/public/favicon.ico +0 -0
  129. data/lib/rails/ruby_version_check.rb +0 -17
  130. data/lib/rails/secrets.rb +0 -110
@@ -4,14 +4,6 @@ require "rails/command/environment_argument"
4
4
 
5
5
  module Rails
6
6
  class Console
7
- module BacktraceCleaner
8
- def filter_backtrace(bt)
9
- if result = super
10
- Rails.backtrace_cleaner.filter([result]).first
11
- end
12
- end
13
- end
14
-
15
7
  def self.start(*args)
16
8
  new(*args).start
17
9
  end
@@ -32,16 +24,8 @@ module Rails
32
24
  app.load_console
33
25
 
34
26
  @console = app.config.console || begin
35
- require "irb"
36
- require "irb/completion"
37
-
38
- IRB::WorkSpace.prepend(BacktraceCleaner)
39
-
40
- if !Rails.env.local?
41
- ENV["IRB_USE_AUTOCOMPLETE"] ||= "false"
42
- end
43
-
44
- IRB
27
+ require "rails/commands/console/irb_console"
28
+ IRBConsole.new(app)
45
29
  end
46
30
  end
47
31
 
@@ -72,9 +56,6 @@ module Rails
72
56
  puts "Loading #{Rails.env} environment (Rails #{Rails.version})"
73
57
  end
74
58
 
75
- if defined?(console::ExtendCommandBundle)
76
- console::ExtendCommandBundle.include(Rails::ConsoleMethods)
77
- end
78
59
  console.start
79
60
  end
80
61
  end
@@ -0,0 +1,137 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "irb/helper_method"
4
+ require "irb/command"
5
+
6
+ module Rails
7
+ class Console
8
+ class RailsHelperBase < IRB::HelperMethod::Base
9
+ include ConsoleMethods
10
+ end
11
+
12
+ class ControllerHelper < RailsHelperBase
13
+ description "Gets helper methods available to ApplicationController."
14
+
15
+ # This method assumes an +ApplicationController+ exists, and that it extends ActionController::Base.
16
+ def execute
17
+ ApplicationController.helpers
18
+ end
19
+ end
20
+
21
+ class ControllerInstance < RailsHelperBase
22
+ description "Gets a new instance of ApplicationController."
23
+
24
+ # This method assumes an +ApplicationController+ exists, and that it extends ActionController::Base.
25
+ def execute
26
+ @controller ||= ApplicationController.new
27
+ end
28
+ end
29
+
30
+ class NewSession < RailsHelperBase
31
+ description "[Deprecated] Please use `app(true)` instead."
32
+
33
+ def execute(*)
34
+ app = Rails.application
35
+ session = ActionDispatch::Integration::Session.new(app)
36
+
37
+ # This makes app.url_for and app.foo_path available in the console
38
+ session.extend(app.routes.url_helpers)
39
+ session.extend(app.routes.mounted_helpers)
40
+
41
+ session
42
+ end
43
+ end
44
+
45
+ class AppInstance < NewSession
46
+ description "Creates a new ActionDispatch::Integration::Session and memoizes it. Use `app(true)` to create a new instance."
47
+
48
+ def execute(create = false)
49
+ @app_integration_instance = nil if create
50
+ @app_integration_instance ||= super
51
+ end
52
+ end
53
+
54
+ class Reloader < IRB::Command::Base
55
+ include ConsoleMethods
56
+
57
+ category "Rails console"
58
+ description "Reloads the Rails application."
59
+
60
+ def execute(*)
61
+ puts "Reloading..."
62
+ Rails.application.reloader.reload!
63
+ end
64
+ end
65
+
66
+ IRB::HelperMethod.register(:helper, ControllerHelper)
67
+ IRB::HelperMethod.register(:controller, ControllerInstance)
68
+ IRB::HelperMethod.register(:new_session, NewSession)
69
+ IRB::HelperMethod.register(:app, AppInstance)
70
+ IRB::Command.register(:reload!, Reloader)
71
+
72
+ class IRBConsole
73
+ def initialize(app)
74
+ @app = app
75
+
76
+ require "irb"
77
+ require "irb/completion"
78
+ end
79
+
80
+ def name
81
+ "IRB"
82
+ end
83
+
84
+ def start
85
+ IRB.setup(nil)
86
+
87
+ if !Rails.env.local? && !ENV.key?("IRB_USE_AUTOCOMPLETE")
88
+ IRB.conf[:USE_AUTOCOMPLETE] = false
89
+ end
90
+
91
+ env = colorized_env
92
+ app_name = @app.class.module_parent_name.underscore.dasherize
93
+ prompt_prefix = "%N(#{env})"
94
+ IRB.conf[:IRB_NAME] = app_name
95
+
96
+ IRB.conf[:PROMPT][:RAILS_PROMPT] = {
97
+ PROMPT_I: "#{prompt_prefix}> ",
98
+ PROMPT_S: "#{prompt_prefix}%l ",
99
+ PROMPT_C: "#{prompt_prefix}* ",
100
+ RETURN: "=> %s\n"
101
+ }
102
+
103
+ if current_filter = IRB.conf[:BACKTRACE_FILTER]
104
+ IRB.conf[:BACKTRACE_FILTER] = -> (backtrace) do
105
+ backtrace = current_filter.call(backtrace)
106
+ Rails.backtrace_cleaner.filter(backtrace)
107
+ end
108
+ else
109
+ IRB.conf[:BACKTRACE_FILTER] = -> (backtrace) do
110
+ Rails.backtrace_cleaner.filter(backtrace)
111
+ end
112
+ end
113
+
114
+ # Because some users/libs use Rails::ConsoleMethods to extend Rails console,
115
+ # we still include it for backward compatibility.
116
+ IRB::ExtendCommandBundle.include ConsoleMethods
117
+
118
+ # Respect user's choice of prompt mode.
119
+ IRB.conf[:PROMPT_MODE] = :RAILS_PROMPT if IRB.conf[:PROMPT_MODE] == :DEFAULT
120
+ IRB::Irb.new.run(IRB.conf)
121
+ end
122
+
123
+ def colorized_env
124
+ case Rails.env
125
+ when "development"
126
+ IRB::Color.colorize("dev", [:BLUE])
127
+ when "test"
128
+ IRB::Color.colorize("test", [:BLUE])
129
+ when "production"
130
+ IRB::Color.colorize("prod", [:RED])
131
+ else
132
+ Rails.env
133
+ end
134
+ end
135
+ end
136
+ end
137
+ end
@@ -20,8 +20,8 @@ module Rails
20
20
  load_generators
21
21
 
22
22
  if environment_specified?
23
- @content_path = "config/credentials/#{environment}.yml.enc" unless config.key?(:content_path)
24
- @key_path = "config/credentials/#{environment}.key" unless config.key?(:key_path)
23
+ @content_path = "config/credentials/#{environment}.yml.enc" unless config.overridden?(:content_path)
24
+ @key_path = "config/credentials/#{environment}.key" unless config.overridden?(:key_path)
25
25
  end
26
26
 
27
27
  ensure_encryption_key_has_been_added
@@ -16,28 +16,29 @@ module Rails
16
16
 
17
17
  def start
18
18
  adapter_class.dbconsole(db_config, @options)
19
- rescue NotImplementedError
20
- abort "Unknown command-line client for #{db_config.database}."
19
+ rescue NotImplementedError, ActiveRecord::AdapterNotFound, LoadError => error
20
+ abort error.message
21
21
  end
22
22
 
23
23
  def db_config
24
- return @db_config if defined?(@db_config)
25
-
26
- # If the user provided a database, use that. Otherwise find
27
- # the first config in the database.yml
28
- if database
29
- @db_config = configurations.configs_for(env_name: environment, name: database, include_hidden: true)
30
- else
31
- @db_config = configurations.find_db_config(environment)
32
- end
24
+ @db_config ||= begin
25
+ # If the user provided a database, use that. Otherwise find
26
+ # the first config in the database.yml
27
+ config = if database
28
+ @db_config = configurations.configs_for(env_name: environment, name: database, include_hidden: true)
29
+ else
30
+ @db_config = configurations.find_db_config(environment)
31
+ end
33
32
 
34
- unless @db_config
35
- missing_db = database ? "'#{database}' database is not" : "No databases are"
36
- raise ActiveRecord::AdapterNotSpecified,
37
- "#{missing_db} configured for '#{environment}'. Available configuration: #{configurations.inspect}"
38
- end
33
+ unless config
34
+ missing_db = database ? "'#{database}' database is not" : "No databases are"
35
+ raise ActiveRecord::AdapterNotSpecified,
36
+ "#{missing_db} configured for '#{environment}'. Available configuration: #{configurations.inspect}"
37
+ end
39
38
 
40
- @db_config
39
+ config.validate!
40
+ config
41
+ end
41
42
  end
42
43
 
43
44
  def database
@@ -50,11 +51,9 @@ module Rails
50
51
 
51
52
  private
52
53
  def adapter_class
53
- if ActiveRecord::Base.respond_to?(db_config.adapter_class_method)
54
- ActiveRecord::Base.public_send(db_config.adapter_class_method)
55
- else
56
- ActiveRecord::ConnectionAdapters::AbstractAdapter
57
- end
54
+ ActiveRecord::ConnectionAdapters.resolve(db_config.adapter)
55
+ rescue LoadError
56
+ ActiveRecord::ConnectionAdapters::AbstractAdapter
58
57
  end
59
58
 
60
59
  def configurations # :doc:
@@ -62,14 +61,6 @@ module Rails
62
61
  ActiveRecord::Base.configurations = Rails.application.config.database_configuration
63
62
  ActiveRecord::Base.configurations
64
63
  end
65
-
66
- def find_cmd_and_exec(commands, *args) # :doc:
67
- Rails.deprecator.warn(<<~MSG.squish)
68
- Rails::DBConsole#find_cmd_and_exec is deprecated and will be removed in Rails 7.2.
69
- Please use find_cmd_and_exec on the connection adapter class instead.
70
- MSG
71
- ActiveRecord::Base.connection.find_cmd_and_exec(commands, *args)
72
- end
73
64
  end
74
65
 
75
66
  module Command
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "rails/generators"
4
+ require "rails/generators/rails/devcontainer/devcontainer_generator"
5
+
6
+ module Rails
7
+ module Command
8
+ class DevcontainerCommand < Base # :nodoc:
9
+ desc "devcontainer", "Generate a Dev Container setup based on current application configuration"
10
+ def perform(*)
11
+ boot_application!
12
+
13
+ say "Generating Dev Container with the following options:"
14
+ devcontainer_options.each do |option, value|
15
+ say "#{option}: #{value}"
16
+ end
17
+
18
+ Rails::Generators::DevcontainerGenerator.new([], devcontainer_options).invoke_all
19
+ end
20
+
21
+ private
22
+ def devcontainer_options
23
+ @devcontainer_options ||= {
24
+ app_name: Rails.application.railtie_name.chomp("_application"),
25
+ database: !!defined?(ActiveRecord) && database,
26
+ active_storage: !!defined?(ActiveStorage),
27
+ redis: !!(defined?(ActionCable) || defined?(ActiveJob)),
28
+ system_test: File.exist?("test/application_system_test_case.rb"),
29
+ node: File.exist?(".node-version"),
30
+ }
31
+ end
32
+
33
+ def database
34
+ adapter = ActiveRecord::Base.connection_db_config.adapter
35
+ adapter == "mysql2" ? "mysql" : adapter
36
+ end
37
+ end
38
+ end
39
+ end
@@ -18,7 +18,7 @@ module Rails
18
18
 
19
19
  def perform(task, args, config)
20
20
  with_rake(task, *args) do |rake|
21
- if unrecognized_task = rake.top_level_tasks.find { |task| !rake.lookup(task[/[^\[]+/]) }
21
+ if unrecognized_task = (rake.top_level_tasks - ["default"]).find { |task| !rake.lookup(task[/[^\[]+/]) }
22
22
  @rake_tasks = rake.tasks
23
23
  raise UnrecognizedCommandError.new(unrecognized_task)
24
24
  end
@@ -7,6 +7,8 @@ module Rails
7
7
  class RunnerCommand < Base # :nodoc:
8
8
  include EnvironmentArgument
9
9
 
10
+ class_option :skip_executor, type: :boolean, aliases: "-w", desc: "Don't wrap with Rails Executor", default: false
11
+
10
12
  no_commands do
11
13
  def help(command_name = nil, *)
12
14
  super
@@ -30,19 +32,20 @@ module Rails
30
32
 
31
33
  ARGV.replace(command_argv)
32
34
 
35
+ wrap_with_executor = !options[:skip_executor]
33
36
  if code_or_file == "-"
34
- Rails.application.executor.wrap(source: "application.runner.railties") do
37
+ conditional_executor(wrap_with_executor, source: "application.runner.railties") do
35
38
  eval($stdin.read, TOPLEVEL_BINDING, "stdin")
36
39
  end
37
40
  elsif File.exist?(code_or_file)
38
41
  expanded_file_path = File.expand_path code_or_file
39
42
  $0 = expanded_file_path
40
- Rails.application.executor.wrap(source: "application.runner.railties") do
43
+ conditional_executor(wrap_with_executor, source: "application.runner.railties") do
41
44
  Kernel.load expanded_file_path
42
45
  end
43
46
  else
44
47
  begin
45
- Rails.application.executor.wrap(source: "application.runner.railties") do
48
+ conditional_executor(wrap_with_executor, source: "application.runner.railties") do
46
49
  eval(code_or_file, TOPLEVEL_BINDING, __FILE__, __LINE__)
47
50
  end
48
51
  rescue SyntaxError, NameError => e
@@ -62,6 +65,14 @@ module Rails
62
65
  end
63
66
 
64
67
  private
68
+ def conditional_executor(enabled, **args, &block)
69
+ if enabled
70
+ Rails.application.executor.wrap(**args, &block)
71
+ else
72
+ yield
73
+ end
74
+ end
75
+
65
76
  def looks_like_a_file_path?(code_or_file)
66
77
  code_or_file.ends_with?(".rb")
67
78
  end
@@ -114,7 +114,7 @@ module Rails
114
114
  class_option :using, aliases: "-u", type: :string,
115
115
  desc: "Specify the Rack server used to run the application (thin/puma/webrick).", banner: :name
116
116
  class_option :pid, aliases: "-P", type: :string,
117
- desc: "Specify the PID file - defaults to #{DEFAULT_PIDFILE}."
117
+ desc: "Specify the PID file. Defaults to #{DEFAULT_PIDFILE} in development."
118
118
  class_option :dev_caching, aliases: "-C", type: :boolean, default: nil,
119
119
  desc: "Specify whether to perform caching in development."
120
120
  class_option :restart, type: :boolean, default: nil, hide: true
@@ -243,11 +243,13 @@ module Rails
243
243
  end
244
244
 
245
245
  def pid
246
- File.expand_path(options[:pid] || ENV.fetch("PIDFILE", DEFAULT_PIDFILE))
246
+ default_pidfile = environment == "development" ? DEFAULT_PIDFILE : nil
247
+ pid = options[:pid] || ENV["PIDFILE"] || default_pidfile
248
+ File.expand_path(pid) if pid
247
249
  end
248
250
 
249
251
  def prepare_restart
250
- FileUtils.rm_f(pid) if options[:restart]
252
+ FileUtils.rm_f(pid) if pid && options[:restart]
251
253
  end
252
254
 
253
255
  def rack_server_suggestion(server)
@@ -31,6 +31,8 @@ module Rails
31
31
  Rails::TestUnit::Runner.parse_options(args)
32
32
  run_prepare_task if self.args.none?(EXACT_TEST_ARGUMENT_PATTERN)
33
33
  Rails::TestUnit::Runner.run(args)
34
+ rescue Rails::TestUnit::InvalidTestError => error
35
+ raise ArgumentError, error.message
34
36
  end
35
37
 
36
38
  # Define Thor tasks to avoid going through Rake and booting twice when using bin/rails test:*
@@ -131,8 +131,17 @@ module Rails
131
131
  @after_generate_callbacks << block
132
132
  end
133
133
 
134
+ def apply_rubocop_autocorrect_after_generate!
135
+ after_generate do |files|
136
+ parsable_files = files.filter { |file| File.exist?(file) && file.end_with?(".rb") }
137
+ unless parsable_files.empty?
138
+ system(RbConfig.ruby, "bin/rubocop", "-A", "--fail-level=E", "--format=quiet", *parsable_files, exception: true)
139
+ end
140
+ end
141
+ end
142
+
134
143
  def method_missing(method, *args)
135
- method = method.to_s.delete_suffix("=").to_sym
144
+ method = method.name.delete_suffix("=").to_sym
136
145
 
137
146
  if args.empty?
138
147
  if method == :rails
@@ -1,35 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "active_support/all"
4
- require "action_controller"
3
+ Rails.deprecator.warn(<<~MSG, caller_locations(0..1))
4
+ `rails/console/app` has been deprecated and will be removed in Rails 8.0.
5
+ Please require `rails/console/methods` instead.
6
+ MSG
5
7
 
6
- module Rails
7
- module ConsoleMethods
8
- # reference the global "app" instance, created on demand. To recreate the
9
- # instance, pass a non-false value as the parameter.
10
- def app(create = false)
11
- @app_integration_instance = nil if create
12
- @app_integration_instance ||= new_session
13
- end
14
-
15
- # create a new session. If a block is given, the new session will be yielded
16
- # to the block before being returned.
17
- def new_session
18
- app = Rails.application
19
- session = ActionDispatch::Integration::Session.new(app)
20
-
21
- # This makes app.url_for and app.foo_path available in the console
22
- session.extend(app.routes.url_helpers)
23
- session.extend(app.routes.mounted_helpers)
24
-
25
- session
26
- end
27
-
28
- # reloads the environment
29
- def reload!(print = true)
30
- puts "Reloading..." if print
31
- Rails.application.reloader.reload!
32
- true
33
- end
34
- end
35
- end
8
+ require "rails/console/methods"
@@ -1,19 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module Rails
4
- module ConsoleMethods
5
- # Gets the helper methods available to the controller.
6
- #
7
- # This method assumes an +ApplicationController+ exists, and that it extends ActionController::Base.
8
- def helper
9
- ApplicationController.helpers
10
- end
3
+ Rails.deprecator.warn(<<~MSG, caller_locations(0..1))
4
+ `rails/console/helpers` has been deprecated and will be removed in Rails 8.0.
5
+ Please require `rails/console/methods` instead.
6
+ MSG
11
7
 
12
- # Gets a new instance of a controller object.
13
- #
14
- # This method assumes an +ApplicationController+ exists, and that it extends ActionController::Base.
15
- def controller
16
- @controller ||= ApplicationController.new
17
- end
18
- end
19
- end
8
+ require "rails/console/methods"
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Rails
4
+ module ConsoleMethods
5
+ def self.include(_mod, ...)
6
+ raise_deprecation_warning
7
+ super
8
+ end
9
+
10
+ def self.method_added(_method_name)
11
+ raise_deprecation_warning
12
+ super
13
+ end
14
+
15
+ def self.raise_deprecation_warning
16
+ Rails.deprecator.warn(<<~MSG, caller_locations(2..2))
17
+ Extending Rails console through `Rails::ConsoleMethods` is deprecated and will be removed in Rails 8.0.
18
+ Please directly use IRB's extension API to add new commands or helpers to the console.
19
+ For more details, please visit: https://github.com/ruby/irb/blob/master/EXTEND_IRB.md
20
+ MSG
21
+ end
22
+ end
23
+ end
data/lib/rails/engine.rb CHANGED
@@ -451,8 +451,7 @@ module Rails
451
451
  # Load console and invoke the registered hooks.
452
452
  # Check Rails::Railtie.console for more info.
453
453
  def load_console(app = self)
454
- require "rails/console/app"
455
- require "rails/console/helpers"
454
+ require "rails/console/methods"
456
455
  run_console_blocks(app)
457
456
  self
458
457
  end
@@ -627,7 +626,7 @@ module Rails
627
626
  next if is_a?(Rails::Application)
628
627
 
629
628
  fixtures = config.root.join("test", "fixtures")
630
- if fixtures_in_root_and_not_in_vendor?(fixtures)
629
+ if fixtures_in_root_and_not_in_vendor_or_dot_dir?(fixtures)
631
630
  ActiveSupport.on_load(:active_record_fixtures) { self.fixture_paths |= ["#{fixtures}/"] }
632
631
  end
633
632
  end
@@ -735,9 +734,10 @@ module Rails
735
734
  end
736
735
  end
737
736
 
738
- def fixtures_in_root_and_not_in_vendor?(fixtures)
737
+ def fixtures_in_root_and_not_in_vendor_or_dot_dir?(fixtures)
739
738
  fixtures.exist? && fixtures.to_s.start_with?(Rails.root.to_s) &&
740
- !fixtures.to_s.start_with?(Rails.root.join("vendor").to_s)
739
+ !fixtures.to_s.start_with?(Rails.root.join("vendor").to_s) &&
740
+ !fixtures.to_s.start_with?("#{Rails.root}/.".to_s)
741
741
  end
742
742
 
743
743
  def build_request(env)
@@ -8,9 +8,9 @@ module Rails
8
8
 
9
9
  module VERSION
10
10
  MAJOR = 7
11
- MINOR = 1
12
- TINY = 3
13
- PRE = "4"
11
+ MINOR = 2
12
+ TINY = 0
13
+ PRE = nil
14
14
 
15
15
  STRING = [MAJOR, MINOR, TINY, PRE].compact.join(".")
16
16
  end