diff options
author | José Valim <jose.valim@gmail.com> | 2009-06-25 12:57:58 +0200 |
---|---|---|
committer | José Valim <jose.valim@gmail.com> | 2009-06-25 12:57:58 +0200 |
commit | 6e6c0117b30226f031771acb9715318987067f51 (patch) | |
tree | 0561577a33b94e0245ee88ef56988eb8b638b4a1 /railties/lib/generators/test_unit | |
parent | ed33c29a4e2a07c2a738ec13775c5cc0d7867b50 (diff) | |
download | rails-6e6c0117b30226f031771acb9715318987067f51.tar.gz rails-6e6c0117b30226f031771acb9715318987067f51.tar.bz2 rails-6e6c0117b30226f031771acb9715318987067f51.zip |
Added Mailer generaator template engine and test framework agnostic.
Diffstat (limited to 'railties/lib/generators/test_unit')
3 files changed, 46 insertions, 0 deletions
diff --git a/railties/lib/generators/test_unit/mailer/mailer_generator.rb b/railties/lib/generators/test_unit/mailer/mailer_generator.rb new file mode 100644 index 0000000000..5fa7751076 --- /dev/null +++ b/railties/lib/generators/test_unit/mailer/mailer_generator.rb @@ -0,0 +1,23 @@ +module TestUnit + module Generators + class MailerGenerator < Base + argument :actions, :type => :array, :default => [] + + desc <<DESC +Description: + Create TestUnit files for mailer generator. +DESC + + def create_test_files + template "unit_test.rb", File.join('test', 'unit', class_path, "#{file_name}_test.rb") + end + + def create_fixtures_files + actions.each do |action| + @action, @path = action, File.join(file_path, action) + template "fixture", File.join("test", "fixtures", @path) + end + end + end + end +end diff --git a/railties/lib/generators/test_unit/mailer/templates/fixture b/railties/lib/generators/test_unit/mailer/templates/fixture new file mode 100644 index 0000000000..cda2cd24fe --- /dev/null +++ b/railties/lib/generators/test_unit/mailer/templates/fixture @@ -0,0 +1,3 @@ +<%= class_name %>#<%= @action %> + +Find me in <%= @path %> diff --git a/railties/lib/generators/test_unit/mailer/templates/unit_test.rb b/railties/lib/generators/test_unit/mailer/templates/unit_test.rb new file mode 100644 index 0000000000..4de94076e9 --- /dev/null +++ b/railties/lib/generators/test_unit/mailer/templates/unit_test.rb @@ -0,0 +1,20 @@ +require 'test_helper' + +class <%= class_name %>Test < ActionMailer::TestCase +<% for action in actions -%> + test "<%= action %>" do + @expected.subject = '<%= class_name %>#<%= action %>' + @expected.body = read_fixture('<%= action %>') + @expected.date = Time.now + + assert_equal @expected.encoded, <%= class_name %>.create_<%= action %>(@expected.date).encoded + end + +<% end -%> +<% if actions.blank? -%> + # replace this with your real tests + test "the truth" do + assert true + end +<% end -%> +end |