Skip to content

Commit

Permalink
Ensures the app generator generates the correct @app_name. [#5434 sta…
Browse files Browse the repository at this point in the history
…te:resolved]

Signed-off-by: José Valim <jose.valim@gmail.com>
  • Loading branch information
fredwu authored and josevalim committed Sep 24, 2010
1 parent 684bb86 commit b0f0591
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
11 changes: 7 additions & 4 deletions railties/lib/rails/generators/rails/app/app_generator.rb
Expand Up @@ -353,18 +353,21 @@ def file(*args, &block)
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

Expand Down
1 change: 1 addition & 0 deletions railties/test/generators/app_generator_test.rb
Expand Up @@ -129,6 +129,7 @@ def test_application_name_is_detected_if_it_exists_and_app_folder_renamed
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
Expand Down

0 comments on commit b0f0591

Please sign in to comment.