parent
bc04455f10
commit
39d2251d8a
|
@ -246,8 +246,20 @@ task :default => :test
|
|||
"rails plugin new #{self.arguments.map(&:usage).join(' ')} [options]"
|
||||
end
|
||||
|
||||
def original_name
|
||||
@original_name ||= File.basename(destination_root)
|
||||
end
|
||||
|
||||
def name
|
||||
@name ||= File.basename(destination_root)
|
||||
unless @name
|
||||
# same as ActiveSupport::Inflector#underscore except not replacing '-'
|
||||
@name = original_name.dup
|
||||
@name.gsub!(/([A-Z]+)([A-Z][a-z])/,'\1_\2')
|
||||
@name.gsub!(/([a-z\d])([A-Z])/,'\1_\2')
|
||||
@name.downcase!
|
||||
end
|
||||
|
||||
@name
|
||||
end
|
||||
|
||||
def camelized
|
||||
|
@ -256,11 +268,11 @@ task :default => :test
|
|||
|
||||
def valid_const?
|
||||
if camelized =~ /^\d/
|
||||
raise Error, "Invalid plugin name #{name}. Please give a name which does not start with numbers."
|
||||
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 #{name}. Please give a name which does not match one of the reserved rails words."
|
||||
raise Error, "Invalid plugin name #{original_name}. Please give a name which does not match one of the reserved rails words."
|
||||
elsif Object.const_defined?(camelized)
|
||||
raise Error, "Invalid plugin name #{name}, constant #{camelized} is already in use. Please choose another plugin name."
|
||||
raise Error, "Invalid plugin name #{original_name}, constant #{camelized} is already in use. Please choose another plugin name."
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -37,6 +37,12 @@ class PluginNewGeneratorTest < Rails::Generators::TestCase
|
|||
assert_file "things-43/lib/things-43.rb", /module Things43/
|
||||
end
|
||||
|
||||
def test_camelcase_plugin_name_underscores_filenames
|
||||
run_generator [File.join(destination_root, "CamelCasedName")]
|
||||
assert_no_file "CamelCasedName/lib/CamelCasedName.rb"
|
||||
assert_file "CamelCasedName/lib/camel_cased_name.rb", /module CamelCasedName/
|
||||
end
|
||||
|
||||
def test_generating_without_options
|
||||
run_generator
|
||||
assert_file "README.rdoc", /Bukkits/
|
||||
|
|
Loading…
Reference in New Issue