Skip to content

Commit 33a748a

Browse files
zzakmorgoth
andcommitted
Rails::ConsoleMethods deprecation warning should point to the source
Before: ``` (called from Rails::ConsoleMethods.include at /home/zzak/code/rails/railties/lib/rails/console/methods.rb:6) ``` After: ``` (called from block in <class:Engine> at /home/zzak/.rbenv/versions/3.4.0/lib/ruby/gems/3.4.0+0/bundler/gems/mission_control-jobs-7295d75ed735/lib/mission_control/jobs/engine.rb:73) ``` Co-authored-by: Wojciech Wnętrzak <[email protected]>
1 parent 63db7d5 commit 33a748a

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

railties/lib/rails/console/methods.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def self.method_added(_method_name)
1313
end
1414

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

railties/test/application/console_test.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,16 @@ def foo
215215

216216
spawn_console("-e development", wait_for_prompt: false)
217217

218+
line_number = 0
219+
app = File.readlines("#{app_path}/config/application.rb")
220+
app.each_with_index do |line, index|
221+
if line.include?("Rails::ConsoleMethods.include(MyConsole)")
222+
line_number = index + 1
223+
end
224+
end
225+
218226
assert_output "Extending Rails console through `Rails::ConsoleMethods` is deprecated", @primary, 30
227+
assert_output "(called from block in <class:Application> at #{app_path}/config/application.rb:#{line_number})", @primary, 30
219228
write_prompt "foo", "=> \"this is foo\""
220229
end
221230

0 commit comments

Comments
 (0)