This project is archived and is in readonly mode.

#3985 ✓resolved
Brian D. Burns

rake rails:update / generator using 'Config::Application' for app_const_base

Reported by Brian D. Burns | February 17th, 2010 @ 09:50 PM | in 3.0.2

When running 'rake rails:update', the config files are using 'Config::Application' for 'app_const_base'.

It appears the problem is that Thor::Actions#inside is changing @destination_root
before AppGenerator#app_name is being set.

I'm not sure if this would be the proper solution...

diff --git a/railties/lib/generators/rails/app/app_generator.rb b/railties/lib/generators/rails/app/app_generator.rb
index ea1930a..82e852c 100644
--- a/railties/lib/generators/rails/app/app_generator.rb
+++ b/railties/lib/generators/rails/app/app_generator.rb
@@ -81,6 +81,10 @@ module Rails::Generators
     def create_config_files
       empty_directory "config"
 
+      # set @app_name here, since Thor::Actions#inside is changing @destination_root,
+      # causing @app_const_base to be incorrect when parsing config templates.
+      app_name
+
       inside "config" do
         template "routes.rb"
         template "application.rb"

Here's a failing test case:

diff --git a/railties/test/generators/app_generator_test.rb b/railties/test/generators/app_generator_test.rb
index 01d643c..3b23d81 100644
--- a/railties/test/generators/app_generator_test.rb
+++ b/railties/test/generators/app_generator_test.rb
@@ -71,6 +71,13 @@ class AppGeneratorTest < Rails::Generators::TestCase
     assert_file "things-43/config/application.rb", /^module Things43$/
   end
 
+  def test_create_config_files
+    gen = generator(default_arguments, {}, {:destination_root => File.join(destination_root, "my_app")})
+    capture(:stdout) { gen.invoke :create_config_files }
+    assert_file "my_app/config/environment.rb", /MyApp::Application\.initialize!/
+    assert_file "my_app/config/application.rb", /^module MyApp$/
+  end
+
   def test_application_names_are_not_singularized
     run_generator [File.join(destination_root, "hats")]
     assert_file "hats/config/environment.rb", /Hats::Application\.initialize!/

Comments and changes to this ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

People watching this ticket

Pages