Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

allow preview interceptors to be registered through `config.action_ma…

…iler`.

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 a15704d, reversing
changes made to 1bd12a8.

/cc @kuldeepaggarwal @y-yagi

Conflicts:
	actionmailer/CHANGELOG.md
  • Loading branch information...
commit 0a2ddeadb18abfd76185e7ee0341cd3a6c6041f5 1 parent 276a0e3
@senny senny authored
View
7 actionmailer/CHANGELOG.md
@@ -1,3 +1,10 @@
+* Allow preview interceptors to be registered through
+ `config.action_mailer.preview_interceptors`.
+
+ See #15739.
+
+ *Yves Senn*
+
## Rails 4.1.2 (unreleased) ##
* No changes.
View
2  actionmailer/lib/action_mailer/base.rb
@@ -339,7 +339,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
View
1  actionmailer/lib/action_mailer/railtie.rb
@@ -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) }
View
32 railties/test/application/configuration_test.rb
@@ -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

2 comments on commit 0a2ddea

Please sign in to comment.
Something went wrong with that request. Please try again.