Skip to content

Commit

Permalink
Remove obsolete new_session helper
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
st0012 committed May 15, 2024
1 parent dfa4efe commit 9bf8208
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 24 deletions.
32 changes: 14 additions & 18 deletions railties/lib/rails/commands/console/irb_console.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,28 +27,25 @@ def execute
end
end

class NewSession < RailsHelperBase
description "Creates a new ActionDispatch::Integration::Session. If a block is given, the new session will be yielded to it."

def execute(*)
app = Rails.application
session = ActionDispatch::Integration::Session.new(app)

# This makes app.url_for and app.foo_path available in the console
session.extend(app.routes.url_helpers)
session.extend(app.routes.mounted_helpers)

session
end
end

class AppInstance < NewSession
class AppInstance < RailsHelperBase
description "Creates a new ActionDispatch::Integration::Session and memoizes it. Use `app(true)` to create a new instance."

def execute(create = false)
@app_integration_instance = nil if create
@app_integration_instance ||= super
@app_integration_instance ||= new_session
end

private
def new_session
app = Rails.application
session = ActionDispatch::Integration::Session.new(app)

# This makes app.url_for and app.foo_path available in the console
session.extend(app.routes.url_helpers)
session.extend(app.routes.mounted_helpers)

session
end
end

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

IRB::HelperMethod.register(:helper, ControllerHelper)
IRB::HelperMethod.register(:controller, ControllerInstance)
IRB::HelperMethod.register(:new_session, NewSession)
IRB::HelperMethod.register(:app, AppInstance)
IRB::Command.register(:reload!, Reloader)

Expand Down
6 changes: 0 additions & 6 deletions railties/test/application/console_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -168,12 +168,6 @@ def test_controller_helper_method
write_prompt "controller.class.name", "ApplicationController"
end

def test_new_session_helper_method
spawn_console("-e development")

write_prompt "new_session.class.name", "ActionDispatch::Integration::Session"
end

def test_app_helper_method
app_file "config/routes.rb", <<-RUBY
Rails.application.routes.draw do
Expand Down

0 comments on commit 9bf8208

Please sign in to comment.