From 8d47078a492de9e3fca61ec6894e975d570ef449 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Wed, 15 Jul 2009 22:37:22 +0200 Subject: Added source_paths to rails generators. If a template is added to RAILS_ROOT/lib/templates/base/generator it will be used. For example, to customize edit.html.erb template on scaffold, just add a customized copy at RAILS_ROOT/lib/templates/erb/scaffold. --- railties/test/generators_test.rb | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'railties/test/generators_test.rb') diff --git a/railties/test/generators_test.rb b/railties/test/generators_test.rb index 964def4158..78c05f2eb8 100644 --- a/railties/test/generators_test.rb +++ b/railties/test/generators_test.rb @@ -84,7 +84,7 @@ class GeneratorsTest < GeneratorsTestCase assert_equal "Others: active_record:fixjour, fixjour, mspec, rails:javascripts, wrong.", output end - def test_warning_is_raised_if_generator_cant_be_loaded + def test_warning_is_shown_if_generator_cant_be_loaded output = capture(:stderr){ Rails::Generators.find_by_namespace(:wrong) } assert_match /\[WARNING\] Could not load generator at/, output assert_match /Error: uninitialized constant Rails::Generator/, output @@ -96,4 +96,22 @@ class GeneratorsTest < GeneratorsTestCase ensure Thor::Base.shell = Thor::Shell::Color end + + def test_rails_root_templates + template = File.join(RAILS_ROOT, "lib", "templates", "active_record", "model", "model.rb") + + # Create template + mkdir_p(File.dirname(template)) + File.open(template, 'w'){ |f| f.write "empty" } + + output = capture(:stdout) do + Rails::Generators.invoke :model, ["user"], :destination_root => destination_root + end + + assert_file "app/models/user.rb" do |content| + assert_equal "empty", content + end + ensure + rm_rf File.dirname(template) + end end -- cgit v1.2.3