Skip to content

Commit bf366f6

Browse files
Merge pull request #51732 from Shopify/fix-rails-console-prompt
Avoid setting fixed app name in console prompt
1 parent 853205b commit bf366f6

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
@@ -90,7 +90,8 @@ def start
9090

9191
env = colorized_env
9292
app_name = @app.class.module_parent_name.underscore.dasherize
93-
prompt_prefix = "#{app_name}(#{env})"
93+
prompt_prefix = "%N(#{env})"
94+
IRB.conf[:IRB_NAME] = app_name
9495

9596
IRB.conf[:PROMPT][:RAILS_PROMPT] = {
9697
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)