From 688c0f8ab276ca1e4a4a41103a15e702f1b19bbb Mon Sep 17 00:00:00 2001 From: Krekoten' Marjan Date: Tue, 24 Aug 2010 18:51:21 +0300 Subject: [PATCH] Fix appication name detection when running rake rails:update --- .../rails/generators/rails/app/app_generator.rb | 6 +++++- railties/test/generators/app_generator_test.rb | 19 +++++++++++++++++++ 2 files changed, 24 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 6eba0f7..be6c88b 100644 --- a/railties/lib/rails/generators/rails/app/app_generator.rb +++ b/railties/lib/rails/generators/rails/app/app_generator.rb @@ -352,8 +352,12 @@ module Rails create_file(*args, &block) end + def defined_app_name + defined_app_const_base ? defined_app_const_base.underscore : false + end + def app_name - @app_name ||= File.basename(destination_root) + @app_name ||= defined_app_name || File.basename(destination_root) end def defined_app_const_base diff --git a/railties/test/generators/app_generator_test.rb b/railties/test/generators/app_generator_test.rb index dcd7629..6cd1786 100644 --- a/railties/test/generators/app_generator_test.rb +++ b/railties/test/generators/app_generator_test.rb @@ -134,6 +134,25 @@ class AppGeneratorTest < Rails::Generators::TestCase run_generator [File.join(destination_root, "hats")] assert_file "hats/config/environment.rb", /Hats::Application\.initialize!/ end + + def test_rails_update_generates_correct_session_key + app_path = File.join(destination_root, 'my_app') + run_generator [app_path] + + Rails.application.config.root = app_path + Rails.application.class.stubs(:name).returns("MyApp") + Rails.application.stubs(:is_a?).returns(Rails::Application) + + 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_path, :shell => shell + generator.send(:app_const) + silence(:stdout){ generator.send(:create_config_files) } + assert_file "my_app/config/initializers/session_store.rb", /_my_app_session/ + end def test_config_database_is_added_by_default run_generator -- 1.7.2