aboutsummaryrefslogtreecommitdiffstats
path: root/railties
diff options
context:
space:
mode:
authorPiotr Sarnacki <drogus@gmail.com>2012-04-01 01:12:49 +0200
committerPiotr Sarnacki <drogus@gmail.com>2012-04-02 00:30:42 +0200
commit515e1d33f25a75dee0726dab67a1469f5a4ce813 (patch)
tree1f6dd1fd2f2922830cf706c1743095c0700a5f9d /railties
parent27fc6ec95eb7a1756fb86693b6fe8e03f1d66ef3 (diff)
downloadrails-515e1d33f25a75dee0726dab67a1469f5a4ce813.tar.gz
rails-515e1d33f25a75dee0726dab67a1469f5a4ce813.tar.bz2
rails-515e1d33f25a75dee0726dab67a1469f5a4ce813.zip
Usage file in generators shouldn't be fetched only based on source_root
In case `source_roout` is not set, `default_source_root` is used, which includes also `templates` directory. If there is no `templates` directory, `default_source_root` is not available and USAGE will not be displayed. USAGE should be also checked based on default directory excluding `templates`.
Diffstat (limited to 'railties')
-rw-r--r--railties/lib/rails/generators/base.rb21
-rw-r--r--railties/test/generators/app_generator_test.rb2
-rw-r--r--railties/test/generators/migration_generator_test.rb4
3 files changed, 22 insertions, 5 deletions
diff --git a/railties/lib/rails/generators/base.rb b/railties/lib/rails/generators/base.rb
index af743a9c51..addc979dff 100644
--- a/railties/lib/rails/generators/base.rb
+++ b/railties/lib/rails/generators/base.rb
@@ -31,10 +31,9 @@ module Rails
# root otherwise uses a default description.
def self.desc(description=nil)
return super if description
- usage = source_root && File.expand_path("../USAGE", source_root)
- @desc ||= if usage && File.exist?(usage)
- ERB.new(File.read(usage)).result(binding)
+ @desc ||= if usage_path
+ ERB.new(File.read(usage_path)).result(binding)
else
"Description:\n Create #{base_name.humanize.downcase} files for #{generator_name} generator."
end
@@ -207,7 +206,8 @@ module Rails
# root, you should use source_root.
def self.default_source_root
return unless base_name && generator_name
- path = File.expand_path(File.join(base_name, generator_name, 'templates'), base_root)
+ return unless default_generator_root
+ path = File.join(default_generator_root, 'templates')
path if File.exists?(path)
end
@@ -371,6 +371,19 @@ module Rails
}
end
+ def self.usage_path
+ paths = [
+ source_root && File.expand_path("../USAGE", source_root),
+ default_generator_root && File.join(default_generator_root, "USAGE")
+ ]
+ paths.compact.detect { |path| File.exists? path }
+ end
+
+ def self.default_generator_root
+ path = File.expand_path(File.join(base_name, generator_name), base_root)
+ path if File.exists?(path)
+ end
+
end
end
end
diff --git a/railties/test/generators/app_generator_test.rb b/railties/test/generators/app_generator_test.rb
index 37703d9376..f1e760c52f 100644
--- a/railties/test/generators/app_generator_test.rb
+++ b/railties/test/generators/app_generator_test.rb
@@ -316,7 +316,7 @@ class AppGeneratorTest < Rails::Generators::TestCase
end
def test_default_usage
- File.expects(:exist?).returns(false)
+ Rails::Generators::AppGenerator.expects(:usage_path).returns(nil)
assert_match(/Create rails files for app generator/, Rails::Generators::AppGenerator.desc)
end
diff --git a/railties/test/generators/migration_generator_test.rb b/railties/test/generators/migration_generator_test.rb
index 16e4ac0881..a89631d022 100644
--- a/railties/test/generators/migration_generator_test.rb
+++ b/railties/test/generators/migration_generator_test.rb
@@ -157,4 +157,8 @@ class MigrationGeneratorTest < Rails::Generators::TestCase
end
end
end
+
+ def test_properly_identifies_usage_file
+ assert generator_class.send(:usage_path)
+ end
end