aboutsummaryrefslogtreecommitdiffstats
path: root/railties
diff options
context:
space:
mode:
Diffstat (limited to 'railties')
-rw-r--r--railties/lib/generators/rails/app/app_generator.rb9
-rw-r--r--railties/test/generators/app_generator_test.rb5
2 files changed, 12 insertions, 2 deletions
diff --git a/railties/lib/generators/rails/app/app_generator.rb b/railties/lib/generators/rails/app/app_generator.rb
index c439ed89f5..ea1930a966 100644
--- a/railties/lib/generators/rails/app/app_generator.rb
+++ b/railties/lib/generators/rails/app/app_generator.rb
@@ -7,6 +7,10 @@ module Rails::Generators
# can change in Ruby 1.8.7 when we FileUtils.cd.
RAILS_DEV_PATH = File.expand_path("../../../../..", File.dirname(__FILE__))
+ RESERVED_NAMES = %w[generate console server dbconsole
+ application destroy benchmarker profiler
+ plugin runner test]
+
class AppGenerator < Base
DATABASES = %w( mysql oracle postgresql sqlite3 frontbase ibm_db )
@@ -209,9 +213,10 @@ module Rails::Generators
end
def valid_app_const?
- case app_const
- when /^\d/
+ if app_const =~ /^\d/
raise Error, "Invalid application name #{app_name}. Please give a name which does not start with numbers."
+ elsif RESERVED_NAMES.include?(app_name)
+ raise Error, "Invalid application name #{app_name}. Please give a name which does not match one of the reserved rails words."
end
end
diff --git a/railties/test/generators/app_generator_test.rb b/railties/test/generators/app_generator_test.rb
index 0a746b200f..01d643cd8c 100644
--- a/railties/test/generators/app_generator_test.rb
+++ b/railties/test/generators/app_generator_test.rb
@@ -50,6 +50,11 @@ class AppGeneratorTest < Rails::Generators::TestCase
).each{ |path| assert_file path }
end
+ def test_name_collision_raises_an_error
+ content = capture(:stderr){ run_generator [File.join(destination_root, "generate")] }
+ assert_equal "Invalid application name generate. Please give a name which does not match one of the reserved rails words.\n", content
+ end
+
def test_invalid_database_option_raises_an_error
content = capture(:stderr){ run_generator([destination_root, "-d", "unknown"]) }
assert_match /Invalid value for \-\-database option/, content