aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRafael França <rafaelmfranca@gmail.com>2016-03-11 22:25:31 -0300
committerRafael França <rafaelmfranca@gmail.com>2016-03-11 22:25:31 -0300
commit66afa81110fb7162a27cb43ae30e9880498f2fe7 (patch)
tree045790b31f4bad6a45f1d7b37094ed6a5a2de04d
parentd448918027667bc5ac4296d6df14826193046bc8 (diff)
parent1be95636253739b38abe1e44277da822a328bf20 (diff)
downloadrails-66afa81110fb7162a27cb43ae30e9880498f2fe7.tar.gz
rails-66afa81110fb7162a27cb43ae30e9880498f2fe7.tar.bz2
rails-66afa81110fb7162a27cb43ae30e9880498f2fe7.zip
Merge pull request #24161 from Sen-Zhang/restore_application_mailer
regenerate application_mailer.rb if it is missing
-rw-r--r--actionmailer/lib/rails/generators/mailer/mailer_generator.rb6
-rw-r--r--actionmailer/lib/rails/generators/mailer/templates/application_mailer.rb4
-rw-r--r--railties/test/generators/mailer_generator_test.rb6
3 files changed, 16 insertions, 0 deletions
diff --git a/actionmailer/lib/rails/generators/mailer/mailer_generator.rb b/actionmailer/lib/rails/generators/mailer/mailer_generator.rb
index ae5757917e..f86d43be61 100644
--- a/actionmailer/lib/rails/generators/mailer/mailer_generator.rb
+++ b/actionmailer/lib/rails/generators/mailer/mailer_generator.rb
@@ -9,6 +9,12 @@ module Rails
def create_mailer_file
template "mailer.rb", File.join('app/mailers', class_path, "#{file_name}_mailer.rb")
+
+ in_root do
+ if self.behavior == :invoke && !File.exist?('app/mailers/application_mailer.rb')
+ template 'application_mailer.rb', 'app/mailers/application_mailer.rb'
+ end
+ end
end
hook_for :template_engine, :test_framework
diff --git a/actionmailer/lib/rails/generators/mailer/templates/application_mailer.rb b/actionmailer/lib/rails/generators/mailer/templates/application_mailer.rb
new file mode 100644
index 0000000000..02e8d3e454
--- /dev/null
+++ b/actionmailer/lib/rails/generators/mailer/templates/application_mailer.rb
@@ -0,0 +1,4 @@
+class ApplicationMailer < ActionMailer::Base
+ default from: 'from@example.com'
+ layout :mailer
+end
diff --git a/railties/test/generators/mailer_generator_test.rb b/railties/test/generators/mailer_generator_test.rb
index f8d9ccacb4..71c11e5ef6 100644
--- a/railties/test/generators/mailer_generator_test.rb
+++ b/railties/test/generators/mailer_generator_test.rb
@@ -12,6 +12,12 @@ class MailerGeneratorTest < Rails::Generators::TestCase
assert_no_match(/default from: "from@example.com"/, mailer)
assert_no_match(/layout :mailer_notifier/, mailer)
end
+
+ assert_file 'app/mailers/application_mailer.rb' do |mailer|
+ assert_match(/class ApplicationMailer < ActionMailer::Base/, mailer)
+ assert_match(/default from: 'from@example.com'/, mailer)
+ assert_match(/layout :mailer/, mailer)
+ end
end
def test_mailer_with_i18n_helper