Skip to content

Commit fcf641a

Browse files
committed
Remove deprecated support to extend Rails console through Rails::ConsoleMethods
1 parent a27cb03 commit fcf641a

File tree

7 files changed

+11
-75
lines changed

7 files changed

+11
-75
lines changed

guides/source/8_0_release_notes.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ Please refer to the [Changelog][railties] for detailed changes.
3434

3535
* Remove deprecated file `rails/console/helpers`.
3636

37+
* Remove deprecated support to extend Rails console through `Rails::ConsoleMethods`.
38+
3739
### Deprecations
3840

3941
### Notable changes

railties/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
* Remove deprecated support to extend Rails console through `Rails::ConsoleMethods`.
2+
3+
*Rafael Mendonça França*
4+
15
* Remove deprecated file `rails/console/helpers`.
26

37
*Rafael Mendonça França*

railties/lib/rails/commands/console/irb_console.rb

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
module Rails
77
class Console
88
class RailsHelperBase < IRB::HelperMethod::Base
9-
include ConsoleMethods
109
end
1110

1211
class ControllerHelper < RailsHelperBase
@@ -61,8 +60,6 @@ def execute
6160
end
6261

6362
class ReloadCommand < IRB::Command::Base
64-
include ConsoleMethods
65-
6663
category "Rails console"
6764
description "Reloads the Rails application."
6865

@@ -120,10 +117,6 @@ def start
120117
end
121118
end
122119

123-
# Because some users/libs use Rails::ConsoleMethods to extend Rails console,
124-
# we still include it for backward compatibility.
125-
IRB::ExtendCommandBundle.include ConsoleMethods
126-
127120
# Respect user's choice of prompt mode.
128121
IRB.conf[:PROMPT_MODE] = :RAILS_PROMPT if IRB.conf[:PROMPT_MODE] == :DEFAULT
129122
IRB::Irb.new.run(IRB.conf)

railties/lib/rails/console/methods.rb

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,7 @@
11
# frozen_string_literal: true
22

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
3+
Rails.deprecator.warn(<<~MSG, caller_locations(0..1))
4+
`rails/console/methods` has been deprecated and will be removed in Rails 8.1.
5+
Please directly use IRB's extension API to add new commands or helpers to the console.
6+
For more details, please visit: https://github.com/ruby/irb/blob/master/EXTEND_IRB.md
7+
MSG

railties/lib/rails/engine.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,6 @@ def initialize
452452
# Load console and invoke the registered hooks.
453453
# Check Rails::Railtie.console for more info.
454454
def load_console(app = self)
455-
require "rails/console/methods"
456455
run_console_blocks(app)
457456
self
458457
end

railties/test/application/console_test.rb

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -200,51 +200,6 @@ def test_reload_command_fires_preparation_and_cleanup_callbacks
200200
write_prompt "c", "=> 3"
201201
end
202202

203-
def test_rails_console_methods_patch_backward_compatibility_with_module_inclusion
204-
add_to_config <<-RUBY
205-
module MyConsole
206-
def foo
207-
"this is foo"
208-
end
209-
end
210-
211-
console do
212-
::Rails::ConsoleMethods.include(MyConsole)
213-
end
214-
RUBY
215-
216-
spawn_console("-e development", wait_for_prompt: false)
217-
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-
226-
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
228-
write_prompt "foo", "=> \"this is foo\""
229-
end
230-
231-
def test_rails_console_methods_patch_backward_compatibility_with_module_reopening
232-
add_to_config <<-RUBY
233-
console do
234-
::Rails::ConsoleMethods.module_eval do
235-
def foo
236-
"this is foo"
237-
end
238-
end
239-
end
240-
RUBY
241-
242-
spawn_console("-e development", wait_for_prompt: false)
243-
244-
assert_output "Extending Rails console through `Rails::ConsoleMethods` is deprecated", @primary, 30
245-
write_prompt "foo", "=> \"this is foo\""
246-
end
247-
248203
def test_reload_command_reload_constants
249204
app_file "app/models/user.rb", <<-MODEL
250205
class User

railties/test/commands/console_test.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,6 @@ def config
167167
end
168168

169169
def load_console
170-
require "rails/console/methods"
171170
end
172171
end
173172
mocked_app.new(console)

0 commit comments

Comments
 (0)