ApplicationMailer should be generated by default just like every other Application* parent

This commit is contained in:
David Heinemeier Hansson 2015-12-17 12:47:49 +01:00 committed by Rafael Mendonça França
parent 80ba81d2a0
commit 293d35e256
12 changed files with 25 additions and 45 deletions

View File

@ -9,9 +9,6 @@ module Rails
def create_mailer_file
template "mailer.rb", File.join('app/mailers', class_path, "#{file_name}_mailer.rb")
if self.behavior == :invoke
template "application_mailer.rb", 'app/mailers/application_mailer.rb'
end
end
hook_for :template_engine, :test_framework

View File

@ -9,13 +9,6 @@ module Erb # :nodoc:
view_base_path = File.join("app/views", class_path, file_name + '_mailer')
empty_directory view_base_path
if self.behavior == :invoke
formats.each do |format|
layout_path = File.join("app/views/layouts", filename_with_extensions("mailer", format))
template filename_with_extensions(:layout, format), layout_path
end
end
actions.each do |action|
@action = action

View File

@ -1,5 +0,0 @@
<html>
<body>
<%%= yield %>
</body>
</html>

View File

@ -59,8 +59,6 @@ module Rails
keep_file 'app/assets/images'
keep_file 'app/assets/javascripts/channels' unless options[:skip_action_cable]
keep_file 'app/mailers'
keep_file 'app/controllers/concerns'
keep_file 'app/models/concerns'
end
@ -301,6 +299,14 @@ module Rails
end
end
def delete_action_mailer_files_skipping_action_mailer
if options[:skip_action_mailer]
remove_file 'app/mailers/application_mailer.rb'
remove_file 'app/views/layouts/mailer.html.erb'
remove_file 'app/views/layouts/mailer.text.erb'
end
end
def delete_active_record_initializers_skipping_active_record
if options[:skip_active_record]
remove_file 'config/initializers/active_record_belongs_to_required_by_default.rb'

View File

@ -1,4 +1,4 @@
class ApplicationMailer < ActionMailer::Base
default from: "from@example.com"
default from: 'from@example.com'
layout 'mailer'
end

View File

@ -0,0 +1,13 @@
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style>
/* Email styles need to be inline */
</style>
</head>
<body>
<%%= yield %>
</body>
</html>

View File

@ -229,6 +229,7 @@ module ApplicationTests
test "the application can be eager loaded even when there are no frameworks" do
FileUtils.rm_rf("#{app_path}/app/models/application_record.rb")
FileUtils.rm_rf("#{app_path}/app/mailers/application_mailer.rb")
FileUtils.rm_rf("#{app_path}/config/environments")
add_to_config <<-RUBY
config.eager_load = true

View File

@ -98,7 +98,7 @@ module ApplicationTests
end
def test_code_statistics_sanity
assert_match "Code LOC: 10 Test LOC: 0 Code to Test Ratio: 1:0.0",
assert_match "Code LOC: 14 Test LOC: 0 Code to Test Ratio: 1:0.0",
Dir.chdir(app_path){ `bin/rake stats` }
end

View File

@ -617,7 +617,6 @@ class AppGeneratorTest < Rails::Generators::TestCase
run_generator
folders_with_keep = %w(
app/assets/images
app/mailers
app/controllers/concerns
app/models/concerns
lib/tasks

View File

@ -14,15 +14,6 @@ class MailerGeneratorTest < Rails::Generators::TestCase
end
end
def test_application_mailer_skeleton_is_created
run_generator
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
run_generator
assert_file "app/mailers/notifier_mailer.rb" do |mailer|
@ -87,10 +78,6 @@ class MailerGeneratorTest < Rails::Generators::TestCase
assert_match(%r(\sapp/views/notifier_mailer/bar\.text\.erb), view)
assert_match(/<%= @greeting %>/, view)
end
assert_file "app/views/layouts/mailer.text.erb" do |view|
assert_match(/<%= yield %>/, view)
end
end
def test_invokes_default_html_template_engine
@ -104,17 +91,11 @@ class MailerGeneratorTest < Rails::Generators::TestCase
assert_match(%r(\sapp/views/notifier_mailer/bar\.html\.erb), view)
assert_match(/<%= @greeting %>/, view)
end
assert_file "app/views/layouts/mailer.html.erb" do |view|
assert_match(%r{<html>\n <body>\n <%= yield %>\n </body>\n</html>}, view)
end
end
def test_invokes_default_template_engine_even_with_no_action
run_generator ["notifier"]
assert_file "app/views/notifier_mailer"
assert_file "app/views/layouts/mailer.text.erb"
assert_file "app/views/layouts/mailer.html.erb"
end
def test_logs_if_the_template_engine_cannot_be_found
@ -162,10 +143,6 @@ class MailerGeneratorTest < Rails::Generators::TestCase
assert_no_file "app/views/notifier/bar.text.erb"
assert_no_file "app/views/notifier/foo.html.erb"
assert_no_file "app/views/notifier/bar.html.erb"
assert_file "app/mailers/application_mailer.rb"
assert_file "app/views/layouts/mailer.text.erb"
assert_file "app/views/layouts/mailer.html.erb"
end
def test_mailer_suffix_is_not_duplicated

View File

@ -144,7 +144,6 @@ module SharedGeneratorTests
def test_skip_git
run_generator [destination_root, '--skip-git', '--full']
assert_no_file('.gitignore')
assert_file('app/mailers/.keep')
end
def test_skip_keeps
@ -154,6 +153,6 @@ module SharedGeneratorTests
assert_no_match(/\.keep/, content)
end
assert_no_file('app/mailers/.keep')
assert_no_file('app/models/concerns/.keep')
end
end