Skip to content

Commit

Permalink
Merge pull request #20748 from robin850/reserved-names
Browse files Browse the repository at this point in the history
Display a more human readable list of reserved names
  • Loading branch information
eileencodes committed Jul 5, 2015
2 parents a05e245 + 42b5906 commit 4d737a4
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 4 deletions.
4 changes: 3 additions & 1 deletion railties/lib/rails/generators/rails/app/app_generator.rb
Expand Up @@ -356,7 +356,9 @@ def valid_const?
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: #{RESERVED_NAMES}"
raise Error, "Invalid application name #{app_name}. Please give a " \
"name which does not match one of the reserved rails " \
"words: #{RESERVED_NAMES.join(", ")}"
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
Expand Down
Expand Up @@ -364,7 +364,9 @@ def valid_const?
elsif camelized =~ /^\d/
raise Error, "Invalid plugin name #{original_name}. Please give a name which does not start with numbers."
elsif RESERVED_NAMES.include?(name)
raise Error, "Invalid plugin name #{original_name}. Please give a name which does not match one of the reserved rails words: #{RESERVED_NAMES}"
raise Error, "Invalid plugin name #{original_name}. Please give a " \
"name which does not match one of the reserved rails " \
"words: #{RESERVED_NAMES.join(", ")}"
elsif Object.const_defined?(camelized)
raise Error, "Invalid plugin name #{original_name}, constant #{camelized} is already in use. Please choose another plugin name."
end
Expand Down
2 changes: 1 addition & 1 deletion railties/test/generators/plugin_generator_test.rb
Expand Up @@ -38,7 +38,7 @@ def test_invalid_plugin_name_raises_an_error
assert_equal "Invalid plugin name 43things. Please give a name which does not start with numbers.\n", content

content = capture(:stderr){ run_generator [File.join(destination_root, "plugin")] }
assert_equal "Invalid plugin name plugin. Please give a name which does not match one of the reserved rails words: [\"application\", \"destroy\", \"plugin\", \"runner\", \"test\"]\n", content
assert_equal "Invalid plugin name plugin. Please give a name which does not match one of the reserved rails words: application, destroy, plugin, runner, test\n", content

content = capture(:stderr){ run_generator [File.join(destination_root, "Digest")] }
assert_equal "Invalid plugin name Digest, constant Digest is already in use. Please choose another plugin name.\n", content
Expand Down
2 changes: 1 addition & 1 deletion railties/test/generators/shared_generator_tests.rb
Expand Up @@ -56,7 +56,7 @@ def test_name_collision_raises_an_error
reserved_words = %w[application destroy plugin runner test]
reserved_words.each do |reserved|
content = capture(:stderr){ run_generator [File.join(destination_root, reserved)] }
assert_match(/Invalid \w+ name #{reserved}. Please give a name which does not match one of the reserved rails words: \["application", "destroy", "plugin", "runner", "test"\]\n/, content)
assert_match(/Invalid \w+ name #{reserved}. Please give a name which does not match one of the reserved rails words: application, destroy, plugin, runner, test\n/, content)
end
end

Expand Down

0 comments on commit 4d737a4

Please sign in to comment.