提交 d4e008fd 编写于 作者: K Kyle Maxwell 提交者: José Valim

Invalid namespace on app generation raises an error

Signed-off-by: NJosé Valim <jose.valim@gmail.com>
上级 23fd1f12
...@@ -7,6 +7,10 @@ module Rails::Generators ...@@ -7,6 +7,10 @@ module Rails::Generators
# can change in Ruby 1.8.7 when we FileUtils.cd. # can change in Ruby 1.8.7 when we FileUtils.cd.
RAILS_DEV_PATH = File.expand_path("../../../../..", File.dirname(__FILE__)) 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 class AppGenerator < Base
DATABASES = %w( mysql oracle postgresql sqlite3 frontbase ibm_db ) DATABASES = %w( mysql oracle postgresql sqlite3 frontbase ibm_db )
...@@ -209,9 +213,10 @@ def app_const ...@@ -209,9 +213,10 @@ def app_const
end end
def valid_app_const? def valid_app_const?
case app_const if app_const =~ /^\d/
when /^\d/
raise Error, "Invalid application name #{app_name}. Please give a name which does not start with numbers." 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
end end
......
...@@ -50,6 +50,11 @@ def test_application_skeleton_is_created ...@@ -50,6 +50,11 @@ def test_application_skeleton_is_created
).each{ |path| assert_file path } ).each{ |path| assert_file path }
end 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 def test_invalid_database_option_raises_an_error
content = capture(:stderr){ run_generator([destination_root, "-d", "unknown"]) } content = capture(:stderr){ run_generator([destination_root, "-d", "unknown"]) }
assert_match /Invalid value for \-\-database option/, content assert_match /Invalid value for \-\-database option/, content
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册