Skip to content

Commit d3ff40e

Browse files
committed
Make app_name consistent between new and update
Previously, the app_name in the App Generator would behave differently when creating a new app and updating an existing app. When updating an app, app_name is always the Rails::Application class name underscored. When creating a new app, app_name will use whatever the user passes in with a few characters replaced. This isn't necessarily an issue, but it can lead to extra noise when running app:update. For example, an app generated with `rails new MyWebSite` will end up with a configuration line like: ``` config.active_job.queue_name_prefix = "MyWebSite_production" ``` and running app:update will change it to ``` config.active_job.queue_name_prefix = "my_web_site_production" ``` By normalizing app_name when creating an application, the amount of changes when updating is reduced.
1 parent 61fdd53 commit d3ff40e

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

railties/lib/rails/generators/app_name.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ module AppName # :nodoc:
77

88
private
99
def app_name
10-
@app_name ||= original_app_name.tr("\\", "").tr("-. ", "_")
10+
@app_name ||= original_app_name.parameterize(preserve_case: true).underscore
1111
end
1212

1313
def original_app_name

railties/test/generators/app_generator_test.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,12 @@ def test_application_names_are_not_singularized
470470
assert_file "hats/config/environment.rb", /Rails\.application\.initialize!/
471471
end
472472

473+
def test_application_name_is_normalized_in_config
474+
run_generator [File.join(destination_root, "MyWebSite"), "-d", "postgresql"]
475+
assert_file "MyWebSite/app/views/layouts/application.html.erb", /<title>MyWebSite<\/title>/
476+
assert_file "MyWebSite/config/database.yml", /my_web_site_production/
477+
end
478+
473479
def test_gemfile_has_no_whitespace_errors
474480
run_generator
475481
absolute = File.expand_path("Gemfile", destination_root)

0 commit comments

Comments
 (0)