From faaed863dd374b6c3c3ee0e317ed213edce1dd4d Mon Sep 17 00:00:00 2001 From: Andrew White Date: Mon, 4 May 2015 19:46:51 +0100 Subject: Document inline image mailer preview interceptor Explain what the interceptor is used for and how to remove it. --- railties/test/application/configuration_test.rb | 17 +++++++++++++++-- railties/test/application/mailer_previews_test.rb | 10 +++++----- 2 files changed, 20 insertions(+), 7 deletions(-) (limited to 'railties/test') diff --git a/railties/test/application/configuration_test.rb b/railties/test/application/configuration_test.rb index 14912326fc..38516a1c1a 100644 --- a/railties/test/application/configuration_test.rb +++ b/railties/test/application/configuration_test.rb @@ -690,7 +690,7 @@ module ApplicationTests _ = ActionMailer::Base - assert_equal [ActionMailer::Previews::InlineAttachments, ::MyPreviewMailInterceptor], ActionMailer::Base.preview_interceptors + assert_equal [ActionMailer::InlinePreviewInterceptor, ::MyPreviewMailInterceptor], ActionMailer::Base.preview_interceptors end test "registers multiple preview interceptors with ActionMailer" do @@ -703,7 +703,20 @@ module ApplicationTests _ = ActionMailer::Base - assert_equal [ActionMailer::Previews::InlineAttachments, MyPreviewMailInterceptor, MyOtherPreviewMailInterceptor], ActionMailer::Base.preview_interceptors + assert_equal [ActionMailer::InlinePreviewInterceptor, MyPreviewMailInterceptor, MyOtherPreviewMailInterceptor], ActionMailer::Base.preview_interceptors + end + + test "default preview interceptor can be removed" do + app_file 'config/initializers/preview_interceptors.rb', <<-RUBY + ActionMailer::Base.preview_interceptors.delete(ActionMailer::InlinePreviewInterceptor) + RUBY + + require "#{app_path}/config/environment" + require "mail" + + _ = ActionMailer::Base + + assert_equal [], ActionMailer::Base.preview_interceptors end test "registers observers with ActionMailer" do diff --git a/railties/test/application/mailer_previews_test.rb b/railties/test/application/mailer_previews_test.rb index 3c9de0115f..e462d2c15e 100644 --- a/railties/test/application/mailer_previews_test.rb +++ b/railties/test/application/mailer_previews_test.rb @@ -487,7 +487,7 @@ module ApplicationTests end test "plain text mailer preview with attachment" do - image_file "pixel.png", "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABAQMAAAAl21bKAAAAA1BMVEWzIioca_JlAAAACklEQVQI12NgAAAAAgAB4iG8MwAAAABJRU5ErkJgggo=" + image_file "pixel.png", "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABAQMAAAAl21bKAAAAA1BMVEWzIioca/JlAAAACklEQVQI12NgAAAAAgAB4iG8MwAAAABJRU5ErkJgggo=" mailer 'notifier', <<-RUBY class Notifier < ActionMailer::Base @@ -524,7 +524,7 @@ module ApplicationTests end test "multipart mailer preview with attachment" do - image_file "pixel.png", "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABAQMAAAAl21bKAAAAA1BMVEWzIioca_JlAAAACklEQVQI12NgAAAAAgAB4iG8MwAAAABJRU5ErkJgggo=" + image_file "pixel.png", "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABAQMAAAAl21bKAAAAA1BMVEWzIioca/JlAAAACklEQVQI12NgAAAAAgAB4iG8MwAAAABJRU5ErkJgggo=" mailer 'notifier', <<-RUBY class Notifier < ActionMailer::Base @@ -569,7 +569,7 @@ module ApplicationTests end test "multipart mailer preview with inline attachment" do - image_file "pixel.png", "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABAQMAAAAl21bKAAAAA1BMVEWzIioca_JlAAAACklEQVQI12NgAAAAAgAB4iG8MwAAAABJRU5ErkJgggo=" + image_file "pixel.png", "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABAQMAAAAl21bKAAAAA1BMVEWzIioca/JlAAAACklEQVQI12NgAAAAAgAB4iG8MwAAAABJRU5ErkJgggo=" mailer 'notifier', <<-RUBY class Notifier < ActionMailer::Base @@ -612,7 +612,7 @@ module ApplicationTests get "/rails/mailers/notifier/foo?part=text/html" assert_equal 200, last_response.status assert_match %r[

Hello, World!

], last_response.body - assert_match %r[src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABAQMAAAAl21bKAAAAA1BMVEWzIioca_JlAAAACklEQVQI12NgAAAAAgAB4iG8MwAAAABJRU5ErkJgggo="], last_response.body + assert_match %r[src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABAQMAAAAl21bKAAAAA1BMVEWzIioca/JlAAAACklEQVQI12NgAAAAAgAB4iG8MwAAAABJRU5ErkJgggo="], last_response.body end test "multipart mailer preview with attached email" do @@ -695,7 +695,7 @@ module ApplicationTests end def image_file(name, contents) - app_file("public/images/#{name}", Base64.urlsafe_decode64(contents), 'wb') + app_file("public/images/#{name}", Base64.strict_decode64(contents), 'wb') end end end -- cgit v1.2.3