From 89a6955fb77ac5f5157a04557089f1170c577bdb Mon Sep 17 00:00:00 2001 From: Kyle Maxwell Date: Thu, 11 Feb 2010 16:04:24 -0800 Subject: [PATCH] invalid namespace raises an error --- railties/lib/generators/rails/app/app_generator.rb | 7 +++++++ railties/test/generators/app_generator_test.rb | 5 +++++ 2 files changed, 12 insertions(+), 0 deletions(-) diff --git a/railties/lib/generators/rails/app/app_generator.rb b/railties/lib/generators/rails/app/app_generator.rb index c439ed8..57cbc47 100644 --- a/railties/lib/generators/rails/app/app_generator.rb +++ b/railties/lib/generators/rails/app/app_generator.rb @@ -6,6 +6,10 @@ module Rails::Generators # We need to store the RAILS_DEV_PATH in a constant, otherwise the path # 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] class AppGenerator < Base DATABASES = %w( mysql oracle postgresql sqlite3 frontbase ibm_db ) @@ -213,6 +217,9 @@ module Rails::Generators when /^\d/ raise Error, "Invalid application name #{app_name}. Please give a name which does not start with numbers." end + if 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 commands." + end end def app_secret diff --git a/railties/test/generators/app_generator_test.rb b/railties/test/generators/app_generator_test.rb index 0a746b2..7e43d26 100644 --- a/railties/test/generators/app_generator_test.rb +++ b/railties/test/generators/app_generator_test.rb @@ -49,6 +49,11 @@ class AppGeneratorTest < Rails::Generators::TestCase tmp/pids ).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 commands.\n", content + end def test_invalid_database_option_raises_an_error content = capture(:stderr){ run_generator([destination_root, "-d", "unknown"]) } -- 1.6.4.4