提交 52b25261 编写于 作者: R Robin Dupret

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.
上级 99044beb
* 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`. * Added `--model-name` option to `ScaffoldControllerGenerator`.
*yalab* *yalab*
......
...@@ -239,7 +239,7 @@ def file(*args, &block) ...@@ -239,7 +239,7 @@ def file(*args, &block)
end end
def app_name 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 end
def defined_app_name def defined_app_name
......
...@@ -21,7 +21,7 @@ module Assertions ...@@ -21,7 +21,7 @@ module Assertions
# end # end
# end # end
def assert_file(relative, *contents) 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" assert File.exists?(absolute), "Expected file #{relative.inspect} to exist, but does not"
read = File.read(absolute) if block_given? || !contents.empty? read = File.read(absolute) if block_given? || !contents.empty?
......
...@@ -367,6 +367,16 @@ def test_pretend_option ...@@ -367,6 +367,16 @@ def test_pretend_option
assert_no_match(/run bundle install/, output) assert_no_match(/run bundle install/, output)
end 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 protected
def action(*args, &block) def action(*args, &block)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册