aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYves Senn <yves.senn@gmail.com>2013-10-22 05:22:04 -0700
committerYves Senn <yves.senn@gmail.com>2013-10-22 05:22:04 -0700
commitebeb87eca8424bad214a50b7fb9b2704f102d34d (patch)
tree941a7fc64fc84da3442b66338805829c16f6d16d
parent99044beb8163d42d6f0bcf26c7215e209e7f2bc7 (diff)
parent52b252614e275da799b6a15cebbfd067c59987d1 (diff)
downloadrails-ebeb87eca8424bad214a50b7fb9b2704f102d34d.tar.gz
rails-ebeb87eca8424bad214a50b7fb9b2704f102d34d.tar.bz2
rails-ebeb87eca8424bad214a50b7fb9b2704f102d34d.zip
Merge pull request #12606 from robin850/apps-with-spaces
Make the application name snake cased when it contains spaces
-rw-r--r--railties/CHANGELOG.md8
-rw-r--r--railties/lib/rails/generators/rails/app/app_generator.rb2
-rw-r--r--railties/lib/rails/generators/testing/assertions.rb2
-rw-r--r--railties/test/generators/app_generator_test.rb10
4 files changed, 20 insertions, 2 deletions
diff --git a/railties/CHANGELOG.md b/railties/CHANGELOG.md
index 1d01c8d0e5..d12a1f21f8 100644
--- a/railties/CHANGELOG.md
+++ b/railties/CHANGELOG.md
@@ -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*
diff --git a/railties/lib/rails/generators/rails/app/app_generator.rb b/railties/lib/rails/generators/rails/app/app_generator.rb
index 92c876c835..db6b11abfa 100644
--- a/railties/lib/rails/generators/rails/app/app_generator.rb
+++ b/railties/lib/rails/generators/rails/app/app_generator.rb
@@ -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
diff --git a/railties/lib/rails/generators/testing/assertions.rb b/railties/lib/rails/generators/testing/assertions.rb
index 6267b2f2ee..cc88e830dd 100644
--- a/railties/lib/rails/generators/testing/assertions.rb
+++ b/railties/lib/rails/generators/testing/assertions.rb
@@ -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?
diff --git a/railties/test/generators/app_generator_test.rb b/railties/test/generators/app_generator_test.rb
index 2f0dfc7d3e..24f01c878c 100644
--- a/railties/test/generators/app_generator_test.rb
+++ b/railties/test/generators/app_generator_test.rb
@@ -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)