Skip to content

Commit 9bf8208

Browse files
committed
Remove obsolete new_session helper
After #44748, the `new_session` helper no longer takes a block and is the same as calling `app(true)`. Therefore, I think there's no reason to expose it to Rails console users.
1 parent dfa4efe commit 9bf8208

File tree

2 files changed

+14
-24
lines changed

2 files changed

+14
-24
lines changed

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

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -27,28 +27,25 @@ def execute
2727
end
2828
end
2929

30-
class NewSession < RailsHelperBase
31-
description "Creates a new ActionDispatch::Integration::Session. If a block is given, the new session will be yielded to it."
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
30+
class AppInstance < RailsHelperBase
4631
description "Creates a new ActionDispatch::Integration::Session and memoizes it. Use `app(true)` to create a new instance."
4732

4833
def execute(create = false)
4934
@app_integration_instance = nil if create
50-
@app_integration_instance ||= super
35+
@app_integration_instance ||= new_session
5136
end
37+
38+
private
39+
def new_session
40+
app = Rails.application
41+
session = ActionDispatch::Integration::Session.new(app)
42+
43+
# This makes app.url_for and app.foo_path available in the console
44+
session.extend(app.routes.url_helpers)
45+
session.extend(app.routes.mounted_helpers)
46+
47+
session
48+
end
5249
end
5350

5451
class Reloader < IRB::Command::Base
@@ -65,7 +62,6 @@ def execute(*)
6562

6663
IRB::HelperMethod.register(:helper, ControllerHelper)
6764
IRB::HelperMethod.register(:controller, ControllerInstance)
68-
IRB::HelperMethod.register(:new_session, NewSession)
6965
IRB::HelperMethod.register(:app, AppInstance)
7066
IRB::Command.register(:reload!, Reloader)
7167

railties/test/application/console_test.rb

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -168,12 +168,6 @@ def test_controller_helper_method
168168
write_prompt "controller.class.name", "ApplicationController"
169169
end
170170

171-
def test_new_session_helper_method
172-
spawn_console("-e development")
173-
174-
write_prompt "new_session.class.name", "ActionDispatch::Integration::Session"
175-
end
176-
177171
def test_app_helper_method
178172
app_file "config/routes.rb", <<-RUBY
179173
Rails.application.routes.draw do

0 commit comments

Comments
 (0)