提交 4d0bf49b 编写于 作者: P Prathamesh Sonpatki

Correctly generate application_mailer.rb in mountable engines

- Followup of https://github.com/rails/rails/pull/24161.
上级 92010303
......@@ -11,8 +11,8 @@ 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'
if self.behavior == :invoke && !File.exist?(application_mailer_file_name)
template 'application_mailer.rb', application_mailer_file_name
end
end
end
......@@ -23,6 +23,15 @@ def create_mailer_file
def file_name
@_file_name ||= super.gsub(/_mailer/i, '')
end
private
def application_mailer_file_name
@_application_mailer_file_name ||= if mountable_engine?
"app/mailers/#{namespaced_path}/application_mailer.rb"
else
"app/mailers/application_mailer.rb"
end
end
end
end
end
<% module_namespacing do %>
class ApplicationMailer < ActionMailer::Base
default from: 'from@example.com'
layout :mailer
end
<% end %>
......@@ -656,6 +656,19 @@ def test_generate_application_record_when_does_not_exist_in_mountable_engine
end
end
def test_generate_application_mailer_when_does_not_exist_in_mountable_engine
run_generator [destination_root, '--mountable']
FileUtils.rm "#{destination_root}/app/mailers/bukkits/application_mailer.rb"
capture(:stdout) do
`#{destination_root}/bin/rails g mailer User`
end
assert_file "#{destination_root}/app/mailers/bukkits/application_mailer.rb" do |mailer|
assert_match(/module Bukkits/, mailer)
assert_match(/class ApplicationMailer < ActionMailer::Base/, mailer)
end
end
def test_after_bundle_callback
path = 'http://example.org/rails_template'
template = %{ after_bundle { run 'echo ran after_bundle' } }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册