diff options
3 files changed, 8 insertions, 3 deletions
diff --git a/railties/lib/rails/generators/rails/app/app_generator.rb b/railties/lib/rails/generators/rails/app/app_generator.rb index fc6a3cdee8..2f85a0504e 100644 --- a/railties/lib/rails/generators/rails/app/app_generator.rb +++ b/railties/lib/rails/generators/rails/app/app_generator.rb @@ -193,8 +193,12 @@ module Rails::Generators @app_name ||= File.basename(destination_root) end + def app_const_base + @app_const_base ||= app_name.gsub(/\W/, '_').squeeze('_').classify + end + def app_const - @app_const ||= "#{app_name.gsub(/\W/, '_').squeeze('_').classify}::Application" + @app_const ||= "#{app_const_base}::Application" end def valid_app_const? diff --git a/railties/lib/rails/generators/rails/app/templates/config/application.rb b/railties/lib/rails/generators/rails/app/templates/config/application.rb index dce5b55d86..334820826f 100644 --- a/railties/lib/rails/generators/rails/app/templates/config/application.rb +++ b/railties/lib/rails/generators/rails/app/templates/config/application.rb @@ -1,6 +1,6 @@ require File.expand_path('../boot', __FILE__) -module <%= app_name.classify %> +module <%= app_const_base %> class Application < Rails::Application # Settings in config/environments/* take precedence over those specified here. # Application configuration should go into files in config/initializers diff --git a/railties/test/generators/app_generator_test.rb b/railties/test/generators/app_generator_test.rb index 27537f39b2..85081609de 100644 --- a/railties/test/generators/app_generator_test.rb +++ b/railties/test/generators/app_generator_test.rb @@ -61,7 +61,8 @@ class AppGeneratorTest < GeneratorsTestCase def test_invalid_application_name_is_fixed silence(:stdout){ Rails::Generators::AppGenerator.start [File.join(destination_root, "things-43")] } - assert_file "things-43/config/environment.rb", /Things43::Application/ + assert_file "things-43/config/environment.rb", /Things43::Application\.initialize!/ + assert_file "things-43/config/application.rb", /^module Things43$/ end def test_config_database_is_added_by_default |