mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Add a check to ensure that the application name does not already exist, i.e. String or Module are part of ruby [#3872 status:resolved]
Signed-off-by: José Valim <jose.valim@gmail.com>
This commit is contained in:
parent
e484d4ae56
commit
9268b598bb
2 changed files with 9 additions and 0 deletions
|
@ -220,6 +220,8 @@ module Rails::Generators
|
|||
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."
|
||||
elsif Object.const_defined?(app_const_base)
|
||||
raise Error, "Invalid application name #{app_name}, constant #{app_const_base} is already in use. Please choose another application name."
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -65,6 +65,13 @@ class AppGeneratorTest < Rails::Generators::TestCase
|
|||
assert_equal "Invalid application name 43-things. Please give a name which does not start with numbers.\n", content
|
||||
end
|
||||
|
||||
def test_application_name_raises_an_error_if_name_already_used_constant
|
||||
%w{ String Hash Class Module Set Symbol }.each do |ruby_class|
|
||||
content = capture(:stderr){ run_generator [File.join(destination_root, ruby_class)] }
|
||||
assert_equal "Invalid application name #{ruby_class}, constant #{ruby_class} is already in use. Please choose another application name.\n", content
|
||||
end
|
||||
end
|
||||
|
||||
def test_invalid_application_name_is_fixed
|
||||
run_generator [File.join(destination_root, "things-43")]
|
||||
assert_file "things-43/config/environment.rb", /Things43::Application\.initialize!/
|
||||
|
|
Loading…
Reference in a new issue