mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Fixed the session name generated by the app_generator. Also refactored the corresponding test suites to be cleaner. [#5434 state:resolved]
Signed-off-by: José Valim <jose.valim@gmail.com>
This commit is contained in:
parent
3e22e0b025
commit
83f4507cf1
2 changed files with 24 additions and 6 deletions
|
@ -356,12 +356,15 @@ module Rails
|
|||
@app_name ||= File.basename(destination_root)
|
||||
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
|
||||
|
||||
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
|
||||
|
||||
|
|
|
@ -45,6 +45,12 @@ class AppGeneratorTest < Rails::Generators::TestCase
|
|||
super
|
||||
Rails::Generators::AppGenerator.instance_variable_set('@desc', nil)
|
||||
@bundle_command = File.basename(Thor::Util.ruby_command).sub(/ruby/, 'bundle')
|
||||
|
||||
Kernel::silence_warnings do
|
||||
Thor::Base.shell.send(:attr_accessor, :always_force)
|
||||
@shell = Thor::Base.shell.new
|
||||
@shell.send(:always_force=, true)
|
||||
end
|
||||
end
|
||||
|
||||
def teardown
|
||||
|
@ -118,18 +124,27 @@ class AppGeneratorTest < Rails::Generators::TestCase
|
|||
|
||||
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
|
||||
: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_rails_update_generates_correct_session_key
|
||||
app_root = File.join(destination_root, 'myapp')
|
||||
run_generator [app_root]
|
||||
|
||||
Rails.application.config.root = app_root
|
||||
Rails.application.class.stubs(:name).returns("Myapp")
|
||||
Rails.application.stubs(:is_a?).returns(Rails::Application)
|
||||
|
||||
generator = Rails::Generators::AppGenerator.new ["rails"], { :with_dispatchers => true }, :destination_root => app_root, :shell => @shell
|
||||
generator.send(:app_const)
|
||||
silence(:stdout){ generator.send(:create_config_files) }
|
||||
assert_file "myapp/config/initializers/session_store.rb", /_myapp_session/
|
||||
end
|
||||
|
||||
def test_application_names_are_not_singularized
|
||||
run_generator [File.join(destination_root, "hats")]
|
||||
assert_file "hats/config/environment.rb", /Hats::Application\.initialize!/
|
||||
|
|
Loading…
Reference in a new issue