From d0aea3bd84191e7491afdfc29505bd7f0a5b8c24 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Josef=20=C5=A0im=C3=A1nek?= Date: Thu, 30 Mar 2023 15:47:42 +0200 Subject: [PATCH] Enable IRB autocomplete only in Rails.env.local? environment. --- railties/lib/rails/commands/console/console_command.rb | 2 +- railties/test/commands/console_test.rb | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/railties/lib/rails/commands/console/console_command.rb b/railties/lib/rails/commands/console/console_command.rb index e95b2708605..13d7232e482 100644 --- a/railties/lib/rails/commands/console/console_command.rb +++ b/railties/lib/rails/commands/console/console_command.rb @@ -37,7 +37,7 @@ module Rails IRB::WorkSpace.prepend(BacktraceCleaner) - if Rails.env.production? + if !Rails.env.local? ENV["IRB_USE_AUTOCOMPLETE"] ||= "false" end diff --git a/railties/test/commands/console_test.rb b/railties/test/commands/console_test.rb index bd2c6c461b1..9622cd60c84 100644 --- a/railties/test/commands/console_test.rb +++ b/railties/test/commands/console_test.rb @@ -58,12 +58,13 @@ class Rails::ConsoleTest < ActiveSupport::TestCase assert_equal "IRB", Rails::Console.new(app).console.name end - def test_console_disables_IRB_auto_completion_in_production + def test_console_disables_IRB_auto_completion_in_non_local original_use_autocomplete = ENV["IRB_USE_AUTOCOMPLETE"] ENV["IRB_USE_AUTOCOMPLETE"] = nil with_rack_env "production" do app = build_app(nil) + assert_not_predicate Rails.env, :local? assert_equal "IRB", Rails::Console.new(app).console.name assert_equal "false", ENV["IRB_USE_AUTOCOMPLETE"] end @@ -84,12 +85,13 @@ class Rails::ConsoleTest < ActiveSupport::TestCase ENV["IRB_USE_AUTOCOMPLETE"] = original_use_autocomplete end - def test_console_doesnt_disable_IRB_auto_completion_in_non_production + def test_console_doesnt_disable_IRB_auto_completion_in_local original_use_autocomplete = ENV["IRB_USE_AUTOCOMPLETE"] ENV["IRB_USE_AUTOCOMPLETE"] = nil with_rails_env nil do app = build_app(nil) + assert_predicate Rails.env, :local? assert_equal "IRB", Rails::Console.new(app).console.name assert_nil ENV["IRB_USE_AUTOCOMPLETE"] end