Merge pull request #52040 from zzak/re-52026

Rails::ConsoleMethods deprecation warning should point to the source
This commit is contained in:
Rafael Mendonça França 2024-06-13 15:25:35 -04:00 committed by GitHub
commit 5cb2603d56
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 10 additions and 1 deletions

View File

@ -13,7 +13,7 @@ module Rails
end
def self.raise_deprecation_warning
Rails.deprecator.warn(<<~MSG, caller_locations(1..1))
Rails.deprecator.warn(<<~MSG, caller_locations(2..2))
Extending Rails console through `Rails::ConsoleMethods` is deprecated and will be removed in Rails 7.3.
Please directly use IRB's extension API to add new commands or helpers to the console.
For more details, please visit: https://github.com/ruby/irb/blob/master/EXTEND_IRB.md

View File

@ -215,7 +215,16 @@ class FullStackConsoleTest < ActiveSupport::TestCase
spawn_console("-e development", wait_for_prompt: false)
line_number = 0
app = File.readlines("#{app_path}/config/application.rb")
app.each_with_index do |line, index|
if line.include?("Rails::ConsoleMethods.include(MyConsole)")
line_number = index + 1
end
end
assert_output "Extending Rails console through `Rails::ConsoleMethods` is deprecated", @primary, 30
assert_output "(called from block in <class:Application> at #{app_path}/config/application.rb:#{line_number})", @primary, 30
write_prompt "foo", "=> \"this is foo\""
end