Browse files

Allow generators nested in more than one level

  • Loading branch information...
1 parent c76c699 commit 20897a6c2cef9c70b97eee1bcd2ed5b78303a274 @spastorino spastorino committed Jan 12, 2011
Showing with 9 additions and 1 deletion.
  1. +1 −1 railties/lib/rails/generators.rb
  2. +8 −0 railties/test/generators_test.rb
View
2 railties/lib/rails/generators.rb
@@ -155,7 +155,7 @@ def self.find_by_namespace(name, base=nil, context=nil) #:nodoc:
# commands.
def self.invoke(namespace, args=ARGV, config={})
names = namespace.to_s.split(':')
- if klass = find_by_namespace(names.pop, names.shift)
+ if klass = find_by_namespace(names.pop, names.any? && names.join(':'))
args << "--help" if args.empty? && klass.arguments.any? { |a| a.required? }
klass.start(args, config)
else
View
8 railties/test/generators_test.rb
@@ -94,6 +94,14 @@ def test_find_by_namespace_show_warning_if_generator_cant_be_loaded
assert_match /Rails 2\.x generator/, output
end
+ def test_invoke_with_nested_namespaces
+ model_generator = mock('ModelGenerator') do
+ expects(:start).with(["Account"], {})
+ end
+ Rails::Generators.expects(:find_by_namespace).with('namespace', 'my:awesome').returns(model_generator)
+ Rails::Generators.invoke 'my:awesome:namespace', ["Account"]
+ end
+
def test_rails_generators_help_with_builtin_information
output = capture(:stdout){ Rails::Generators.help }
assert_match /Rails:/, output

0 comments on commit 20897a6

Please sign in to comment.