Skip to content

Commit beba30b

Browse files
st0012flavorjones
andcommitted
Avoid setting fixed app name in console prompt
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 <[email protected]>
1 parent 9ad3685 commit beba30b

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

railties/lib/rails/commands/console/irb_console.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,8 @@ def start
8181

8282
env = colorized_env
8383
app_name = @app.class.module_parent_name.underscore.dasherize
84-
prompt_prefix = "#{app_name}(#{env})"
84+
prompt_prefix = "%N(#{env})"
85+
IRB.conf[:IRB_NAME] = app_name
8586

8687
IRB.conf[:PROMPT][:RAILS_PROMPT] = {
8788
PROMPT_I: "#{prompt_prefix}> ",

railties/test/application/console_test.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,22 @@ def test_sandbox_by_default_with_development_environment
110110
@primary.puts "quit"
111111
end
112112

113+
def test_prompt_is_properly_set
114+
options = "-e test"
115+
spawn_console(options)
116+
117+
write_prompt "a = 1", "a = 1", prompt: "app-template(test)>"
118+
end
119+
120+
def test_prompt_allows_changing_irb_name
121+
options = "-e test"
122+
spawn_console(options)
123+
124+
write_prompt "conf.irb_name = 'foo'"
125+
write_prompt "a = 1", "a = 1", prompt: "foo(test)>"
126+
@primary.puts "quit"
127+
end
128+
113129
def test_environment_option_and_irb_option
114130
options = "-e test -- --verbose"
115131
spawn_console(options)

0 commit comments

Comments
 (0)