diff options
Diffstat (limited to 'actionmailer')
-rw-r--r-- | actionmailer/CHANGELOG.md | 10 | ||||
-rw-r--r-- | actionmailer/README.rdoc | 4 | ||||
-rw-r--r-- | actionmailer/actionmailer.gemspec | 2 | ||||
-rw-r--r-- | actionmailer/lib/action_mailer/base.rb | 14 | ||||
-rw-r--r-- | actionmailer/lib/action_mailer/gem_version.rb | 2 | ||||
-rw-r--r-- | actionmailer/lib/action_mailer/log_subscriber.rb | 5 | ||||
-rw-r--r-- | actionmailer/lib/action_mailer/mail_delivery_job.rb | 2 | ||||
-rw-r--r-- | actionmailer/lib/action_mailer/railtie.rb | 16 | ||||
-rw-r--r-- | actionmailer/test/abstract_unit.rb | 2 | ||||
-rw-r--r-- | actionmailer/test/base_test.rb | 25 | ||||
-rw-r--r-- | actionmailer/test/caching_test.rb | 10 | ||||
-rw-r--r-- | actionmailer/test/fixtures/base_mailer/implicit_multipart_formats.html.erb | 1 | ||||
-rw-r--r-- | actionmailer/test/fixtures/base_mailer/implicit_multipart_formats.text.erb | 1 | ||||
-rw-r--r-- | actionmailer/test/log_subscriber_test.rb | 8 | ||||
-rw-r--r-- | actionmailer/test/mailers/base_mailer.rb | 8 |
15 files changed, 79 insertions, 31 deletions
diff --git a/actionmailer/CHANGELOG.md b/actionmailer/CHANGELOG.md index 806e428481..182c43551d 100644 --- a/actionmailer/CHANGELOG.md +++ b/actionmailer/CHANGELOG.md @@ -1,3 +1,13 @@ +## Rails 6.0.0.beta3 (March 11, 2019) ## + +* No changes. + + +## Rails 6.0.0.beta2 (February 25, 2019) ## + +* No changes. + + ## Rails 6.0.0.beta1 (January 18, 2019) ## * Deprecate `ActionMailer::Base.receive` in favor of [Action Mailbox](https://github.com/rails/rails/tree/master/actionmailbox). diff --git a/actionmailer/README.rdoc b/actionmailer/README.rdoc index 74d7ea65ce..0db4b2668b 100644 --- a/actionmailer/README.rdoc +++ b/actionmailer/README.rdoc @@ -13,6 +13,8 @@ Additionally, an Action Mailer class can be used to process incoming email, such as allowing a blog to accept new posts from an email (which could even have been sent from a phone). +You can read more about Action Mailer in the {Action Mailer Basics}[https://edgeguides.rubyonrails.org/action_mailer_basics.html] guide. + == Sending emails The framework works by initializing any instance variables you want to be @@ -128,7 +130,7 @@ Action Mailer is released under the MIT license: API documentation is at -* http://api.rubyonrails.org +* https://api.rubyonrails.org Bug reports for the Ruby on Rails project can be filed here: diff --git a/actionmailer/actionmailer.gemspec b/actionmailer/actionmailer.gemspec index c76cb3ec72..cadccb905b 100644 --- a/actionmailer/actionmailer.gemspec +++ b/actionmailer/actionmailer.gemspec @@ -15,7 +15,7 @@ Gem::Specification.new do |s| s.author = "David Heinemeier Hansson" s.email = "david@loudthinking.com" - s.homepage = "http://rubyonrails.org" + s.homepage = "https://rubyonrails.org" s.files = Dir["CHANGELOG.md", "README.rdoc", "MIT-LICENSE", "lib/**/*"] s.require_path = "lib" diff --git a/actionmailer/lib/action_mailer/base.rb b/actionmailer/lib/action_mailer/base.rb index 5610212fad..c1ac9c2ad1 100644 --- a/actionmailer/lib/action_mailer/base.rb +++ b/actionmailer/lib/action_mailer/base.rb @@ -593,6 +593,7 @@ module ActionMailer private def set_payload_for_mail(payload, mail) + payload[:mail] = mail.encoded payload[:mailer] = name payload[:message_id] = mail.message_id payload[:subject] = mail.subject @@ -601,7 +602,6 @@ module ActionMailer payload[:bcc] = mail.bcc if mail.bcc.present? payload[:cc] = mail.cc if mail.cc.present? payload[:date] = mail.date - payload[:mail] = mail.encoded payload[:perform_deliveries] = mail.perform_deliveries end @@ -944,9 +944,9 @@ module ActionMailer assignable.each { |k, v| message[k] = v } end - def collect_responses(headers) + def collect_responses(headers, &block) if block_given? - collect_responses_from_block(headers, &Proc.new) + collect_responses_from_block(headers, &block) elsif headers[:body] collect_responses_from_text(headers) else @@ -973,10 +973,10 @@ module ActionMailer templates_name = headers[:template_name] || action_name each_template(Array(templates_path), templates_name).map do |template| - self.formats = template.formats + format = template.format || self.formats.first { - body: render(template: template), - content_type: template.type.to_s + body: render(template: template, formats: [format]), + content_type: Mime[format].to_s } end end @@ -986,7 +986,7 @@ module ActionMailer if templates.empty? raise ActionView::MissingTemplate.new(paths, name, paths, false, "mailer") else - templates.uniq(&:formats).each(&block) + templates.uniq(&:format).each(&block) end end diff --git a/actionmailer/lib/action_mailer/gem_version.rb b/actionmailer/lib/action_mailer/gem_version.rb index 4cab52d1f3..4efcd966db 100644 --- a/actionmailer/lib/action_mailer/gem_version.rb +++ b/actionmailer/lib/action_mailer/gem_version.rb @@ -10,7 +10,7 @@ module ActionMailer MAJOR = 6 MINOR = 0 TINY = 0 - PRE = "beta1" + PRE = "beta3" STRING = [MAJOR, MINOR, TINY, PRE].compact.join(".") end diff --git a/actionmailer/lib/action_mailer/log_subscriber.rb b/actionmailer/lib/action_mailer/log_subscriber.rb index 25c99342c2..26910f20f0 100644 --- a/actionmailer/lib/action_mailer/log_subscriber.rb +++ b/actionmailer/lib/action_mailer/log_subscriber.rb @@ -10,11 +10,10 @@ module ActionMailer def deliver(event) info do perform_deliveries = event.payload[:perform_deliveries] - recipients = Array(event.payload[:to]).join(", ") if perform_deliveries - "Sent mail to #{recipients} (#{event.duration.round(1)}ms)" + "Delivered mail #{event.payload[:message_id]} (#{event.duration.round(1)}ms)" else - "Skipped sending mail to #{recipients} as `perform_deliveries` is false" + "Skipped delivery of mail #{event.payload[:message_id]} as `perform_deliveries` is false" end end diff --git a/actionmailer/lib/action_mailer/mail_delivery_job.rb b/actionmailer/lib/action_mailer/mail_delivery_job.rb index 93778edfce..609c6a72d9 100644 --- a/actionmailer/lib/action_mailer/mail_delivery_job.rb +++ b/actionmailer/lib/action_mailer/mail_delivery_job.rb @@ -3,7 +3,7 @@ require "active_job" module ActionMailer - # The <tt>ActionMailer::NewDeliveryJob</tt> class is used when you + # The <tt>ActionMailer::MailDeliveryJob</tt> class is used when you # want to send emails outside of the request-response cycle. It supports # sending either parameterized or normal mail. # diff --git a/actionmailer/lib/action_mailer/railtie.rb b/actionmailer/lib/action_mailer/railtie.rb index 23488db790..893a4a25b1 100644 --- a/actionmailer/lib/action_mailer/railtie.rb +++ b/actionmailer/lib/action_mailer/railtie.rb @@ -59,6 +59,14 @@ module ActionMailer end end + initializer "action_mailer.set_autoload_paths" do |app| + options = app.config.action_mailer + + if options.show_previews && options.preview_path + ActiveSupport::Dependencies.autoload_paths << options.preview_path + end + end + initializer "action_mailer.compile_config_methods" do ActiveSupport.on_load(:action_mailer) do config.compile_methods! if config.respond_to?(:compile_methods!) @@ -76,12 +84,8 @@ module ActionMailer if options.show_previews app.routes.prepend do - get "/rails/mailers" => "rails/mailers#index", internal: true - get "/rails/mailers/*path" => "rails/mailers#preview", internal: true - end - - if options.preview_path - ActiveSupport::Dependencies.autoload_paths << options.preview_path + get "/rails/mailers" => "rails/mailers#index", internal: true + get "/rails/mailers/*path" => "rails/mailers#preview", internal: true end end end diff --git a/actionmailer/test/abstract_unit.rb b/actionmailer/test/abstract_unit.rb index 448807c144..a2a603834c 100644 --- a/actionmailer/test/abstract_unit.rb +++ b/actionmailer/test/abstract_unit.rb @@ -49,3 +49,5 @@ class ActiveSupport::TestCase skip message if defined?(JRUBY_VERSION) end end + +require_relative "../../tools/test_common" diff --git a/actionmailer/test/base_test.rb b/actionmailer/test/base_test.rb index d0c4f189fd..c07fca5b5e 100644 --- a/actionmailer/test/base_test.rb +++ b/actionmailer/test/base_test.rb @@ -307,6 +307,16 @@ class BaseTest < ActiveSupport::TestCase assert_equal("HTML Implicit Multipart", email.parts[1].body.encoded) end + test "implicit multipart formats" do + email = BaseMailer.implicit_multipart_formats + assert_equal(2, email.parts.size) + assert_equal("multipart/alternative", email.mime_type) + assert_equal("text/plain", email.parts[0].mime_type) + assert_equal("Implicit Multipart [:text]", email.parts[0].body.encoded) + assert_equal("text/html", email.parts[1].mime_type) + assert_equal("Implicit Multipart [:html]", email.parts[1].body.encoded) + end + test "implicit multipart with sort order" do order = ["text/html", "text/plain"] with_default BaseMailer, parts_order: order do @@ -913,6 +923,21 @@ class BaseTest < ActiveSupport::TestCase ActiveSupport::Notifications.unsubscribe "process.action_mailer" end + test "notification for deliver" do + events = [] + ActiveSupport::Notifications.subscribe("deliver.action_mailer") do |*args| + events << ActiveSupport::Notifications::Event.new(*args) + end + + BaseMailer.welcome(body: "Hello there").deliver_now + + assert_equal 1, events.length + assert_equal "deliver.action_mailer", events[0].name + assert_not_nil events[0].payload[:message_id] + ensure + ActiveSupport::Notifications.unsubscribe "deliver.action_mailer" + end + private # Execute the block setting the given values and restoring old values after diff --git a/actionmailer/test/caching_test.rb b/actionmailer/test/caching_test.rb index 22f310f39f..b658c96ec7 100644 --- a/actionmailer/test/caching_test.rb +++ b/actionmailer/test/caching_test.rb @@ -124,7 +124,7 @@ class FunctionalFragmentCachingTest < BaseCachingTest assert_match expected_body, email.body.encoded assert_match expected_body, - @store.read("views/caching_mailer/fragment_cache:#{template_digest("caching_mailer/fragment_cache")}/caching") + @store.read("views/caching_mailer/fragment_cache:#{template_digest("caching_mailer/fragment_cache", "html")}/caching") end def test_fragment_caching_in_partials @@ -133,7 +133,7 @@ class FunctionalFragmentCachingTest < BaseCachingTest assert_match(expected_body, email.body.encoded) assert_match(expected_body, - @store.read("views/caching_mailer/_partial:#{template_digest("caching_mailer/_partial")}/caching")) + @store.read("views/caching_mailer/_partial:#{template_digest("caching_mailer/_partial", "html")}/caching")) end def test_skip_fragment_cache_digesting @@ -183,15 +183,15 @@ class FunctionalFragmentCachingTest < BaseCachingTest end assert_equal "caching_mailer", payload[:mailer] - assert_equal [ :views, "caching_mailer/fragment_cache:#{template_digest("caching_mailer/fragment_cache")}", :caching ], payload[:key] + assert_equal [ :views, "caching_mailer/fragment_cache:#{template_digest("caching_mailer/fragment_cache", "html")}", :caching ], payload[:key] ensure @mailer.enable_fragment_cache_logging = true end private - def template_digest(name) - ActionView::Digestor.digest(name: name, finder: @mailer.lookup_context) + def template_digest(name, format) + ActionView::Digestor.digest(name: name, format: format, finder: @mailer.lookup_context) end end diff --git a/actionmailer/test/fixtures/base_mailer/implicit_multipart_formats.html.erb b/actionmailer/test/fixtures/base_mailer/implicit_multipart_formats.html.erb new file mode 100644 index 0000000000..0179b070b8 --- /dev/null +++ b/actionmailer/test/fixtures/base_mailer/implicit_multipart_formats.html.erb @@ -0,0 +1 @@ +Implicit Multipart <%= formats.inspect %>
\ No newline at end of file diff --git a/actionmailer/test/fixtures/base_mailer/implicit_multipart_formats.text.erb b/actionmailer/test/fixtures/base_mailer/implicit_multipart_formats.text.erb new file mode 100644 index 0000000000..0179b070b8 --- /dev/null +++ b/actionmailer/test/fixtures/base_mailer/implicit_multipart_formats.text.erb @@ -0,0 +1 @@ +Implicit Multipart <%= formats.inspect %>
\ No newline at end of file diff --git a/actionmailer/test/log_subscriber_test.rb b/actionmailer/test/log_subscriber_test.rb index fb569ce45f..f09f1997c0 100644 --- a/actionmailer/test/log_subscriber_test.rb +++ b/actionmailer/test/log_subscriber_test.rb @@ -24,11 +24,11 @@ class AMLogSubscriberTest < ActionMailer::TestCase end def test_deliver_is_notified - BaseMailer.welcome.deliver_now + BaseMailer.welcome(message_id: "123@abc").deliver_now wait assert_equal(1, @logger.logged(:info).size) - assert_match(/Sent mail to system@test\.lindsaar\.net/, @logger.logged(:info).first) + assert_match(/Delivered mail 123@abc/, @logger.logged(:info).first) assert_equal(2, @logger.logged(:debug).size) assert_match(/BaseMailer#welcome: processed outbound mail in [\d.]+ms/, @logger.logged(:debug).first) @@ -38,11 +38,11 @@ class AMLogSubscriberTest < ActionMailer::TestCase end def test_deliver_message_when_perform_deliveries_is_false - BaseMailer.welcome_without_deliveries.deliver_now + BaseMailer.welcome_without_deliveries(message_id: "123@abc").deliver_now wait assert_equal(1, @logger.logged(:info).size) - assert_match("Skipped sending mail to system@test.lindsaar.net as `perform_deliveries` is false", @logger.logged(:info).first) + assert_match("Skipped delivery of mail 123@abc as `perform_deliveries` is false", @logger.logged(:info).first) assert_equal(2, @logger.logged(:debug).size) assert_match(/BaseMailer#welcome_without_deliveries: processed outbound mail in [\d.]+ms/, @logger.logged(:debug).first) diff --git a/actionmailer/test/mailers/base_mailer.rb b/actionmailer/test/mailers/base_mailer.rb index c1bb48cc96..6bd58304e2 100644 --- a/actionmailer/test/mailers/base_mailer.rb +++ b/actionmailer/test/mailers/base_mailer.rb @@ -21,8 +21,8 @@ class BaseMailer < ActionMailer::Base mail(template_name: "welcome", template_path: path) end - def welcome_without_deliveries - mail(template_name: "welcome") + def welcome_without_deliveries(hash = {}) + mail({ template_name: "welcome" }.merge!(hash)) mail.perform_deliveries = false end @@ -62,6 +62,10 @@ class BaseMailer < ActionMailer::Base mail(hash) end + def implicit_multipart_formats(hash = {}) + mail(hash) + end + def implicit_with_locale(hash = {}) mail(hash) end |