Skip to content

Commit

Permalink
Merge pull request #47468 from skipkayhil/only-require-irb-when-uncon…
Browse files Browse the repository at this point in the history
…figured

Only require irb if console is unconfigured
  • Loading branch information
eileencodes committed Feb 23, 2023
2 parents d2af670 + dccb336 commit 832dc52
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
10 changes: 5 additions & 5 deletions railties/lib/rails/commands/console/console_command.rb
@@ -1,8 +1,5 @@
# frozen_string_literal: true

require "irb"
require "irb/completion"

require "rails/command/environment_argument"

module Rails
Expand Down Expand Up @@ -34,14 +31,17 @@ def initialize(app, options = {})

app.load_console

@console = app.config.console || IRB
@console = app.config.console || begin
require "irb"
require "irb/completion"

if @console == IRB
IRB::WorkSpace.prepend(BacktraceCleaner)

if Rails.env.production?
ENV["IRB_USE_AUTOCOMPLETE"] ||= "false"
end

IRB
end
end

Expand Down
8 changes: 4 additions & 4 deletions railties/test/commands/console_test.rb
Expand Up @@ -55,7 +55,7 @@ def test_console_with_environment

def test_console_defaults_to_IRB
app = build_app(nil)
assert_equal IRB, Rails::Console.new(app).console
assert_equal "IRB", Rails::Console.new(app).console.name
end

def test_console_disables_IRB_auto_completion_in_production
Expand All @@ -64,7 +64,7 @@ def test_console_disables_IRB_auto_completion_in_production

with_rack_env "production" do
app = build_app(nil)
assert_equal IRB, Rails::Console.new(app).console
assert_equal "IRB", Rails::Console.new(app).console.name
assert_equal "false", ENV["IRB_USE_AUTOCOMPLETE"]
end
ensure
Expand All @@ -77,7 +77,7 @@ def test_console_accepts_override_on_IRB_auto_completion_flag

with_rack_env "production" do
app = build_app(nil)
assert_equal IRB, Rails::Console.new(app).console
assert_equal "IRB", Rails::Console.new(app).console.name
assert_equal "true", ENV["IRB_USE_AUTOCOMPLETE"]
end
ensure
Expand All @@ -90,7 +90,7 @@ def test_console_doesnt_disable_IRB_auto_completion_in_non_production

with_rails_env nil do
app = build_app(nil)
assert_equal IRB, Rails::Console.new(app).console
assert_equal "IRB", Rails::Console.new(app).console.name
assert_nil ENV["IRB_USE_AUTOCOMPLETE"]
end
ensure
Expand Down

0 comments on commit 832dc52

Please sign in to comment.