Skip to content

Commit

Permalink
Allow generators nested in more than one level
Browse files Browse the repository at this point in the history
  • Loading branch information
spastorino committed Jan 12, 2011
1 parent 5de1314 commit 3667438
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion railties/lib/rails/generators.rb
Expand Up @@ -158,7 +158,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
Expand Down
8 changes: 8 additions & 0 deletions railties/test/generators_test.rb
Expand Up @@ -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
Expand Down

0 comments on commit 3667438

Please sign in to comment.