diff options
-rw-r--r-- | railties/lib/rails/generators.rb | 23 | ||||
-rw-r--r-- | railties/test/fixtures/lib/generators/model_generator.rb | 1 | ||||
-rw-r--r-- | railties/test/fixtures/lib/rails_generators/foobar/foobar_generator.rb (renamed from railties/test/fixtures/lib/generators/foobar/foobar_generator.rb) | 0 | ||||
-rw-r--r-- | railties/test/generators_test.rb | 8 |
4 files changed, 23 insertions, 9 deletions
diff --git a/railties/lib/rails/generators.rb b/railties/lib/rails/generators.rb index efeeecb685..83b8c74966 100644 --- a/railties/lib/rails/generators.rb +++ b/railties/lib/rails/generators.rb @@ -134,9 +134,14 @@ module Rails lookups = [] lookups << "#{base}:#{name}" if base lookups << "#{name}:#{context}" if context - lookups << "#{name}:#{name}" unless name.to_s.include?(?:) - lookups << "#{name}" - lookups << "rails:#{name}" unless base || context || name.to_s.include?(?:) + + unless base || context + unless name.to_s.include?(?:) + lookups << "#{name}:#{name}" + lookups << "rails:#{name}" + end + lookups << "#{name}" + end lookup(lookups) @@ -232,9 +237,9 @@ module Rails load_generators_from_railties! paths = namespaces_to_paths(namespaces) - paths.each do |path| - ["generators", "rails_generators"].each do |base| - path = "#{base}/#{path}_generator" + paths.each do |raw_path| + ["rails_generators", "generators"].each do |base| + path = "#{base}/#{raw_path}_generator" begin require path @@ -243,9 +248,9 @@ module Rails raise unless e.message =~ /#{Regexp.escape(path)}$/ rescue NameError => e raise unless e.message =~ /Rails::Generator([\s(::)]|$)/ - warn "[WARNING] Could not load generator #{path.inspect} because it's a Rails 2.x generator, which is not supported anymore. Error: #{e.message}.\n#{e.backtrace}" + warn "[WARNING] Could not load generator #{path.inspect} because it's a Rails 2.x generator, which is not supported anymore. Error: #{e.message}.\n#{e.backtrace.join("\n")}" rescue Exception => e - warn "[WARNING] Could not load generator #{path.inspect}. Error: #{e.message}.\n#{e.backtrace}" + warn "[WARNING] Could not load generator #{path.inspect}. Error: #{e.message}.\n#{e.backtrace.join("\n")}" end end end @@ -280,7 +285,7 @@ module Rails paths = [] namespaces.each do |namespace| pieces = namespace.split(":") - paths << pieces.dup.push(pieces.last).join("/") + paths << pieces.dup.push(pieces.last).join("/") unless pieces.uniq.size == 1 paths << pieces.join("/") end paths.uniq! diff --git a/railties/test/fixtures/lib/generators/model_generator.rb b/railties/test/fixtures/lib/generators/model_generator.rb new file mode 100644 index 0000000000..9098a8a354 --- /dev/null +++ b/railties/test/fixtures/lib/generators/model_generator.rb @@ -0,0 +1 @@ +raise "I should never be loaded"
\ No newline at end of file diff --git a/railties/test/fixtures/lib/generators/foobar/foobar_generator.rb b/railties/test/fixtures/lib/rails_generators/foobar/foobar_generator.rb index d1de8c56fa..d1de8c56fa 100644 --- a/railties/test/fixtures/lib/generators/foobar/foobar_generator.rb +++ b/railties/test/fixtures/lib/rails_generators/foobar/foobar_generator.rb diff --git a/railties/test/generators_test.rb b/railties/test/generators_test.rb index 664d1e5670..f37b684f73 100644 --- a/railties/test/generators_test.rb +++ b/railties/test/generators_test.rb @@ -16,6 +16,7 @@ class GeneratorsTest < Rails::Generators::TestCase end def test_simple_invoke + assert File.exists?(File.join(@path, 'generators', 'model_generator.rb')) TestUnit::Generators::ModelGenerator.expects(:start).with(["Account"], {}) Rails::Generators.invoke("test_unit:model", ["Account"]) end @@ -30,6 +31,13 @@ class GeneratorsTest < Rails::Generators::TestCase assert_match /Description:/, output end + def test_should_give_higher_preference_to_rails_generators + assert File.exists?(File.join(@path, 'generators', 'model_generator.rb')) + Rails::Generators::ModelGenerator.expects(:start).with(["Account"], {}) + warnings = capture(:stderr){ Rails::Generators.invoke :model, ["Account"] } + assert warnings.empty? + end + def test_invoke_with_default_values Rails::Generators::ModelGenerator.expects(:start).with(["Account"], {}) Rails::Generators.invoke :model, ["Account"] |