aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFred Wu <ifredwu@gmail.com>2010-07-28 22:55:57 +1000
committerJosé Valim <jose.valim@gmail.com>2010-08-02 16:30:20 +0200
commitcdad483dff4fef1b640dc3c750719c325b252f89 (patch)
tree8530a62df5cdbd352229e7c14cba3e00f2e59f32
parentaeaab06c79a9e3cfa9988270847fa8c6f863570a (diff)
downloadrails-cdad483dff4fef1b640dc3c750719c325b252f89.tar.gz
rails-cdad483dff4fef1b640dc3c750719c325b252f89.tar.bz2
rails-cdad483dff4fef1b640dc3c750719c325b252f89.zip
Improved how AppGenerator generates the application name. It now detects the current app name whenever possible. This means that renaming the residing directory will not effect the app name generated by AppGenerator.
[#5225 state:resolved] Signed-off-by: José Valim <jose.valim@gmail.com>
-rw-r--r--railties/lib/rails/generators/rails/app/app_generator.rb6
-rw-r--r--railties/test/generators/app_generator_test.rb24
2 files changed, 29 insertions, 1 deletions
diff --git a/railties/lib/rails/generators/rails/app/app_generator.rb b/railties/lib/rails/generators/rails/app/app_generator.rb
index 96c49a81bb..dd18588b39 100644
--- a/railties/lib/rails/generators/rails/app/app_generator.rb
+++ b/railties/lib/rails/generators/rails/app/app_generator.rb
@@ -356,8 +356,12 @@ module Rails
@app_name ||= File.basename(destination_root)
end
+ def defined_app_const_base
+ Rails.application.class.name.sub(/::Application$/, "") if Rails.application.instance_of?(Rails::Application)
+ end
+
def app_const_base
- @app_const_base ||= app_name.gsub(/\W/, '_').squeeze('_').camelize
+ @app_const_base ||= defined_app_const_base || app_name.gsub(/\W/, '_').squeeze('_').camelize
end
def app_const
diff --git a/railties/test/generators/app_generator_test.rb b/railties/test/generators/app_generator_test.rb
index 1e0b3bf4c7..21725a380c 100644
--- a/railties/test/generators/app_generator_test.rb
+++ b/railties/test/generators/app_generator_test.rb
@@ -106,6 +106,30 @@ class AppGeneratorTest < Rails::Generators::TestCase
assert_file "things-43/config/application.rb", /^module Things43$/
end
+ def test_application_name_is_detected_if_it_exists_and_app_folder_renamed
+ app_root = File.join(destination_root, "myapp")
+ app_moved_root = File.join(destination_root, "myapp_moved")
+
+ run_generator [app_root]
+
+ Rails.application.config.root = app_moved_root
+ Rails.application.class.stubs(:name).returns("Myapp")
+ Rails.application.stubs(:instance_of?).returns(Rails::Application)
+
+ FileUtils.mv(app_root, app_moved_root)
+
+ # forces the shell to automatically overwrite all files
+ Thor::Base.shell.send(:attr_accessor, :always_force)
+ shell = Thor::Base.shell.new
+ shell.send(:always_force=, true)
+
+ generator = Rails::Generators::AppGenerator.new ["rails"], { :with_dispatchers => true },
+ :destination_root => app_moved_root, :shell => shell
+ generator.send(:app_const)
+ silence(:stdout){ generator.send(:create_config_files) }
+ assert_file "myapp_moved/config/environment.rb", /Myapp::Application\.initialize!/
+ end
+
def test_application_names_are_not_singularized
run_generator [File.join(destination_root, "hats")]
assert_file "hats/config/environment.rb", /Hats::Application\.initialize!/