mirror of https://github.com/rails/rails
Make the application name snake cased when it contains spaces
The application name is used to fill the `database.yml` and `session_store.rb` files ; previously, if the provided name contained whitespaces, it led to unexpected names in these files. Since Shellwords.escape adds backslashes to escape spaces, the app_name should remove them and replace any space with an underscore (just like periods previously). Also improve the assert_file helper to work with paths containing spaces using String#shellescape.
This commit is contained in:
parent
99044beb81
commit
52b252614e
|
@ -1,3 +1,11 @@
|
|||
* Make the application name snake cased when it contains spaces
|
||||
|
||||
The application name is used to fill the `database.yml` and
|
||||
`session_store.rb` files ; previously, if the provided name
|
||||
contained whitespaces, it led to unexpected names in these files.
|
||||
|
||||
*Robin Dupret*
|
||||
|
||||
* Added `--model-name` option to `ScaffoldControllerGenerator`.
|
||||
|
||||
*yalab*
|
||||
|
|
|
@ -239,7 +239,7 @@ module Rails
|
|||
end
|
||||
|
||||
def app_name
|
||||
@app_name ||= (defined_app_const_base? ? defined_app_name : File.basename(destination_root)).tr(".", "_")
|
||||
@app_name ||= (defined_app_const_base? ? defined_app_name : File.basename(destination_root)).tr('\\', '').tr(". ", "_")
|
||||
end
|
||||
|
||||
def defined_app_name
|
||||
|
|
|
@ -21,7 +21,7 @@ module Rails
|
|||
# end
|
||||
# end
|
||||
def assert_file(relative, *contents)
|
||||
absolute = File.expand_path(relative, destination_root)
|
||||
absolute = File.expand_path(relative, destination_root).shellescape
|
||||
assert File.exists?(absolute), "Expected file #{relative.inspect} to exist, but does not"
|
||||
|
||||
read = File.read(absolute) if block_given? || !contents.empty?
|
||||
|
|
|
@ -367,6 +367,16 @@ class AppGeneratorTest < Rails::Generators::TestCase
|
|||
assert_no_match(/run bundle install/, output)
|
||||
end
|
||||
|
||||
def test_application_name_with_spaces
|
||||
path = File.join(destination_root, "foo bar".shellescape)
|
||||
|
||||
# This also applies to MySQL apps but not with SQLite
|
||||
run_generator [path, "-d", 'postgresql']
|
||||
|
||||
assert_file "foo bar/config/database.yml", /database: foo_bar_development/
|
||||
assert_file "foo bar/config/initializers/session_store.rb", /key: '_foo_bar/
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def action(*args, &block)
|
||||
|
|
Loading…
Reference in New Issue