Skip to content

Commit

Permalink
Avoid setting fixed app name in console prompt
Browse files Browse the repository at this point in the history
Instead, the app's name should be set via a separate IRB config, which
will allow it to be changed at runtime.

Co-authored-by: Mike Dalessio <mike.dalessio@gmail.com>
  • Loading branch information
st0012 and flavorjones committed May 6, 2024
1 parent 9ad3685 commit beba30b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
3 changes: 2 additions & 1 deletion railties/lib/rails/commands/console/irb_console.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ def start

env = colorized_env
app_name = @app.class.module_parent_name.underscore.dasherize
prompt_prefix = "#{app_name}(#{env})"
prompt_prefix = "%N(#{env})"
IRB.conf[:IRB_NAME] = app_name

IRB.conf[:PROMPT][:RAILS_PROMPT] = {
PROMPT_I: "#{prompt_prefix}> ",
Expand Down
16 changes: 16 additions & 0 deletions railties/test/application/console_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,22 @@ def test_sandbox_by_default_with_development_environment
@primary.puts "quit"
end

def test_prompt_is_properly_set
options = "-e test"
spawn_console(options)

write_prompt "a = 1", "a = 1", prompt: "app-template(test)>"
end

def test_prompt_allows_changing_irb_name
options = "-e test"
spawn_console(options)

write_prompt "conf.irb_name = 'foo'"
write_prompt "a = 1", "a = 1", prompt: "foo(test)>"
@primary.puts "quit"
end

def test_environment_option_and_irb_option
options = "-e test -- --verbose"
spawn_console(options)
Expand Down

0 comments on commit beba30b

Please sign in to comment.