From 3667438da36be96de42e32e0c82584151d1548be Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Wed, 12 Jan 2011 21:27:38 -0200 Subject: [PATCH] Allow generators nested in more than one level --- railties/lib/rails/generators.rb | 2 +- railties/test/generators_test.rb | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/railties/lib/rails/generators.rb b/railties/lib/rails/generators.rb index 76ef598d68719..1f1813dcad48d 100644 --- a/railties/lib/rails/generators.rb +++ b/railties/lib/rails/generators.rb @@ -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 diff --git a/railties/test/generators_test.rb b/railties/test/generators_test.rb index 214a69a949100..f902557d68c5c 100644 --- a/railties/test/generators_test.rb +++ b/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