Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

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

#3985

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!/

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

State: resolved
Milestone: 3.0.2
Assigned to: José Valim José Valim
Importance: none

Activity

  1. José Valim
    José Valim
    • State changed from new to resolved
    • Assigned user set to José Valim
    • Milestone cleared.

    I got this handled a couple days ago, thanks for the patch though!

    February 23rd, 2010 @ 09:37 PM

  2. Jeremy Kemper