From 51c7660e089017adcf064301188c5b584cb41db0 Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Sat, 25 Sep 2010 13:35:29 +0200 Subject: [PATCH] Add namespacing to mailer generator MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: José Valim --- .../generators/mailer/templates/mailer.rb | 2 + .../mailer/templates/functional_test.rb | 2 + .../generators/namespaced_generators_test.rb | 52 +++++++++++++++++++ 3 files changed, 56 insertions(+) diff --git a/actionmailer/lib/rails/generators/mailer/templates/mailer.rb b/actionmailer/lib/rails/generators/mailer/templates/mailer.rb index 21e5918ecb..4d21c65101 100644 --- a/actionmailer/lib/rails/generators/mailer/templates/mailer.rb +++ b/actionmailer/lib/rails/generators/mailer/templates/mailer.rb @@ -1,3 +1,4 @@ +<% module_namespacing do -%> class <%= class_name %> < ActionMailer::Base default :from => "from@example.com" <% for action in actions -%> @@ -14,3 +15,4 @@ def <%= action %> end <% end -%> end +<% end -%> diff --git a/railties/lib/rails/generators/test_unit/mailer/templates/functional_test.rb b/railties/lib/rails/generators/test_unit/mailer/templates/functional_test.rb index 80ac7f0feb..b62c7fd279 100644 --- a/railties/lib/rails/generators/test_unit/mailer/templates/functional_test.rb +++ b/railties/lib/rails/generators/test_unit/mailer/templates/functional_test.rb @@ -1,5 +1,6 @@ require 'test_helper' +<% module_namespacing do -%> class <%= class_name %>Test < ActionMailer::TestCase <% for action in actions -%> test "<%= action %>" do @@ -18,3 +19,4 @@ class <%= class_name %>Test < ActionMailer::TestCase end <% end -%> end +<% end -%> diff --git a/railties/test/generators/namespaced_generators_test.rb b/railties/test/generators/namespaced_generators_test.rb index 6bf3fdf727..38b95a49ac 100644 --- a/railties/test/generators/namespaced_generators_test.rb +++ b/railties/test/generators/namespaced_generators_test.rb @@ -2,6 +2,7 @@ require 'rails/generators/rails/controller/controller_generator' require 'rails/generators/rails/model/model_generator' require 'rails/generators/rails/observer/observer_generator' +require 'rails/generators/mailer/mailer_generator' class NamespacedGeneratorTestCase < Rails::Generators::TestCase def setup @@ -150,3 +151,54 @@ def test_invokes_default_test_framework assert_file "test/unit/test_app/account_observer_test.rb", /module TestApp/, / class AccountObserverTest < ActiveSupport::TestCase/ end end + +class NamespacedMailerGeneratorTest < NamespacedGeneratorTestCase + include GeneratorsTestHelper + arguments %w(notifier foo bar) + tests Rails::Generators::MailerGenerator + + def test_mailer_skeleton_is_created + run_generator + assert_file "app/mailers/test_app/notifier.rb" do |mailer| + assert_match /module TestApp/, mailer + assert_match /class Notifier < ActionMailer::Base/, mailer + assert_match /default :from => "from@example.com"/, mailer + end + end + + def test_mailer_with_i18n_helper + run_generator + assert_file "app/mailers/test_app/notifier.rb" do |mailer| + assert_match /en\.notifier\.foo\.subject/, mailer + assert_match /en\.notifier\.bar\.subject/, mailer + end + end + + def test_invokes_default_test_framework + run_generator + assert_file "test/functional/test_app/notifier_test.rb" do |test| + assert_match /module TestApp/, test + assert_match /class NotifierTest < ActionMailer::TestCase/, test + assert_match /test "foo"/, test + assert_match /test "bar"/, test + end + end + + def test_invokes_default_template_engine + run_generator + assert_file "app/views/test_app/notifier/foo.text.erb" do |view| + assert_match %r(app/views/test_app/notifier/foo\.text\.erb), view + assert_match /<%= @greeting %>/, view + end + + assert_file "app/views/test_app/notifier/bar.text.erb" do |view| + assert_match %r(app/views/test_app/notifier/bar\.text\.erb), view + assert_match /<%= @greeting %>/, view + end + end + + def test_invokes_default_template_engine_even_with_no_action + run_generator ["notifier"] + assert_file "app/views/test_app/notifier" + end +end -- GitLab