diff --git a/railties/lib/rails/commands/console/console_command.rb b/railties/lib/rails/commands/console/console_command.rb index 7a9eaefea1f84..7fa33965372b9 100644 --- a/railties/lib/rails/commands/console/console_command.rb +++ b/railties/lib/rails/commands/console/console_command.rb @@ -38,6 +38,10 @@ def initialize(app, options = {}) if @console == IRB IRB::WorkSpace.prepend(BacktraceCleaner) + + if Rails.env == "production" + ENV["IRB_USE_AUTOCOMPLETE"] ||= "false" + end end end diff --git a/railties/test/commands/console_test.rb b/railties/test/commands/console_test.rb index ee4335e31df95..7d733ad84d1e1 100644 --- a/railties/test/commands/console_test.rb +++ b/railties/test/commands/console_test.rb @@ -58,6 +58,45 @@ def test_console_defaults_to_IRB assert_equal IRB, Rails::Console.new(app).console end + def test_console_disables_IRB_auto_completion_in_production + original_use_autocomplete = ENV["IRB_USE_AUTOCOMPLETE"] + ENV["IRB_USE_AUTOCOMPLETE"] = nil + + with_rack_env "production" do + app = build_app(nil) + assert_equal IRB, Rails::Console.new(app).console + assert_equal "false", ENV["IRB_USE_AUTOCOMPLETE"] + end + ensure + ENV["IRB_USE_AUTOCOMPLETE"] = original_use_autocomplete + end + + def test_console_accepts_override_on_IRB_auto_completion_flag + original_use_autocomplete = ENV["IRB_USE_AUTOCOMPLETE"] + ENV["IRB_USE_AUTOCOMPLETE"] = "true" + + with_rack_env "production" do + app = build_app(nil) + assert_equal IRB, Rails::Console.new(app).console + assert_equal "true", ENV["IRB_USE_AUTOCOMPLETE"] + end + ensure + ENV["IRB_USE_AUTOCOMPLETE"] = original_use_autocomplete + end + + def test_console_doesnt_disable_IRB_auto_completion_in_non_production + original_use_autocomplete = ENV["IRB_USE_AUTOCOMPLETE"] + ENV["IRB_USE_AUTOCOMPLETE"] = nil + + with_rails_env nil do + app = build_app(nil) + assert_equal IRB, Rails::Console.new(app).console + assert_nil ENV["IRB_USE_AUTOCOMPLETE"] + end + ensure + ENV["IRB_USE_AUTOCOMPLETE"] = original_use_autocomplete + end + def test_default_environment_with_no_rails_env with_rails_env nil do start