提交 f59ed560 编写于 作者: Y Yves Senn

allow preview interceptors to be registered through `config.action_mailer`.

This was partially broken because `preview_interceptors=` just assigned the
raw values, whithout going through `register_preview_interceptor`. Now the
Action Mailer railtie takes care of the `preview_interceptors` option.

This commit is a partial revert of:

Revert "Merge pull request #15739 from y-yagi/correct_doc_for_action_mailer_base"

This reverts commit a15704d7, reversing
changes made to 1bd12a86.

/cc @kuldeepaggarwal @y-yagi
上级 a15704d7
* Allow preview interceptors to be registered through
`config.action_mailer.preview_interceptors`.
See #15739.
*Yves Senn*
Please check [4-1-stable](https://github.com/rails/rails/blob/4-1-stable/actionmailer/CHANGELOG.md) for previous changes.
......@@ -340,7 +340,7 @@ module ActionMailer
# end
# end
#
# ActionMailer::Base.register_preview_interceptor :css_inline_styler
# config.action_mailer.preview_interceptors :css_inline_styler
#
# Note that interceptors need to be registered both with <tt>register_interceptor</tt>
# and <tt>register_preview_interceptor</tt> if they should operate on both sending and
......
......@@ -33,6 +33,7 @@ class Railtie < Rails::Railtie # :nodoc:
include app.routes.mounted_helpers
register_interceptors(options.delete(:interceptors))
register_preview_interceptors(options.delete(:preview_interceptors))
register_observers(options.delete(:observers))
options.each { |k,v| send("#{k}=", v) }
......
......@@ -8,6 +8,12 @@ def self.delivering_email(email); email; end
class ::MyOtherMailInterceptor < ::MyMailInterceptor; end
class ::MyPreviewMailInterceptor
def self.previewing_email(email); email; end
end
class ::MyOtherPreviewMailInterceptor < ::MyPreviewMailInterceptor; end
class ::MyMailObserver
def self.delivered_email(email); email; end
end
......@@ -460,6 +466,32 @@ def index
assert_equal [::MyMailInterceptor, ::MyOtherMailInterceptor], ::Mail.send(:class_variable_get, "@@delivery_interceptors")
end
test "registers preview interceptors with ActionMailer" do
add_to_config <<-RUBY
config.action_mailer.preview_interceptors = MyPreviewMailInterceptor
RUBY
require "#{app_path}/config/environment"
require "mail"
_ = ActionMailer::Base
assert_equal [::MyPreviewMailInterceptor], ActionMailer::Base.preview_interceptors
end
test "registers multiple preview interceptors with ActionMailer" do
add_to_config <<-RUBY
config.action_mailer.preview_interceptors = [MyPreviewMailInterceptor, "MyOtherPreviewMailInterceptor"]
RUBY
require "#{app_path}/config/environment"
require "mail"
_ = ActionMailer::Base
assert_equal [MyPreviewMailInterceptor, MyOtherPreviewMailInterceptor], ActionMailer::Base.preview_interceptors
end
test "registers observers with ActionMailer" do
add_to_config <<-RUBY
config.action_mailer.observers = MyMailObserver
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册