diff options
-rw-r--r-- | railties/lib/rails/generators/rails/app/app_generator.rb | 11 | ||||
-rw-r--r-- | railties/test/generators/app_generator_test.rb | 1 |
2 files changed, 8 insertions, 4 deletions
diff --git a/railties/lib/rails/generators/rails/app/app_generator.rb b/railties/lib/rails/generators/rails/app/app_generator.rb index cdff1743ff..2715483914 100644 --- a/railties/lib/rails/generators/rails/app/app_generator.rb +++ b/railties/lib/rails/generators/rails/app/app_generator.rb @@ -353,18 +353,21 @@ module Rails end def app_name - @app_name ||= File.basename(destination_root) + @app_name ||= defined_app_const_base? ? defined_app_name : File.basename(destination_root) + end + + def defined_app_name + defined_app_const_base.underscore end - - alias_method :defined_app_name, :app_name def defined_app_const_base Rails.respond_to?(:application) && defined?(Rails::Application) && Rails.application.is_a?(Rails::Application) && Rails.application.class.name.sub(/::Application$/, "") end + alias :defined_app_const_base? :defined_app_const_base + def app_const_base - defined_app_name # ensures the correct app_name if it's already defined @app_const_base ||= defined_app_const_base || app_name.gsub(/\W/, '_').squeeze('_').camelize end diff --git a/railties/test/generators/app_generator_test.rb b/railties/test/generators/app_generator_test.rb index 9ce2308a02..83a6f8bc20 100644 --- a/railties/test/generators/app_generator_test.rb +++ b/railties/test/generators/app_generator_test.rb @@ -129,6 +129,7 @@ class AppGeneratorTest < Rails::Generators::TestCase generator.send(:app_const) silence(:stdout){ generator.send(:create_config_files) } assert_file "myapp_moved/config/environment.rb", /Myapp::Application\.initialize!/ + assert_file "myapp_moved/config/initializers/session_store.rb", /_myapp_session/ end def test_rails_update_generates_correct_session_key |