actionmailer 5.2.8.1 → 6.0.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of actionmailer might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/CHANGELOG.md +41 -104
- data/MIT-LICENSE +1 -1
- data/README.rdoc +1 -37
- data/lib/action_mailer/base.rb +48 -13
- data/lib/action_mailer/delivery_job.rb +8 -0
- data/lib/action_mailer/gem_version.rb +4 -4
- data/lib/action_mailer/inline_preview_interceptor.rb +1 -3
- data/lib/action_mailer/log_subscriber.rb +6 -1
- data/lib/action_mailer/mail_delivery_job.rb +38 -0
- data/lib/action_mailer/message_delivery.rb +10 -2
- data/lib/action_mailer/parameterized.rb +24 -7
- data/lib/action_mailer/preview.rb +22 -5
- data/lib/action_mailer/railtie.rb +8 -1
- data/lib/action_mailer/test_helper.rb +32 -14
- data/lib/action_mailer.rb +2 -1
- data/lib/rails/generators/mailer/mailer_generator.rb +1 -1
- metadata +21 -20
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: af732a129a02cc2ac2022d963b5055006049a660083fb9eb28de69d31fc01fad
|
4
|
+
data.tar.gz: 994f198cf6a06cbac0a0f920753a30160965bc762470153a928671ef1262a2fa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0ba45855596c9f3d4b88203a88788036f2b24129e9fd71ab22b323e461d6542f8d262dcf4b036c063c1dd781d3dcbc7355b9d71801cc31dd07a41839f17de2df
|
7
|
+
data.tar.gz: 3eb85af6dd23fb37d69cb3771ed118573a78fab9941bd94012bd2058a29eef507592ac29460f971dfc75b5e3b29117ce1f2179c5f4d54c1ff65ec2fe6768672e
|
data/CHANGELOG.md
CHANGED
@@ -1,134 +1,71 @@
|
|
1
|
-
## Rails
|
1
|
+
## Rails 6.0.0.beta1 (January 18, 2019) ##
|
2
2
|
|
3
|
-
*
|
3
|
+
* Deprecate `ActionMailer::Base.receive` in favor of [Action Mailbox](https://github.com/rails/rails/tree/master/actionmailbox).
|
4
4
|
|
5
|
+
*George Claghorn*
|
5
6
|
|
6
|
-
|
7
|
+
* Add `MailDeliveryJob` for delivering both regular and parameterized mail. Deprecate using `DeliveryJob` and `Parameterized::DeliveryJob`.
|
7
8
|
|
8
|
-
*
|
9
|
+
*Gannon McGibbon*
|
9
10
|
|
11
|
+
* Fix ActionMailer assertions not working when a Mail defines
|
12
|
+
a custom delivery job class
|
10
13
|
|
11
|
-
|
14
|
+
*Edouard Chin*
|
12
15
|
|
13
|
-
*
|
16
|
+
* Mails with multipart `format` blocks with implicit render now also check for
|
17
|
+
a template name in options hash instead of only using the action name.
|
14
18
|
|
19
|
+
*Marcus Ilgner*
|
15
20
|
|
16
|
-
|
21
|
+
* `ActionDispatch::IntegrationTest` includes `ActionMailer::TestHelper` module by default.
|
17
22
|
|
18
|
-
*
|
23
|
+
*Ricardo Díaz*
|
19
24
|
|
25
|
+
* Add `perform_deliveries` to a payload of `deliver.action_mailer` notification.
|
20
26
|
|
21
|
-
|
27
|
+
*Yoshiyuki Kinjo*
|
22
28
|
|
23
|
-
*
|
29
|
+
* Change delivery logging message when `perform_deliveries` is false.
|
24
30
|
|
31
|
+
*Yoshiyuki Kinjo*
|
25
32
|
|
26
|
-
|
33
|
+
* Allow call `assert_enqueued_email_with` with no block.
|
27
34
|
|
28
|
-
|
35
|
+
Example:
|
36
|
+
```
|
37
|
+
def test_email
|
38
|
+
ContactMailer.welcome.deliver_later
|
39
|
+
assert_enqueued_email_with ContactMailer, :welcome
|
40
|
+
end
|
29
41
|
|
42
|
+
def test_email_with_arguments
|
43
|
+
ContactMailer.welcome("Hello", "Goodbye").deliver_later
|
44
|
+
assert_enqueued_email_with ContactMailer, :welcome, args: ["Hello", "Goodbye"]
|
45
|
+
end
|
46
|
+
```
|
30
47
|
|
31
|
-
|
32
|
-
|
33
|
-
* No changes.
|
34
|
-
|
35
|
-
|
36
|
-
## Rails 5.2.6 (May 05, 2021) ##
|
37
|
-
|
38
|
-
* No changes.
|
39
|
-
|
40
|
-
|
41
|
-
## Rails 5.2.5 (March 26, 2021) ##
|
42
|
-
|
43
|
-
* No changes.
|
44
|
-
|
45
|
-
|
46
|
-
## Rails 5.2.4.6 (May 05, 2021) ##
|
47
|
-
|
48
|
-
* No changes.
|
49
|
-
|
50
|
-
|
51
|
-
## Rails 5.2.4.5 (February 10, 2021) ##
|
52
|
-
|
53
|
-
* No changes.
|
54
|
-
|
55
|
-
|
56
|
-
## Rails 5.2.4.4 (September 09, 2020) ##
|
57
|
-
|
58
|
-
* No changes.
|
59
|
-
|
60
|
-
|
61
|
-
## Rails 5.2.4.3 (May 18, 2020) ##
|
62
|
-
|
63
|
-
* No changes.
|
64
|
-
|
65
|
-
|
66
|
-
## Rails 5.2.4.2 (March 19, 2020) ##
|
67
|
-
|
68
|
-
* No changes.
|
69
|
-
|
70
|
-
|
71
|
-
## Rails 5.2.4.1 (December 18, 2019) ##
|
72
|
-
|
73
|
-
* No changes.
|
74
|
-
|
75
|
-
|
76
|
-
## Rails 5.2.4 (November 27, 2019) ##
|
77
|
-
|
78
|
-
* No changes.
|
79
|
-
|
80
|
-
|
81
|
-
## Rails 5.2.3 (March 27, 2019) ##
|
82
|
-
|
83
|
-
* No changes.
|
84
|
-
|
85
|
-
|
86
|
-
## Rails 5.2.2.1 (March 11, 2019) ##
|
87
|
-
|
88
|
-
* No changes.
|
89
|
-
|
90
|
-
|
91
|
-
## Rails 5.2.2 (December 04, 2018) ##
|
92
|
-
|
93
|
-
* No changes.
|
94
|
-
|
95
|
-
|
96
|
-
## Rails 5.2.1.1 (November 27, 2018) ##
|
97
|
-
|
98
|
-
* No changes.
|
99
|
-
|
100
|
-
|
101
|
-
## Rails 5.2.1 (August 07, 2018) ##
|
48
|
+
*bogdanvlviv*
|
102
49
|
|
103
50
|
* Ensure mail gem is eager autoloaded when eager load is true to prevent thread deadlocks.
|
104
51
|
|
105
52
|
*Samuel Cochran*
|
106
53
|
|
54
|
+
* Perform email jobs in `assert_emails`.
|
107
55
|
|
108
|
-
|
109
|
-
|
110
|
-
* Bring back proc with arity of 1 in `ActionMailer::Base.default` proc
|
111
|
-
since it was supported in Rails 5.0 but not deprecated.
|
112
|
-
|
113
|
-
*Jimmy Bourassa*
|
114
|
-
|
115
|
-
* Add `assert_enqueued_email_with` test helper.
|
116
|
-
|
117
|
-
assert_enqueued_email_with ContactMailer, :welcome do
|
118
|
-
ContactMailer.welcome.deliver_later
|
119
|
-
end
|
120
|
-
|
121
|
-
*Mikkel Malmberg*
|
56
|
+
*Gannon McGibbon*
|
122
57
|
|
123
|
-
*
|
58
|
+
* Add `Base.unregister_observer`, `Base.unregister_observers`,
|
59
|
+
`Base.unregister_interceptor`, `Base.unregister_interceptors`,
|
60
|
+
`Base.unregister_preview_interceptor` and `Base.unregister_preview_interceptors`.
|
61
|
+
This makes it possible to dynamically add and remove email observers and
|
62
|
+
interceptors at runtime in the same way they're registered.
|
124
63
|
|
125
|
-
|
126
|
-
self.delivery_job = MyCustomDeliveryJob
|
64
|
+
*Claudio Ortolina*, *Kota Miyake*
|
127
65
|
|
128
|
-
|
129
|
-
end
|
66
|
+
* Rails 6 requires Ruby 2.5.0 or newer.
|
130
67
|
|
131
|
-
*
|
68
|
+
*Jeremy Daer*, *Kasper Timm Hansen*
|
132
69
|
|
133
70
|
|
134
|
-
Please check [5-
|
71
|
+
Please check [5-2-stable](https://github.com/rails/rails/blob/5-2-stable/actionmailer/CHANGELOG.md) for previous changes.
|
data/MIT-LICENSE
CHANGED
data/README.rdoc
CHANGED
@@ -93,42 +93,6 @@ Example:
|
|
93
93
|
.....
|
94
94
|
end
|
95
95
|
|
96
|
-
== Receiving emails
|
97
|
-
|
98
|
-
To receive emails, you need to implement a public instance method called
|
99
|
-
+receive+ that takes an email object as its single parameter. The Action Mailer
|
100
|
-
framework has a corresponding class method, which is also called +receive+, that
|
101
|
-
accepts a raw, unprocessed email as a string, which it then turns into the email
|
102
|
-
object and calls the receive instance method.
|
103
|
-
|
104
|
-
Example:
|
105
|
-
|
106
|
-
class Mailman < ActionMailer::Base
|
107
|
-
def receive(email)
|
108
|
-
page = Page.find_by(address: email.to.first)
|
109
|
-
page.emails.create(
|
110
|
-
subject: email.subject, body: email.body
|
111
|
-
)
|
112
|
-
|
113
|
-
if email.has_attachments?
|
114
|
-
email.attachments.each do |attachment|
|
115
|
-
page.attachments.create({
|
116
|
-
file: attachment, description: email.subject
|
117
|
-
})
|
118
|
-
end
|
119
|
-
end
|
120
|
-
end
|
121
|
-
end
|
122
|
-
|
123
|
-
This Mailman can be the target for Postfix or other MTAs. In Rails, you would use
|
124
|
-
the runner in the trivial case like this:
|
125
|
-
|
126
|
-
rails runner 'Mailman.receive(STDIN.read)'
|
127
|
-
|
128
|
-
However, invoking Rails in the runner for each mail to be received is very
|
129
|
-
resource intensive. A single instance of Rails should be run within a daemon, if
|
130
|
-
it is going to process more than just a limited amount of email.
|
131
|
-
|
132
96
|
== Configuration
|
133
97
|
|
134
98
|
The Base class has the full list of configuration options. Here's an example:
|
@@ -150,7 +114,7 @@ The latest version of Action Mailer can be installed with RubyGems:
|
|
150
114
|
|
151
115
|
Source code can be downloaded as part of the Rails project on GitHub:
|
152
116
|
|
153
|
-
* https://github.com/rails/rails/tree/
|
117
|
+
* https://github.com/rails/rails/tree/master/actionmailer
|
154
118
|
|
155
119
|
|
156
120
|
== License
|
data/lib/action_mailer/base.rb
CHANGED
@@ -475,11 +475,21 @@ module ActionMailer
|
|
475
475
|
observers.flatten.compact.each { |observer| register_observer(observer) }
|
476
476
|
end
|
477
477
|
|
478
|
+
# Unregister one or more previously registered Observers.
|
479
|
+
def unregister_observers(*observers)
|
480
|
+
observers.flatten.compact.each { |observer| unregister_observer(observer) }
|
481
|
+
end
|
482
|
+
|
478
483
|
# Register one or more Interceptors which will be called before mail is sent.
|
479
484
|
def register_interceptors(*interceptors)
|
480
485
|
interceptors.flatten.compact.each { |interceptor| register_interceptor(interceptor) }
|
481
486
|
end
|
482
487
|
|
488
|
+
# Unregister one or more previously registered Interceptors.
|
489
|
+
def unregister_interceptors(*interceptors)
|
490
|
+
interceptors.flatten.compact.each { |interceptor| unregister_interceptor(interceptor) }
|
491
|
+
end
|
492
|
+
|
483
493
|
# Register an Observer which will be notified when mail is delivered.
|
484
494
|
# Either a class, string or symbol can be passed in as the Observer.
|
485
495
|
# If a string or symbol is passed in it will be camelized and constantized.
|
@@ -487,6 +497,13 @@ module ActionMailer
|
|
487
497
|
Mail.register_observer(observer_class_for(observer))
|
488
498
|
end
|
489
499
|
|
500
|
+
# Unregister a previously registered Observer.
|
501
|
+
# Either a class, string or symbol can be passed in as the Observer.
|
502
|
+
# If a string or symbol is passed in it will be camelized and constantized.
|
503
|
+
def unregister_observer(observer)
|
504
|
+
Mail.unregister_observer(observer_class_for(observer))
|
505
|
+
end
|
506
|
+
|
490
507
|
# Register an Interceptor which will be called before mail is sent.
|
491
508
|
# Either a class, string or symbol can be passed in as the Interceptor.
|
492
509
|
# If a string or symbol is passed in it will be camelized and constantized.
|
@@ -494,6 +511,13 @@ module ActionMailer
|
|
494
511
|
Mail.register_interceptor(observer_class_for(interceptor))
|
495
512
|
end
|
496
513
|
|
514
|
+
# Unregister a previously registered Interceptor.
|
515
|
+
# Either a class, string or symbol can be passed in as the Interceptor.
|
516
|
+
# If a string or symbol is passed in it will be camelized and constantized.
|
517
|
+
def unregister_interceptor(interceptor)
|
518
|
+
Mail.unregister_interceptor(observer_class_for(interceptor))
|
519
|
+
end
|
520
|
+
|
497
521
|
def observer_class_for(value) # :nodoc:
|
498
522
|
case value
|
499
523
|
when String, Symbol
|
@@ -541,6 +565,11 @@ module ActionMailer
|
|
541
565
|
# end
|
542
566
|
# end
|
543
567
|
def receive(raw_mail)
|
568
|
+
ActiveSupport::Deprecation.warn(<<~MESSAGE.squish)
|
569
|
+
ActionMailer::Base.receive is deprecated and will be removed in Rails 6.1.
|
570
|
+
Use Action Mailbox to process inbound email.
|
571
|
+
MESSAGE
|
572
|
+
|
544
573
|
ActiveSupport::Notifications.instrument("receive.action_mailer") do |payload|
|
545
574
|
mail = Mail.new(raw_mail)
|
546
575
|
set_payload_for_mail(payload, mail)
|
@@ -564,15 +593,16 @@ module ActionMailer
|
|
564
593
|
private
|
565
594
|
|
566
595
|
def set_payload_for_mail(payload, mail)
|
567
|
-
payload[:mailer]
|
568
|
-
payload[:message_id]
|
569
|
-
payload[:subject]
|
570
|
-
payload[:to]
|
571
|
-
payload[:from]
|
572
|
-
payload[:bcc]
|
573
|
-
payload[:cc]
|
574
|
-
payload[:date]
|
575
|
-
payload[:mail]
|
596
|
+
payload[:mailer] = name
|
597
|
+
payload[:message_id] = mail.message_id
|
598
|
+
payload[:subject] = mail.subject
|
599
|
+
payload[:to] = mail.to
|
600
|
+
payload[:from] = mail.from
|
601
|
+
payload[:bcc] = mail.bcc if mail.bcc.present?
|
602
|
+
payload[:cc] = mail.cc if mail.cc.present?
|
603
|
+
payload[:date] = mail.date
|
604
|
+
payload[:mail] = mail.encoded
|
605
|
+
payload[:perform_deliveries] = mail.perform_deliveries
|
576
606
|
end
|
577
607
|
|
578
608
|
def method_missing(method_name, *args)
|
@@ -916,9 +946,7 @@ module ActionMailer
|
|
916
946
|
|
917
947
|
def collect_responses(headers)
|
918
948
|
if block_given?
|
919
|
-
|
920
|
-
yield(collector)
|
921
|
-
collector.responses
|
949
|
+
collect_responses_from_block(headers, &Proc.new)
|
922
950
|
elsif headers[:body]
|
923
951
|
collect_responses_from_text(headers)
|
924
952
|
else
|
@@ -926,6 +954,13 @@ module ActionMailer
|
|
926
954
|
end
|
927
955
|
end
|
928
956
|
|
957
|
+
def collect_responses_from_block(headers)
|
958
|
+
templates_name = headers[:template_name] || action_name
|
959
|
+
collector = ActionMailer::Collector.new(lookup_context) { render(templates_name) }
|
960
|
+
yield(collector)
|
961
|
+
collector.responses
|
962
|
+
end
|
963
|
+
|
929
964
|
def collect_responses_from_text(headers)
|
930
965
|
[{
|
931
966
|
body: headers.delete(:body),
|
@@ -983,7 +1018,7 @@ module ActionMailer
|
|
983
1018
|
end
|
984
1019
|
|
985
1020
|
def instrument_name
|
986
|
-
"action_mailer"
|
1021
|
+
"action_mailer"
|
987
1022
|
end
|
988
1023
|
|
989
1024
|
ActiveSupport.run_load_hooks(:action_mailer, self)
|
@@ -12,6 +12,14 @@ module ActionMailer
|
|
12
12
|
|
13
13
|
rescue_from StandardError, with: :handle_exception_with_mailer_class
|
14
14
|
|
15
|
+
before_perform do
|
16
|
+
ActiveSupport::Deprecation.warn <<~MSG.squish
|
17
|
+
Sending mail with DeliveryJob and Parameterized::DeliveryJob
|
18
|
+
is deprecated and will be removed in Rails 6.1.
|
19
|
+
Please use MailDeliveryJob instead.
|
20
|
+
MSG
|
21
|
+
end
|
22
|
+
|
15
23
|
def perform(mailer, mail_method, delivery_method, *args) #:nodoc:
|
16
24
|
mailer.constantize.public_send(mail_method, *args).send(delivery_method)
|
17
25
|
end
|
@@ -9,8 +9,13 @@ module ActionMailer
|
|
9
9
|
# An email was delivered.
|
10
10
|
def deliver(event)
|
11
11
|
info do
|
12
|
+
perform_deliveries = event.payload[:perform_deliveries]
|
12
13
|
recipients = Array(event.payload[:to]).join(", ")
|
13
|
-
|
14
|
+
if perform_deliveries
|
15
|
+
"Sent mail to #{recipients} (#{event.duration.round(1)}ms)"
|
16
|
+
else
|
17
|
+
"Skipped sending mail to #{recipients} as `perform_deliveries` is false"
|
18
|
+
end
|
14
19
|
end
|
15
20
|
|
16
21
|
debug { event.payload[:mail] }
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "active_job"
|
4
|
+
|
5
|
+
module ActionMailer
|
6
|
+
# The <tt>ActionMailer::NewDeliveryJob</tt> class is used when you
|
7
|
+
# want to send emails outside of the request-response cycle. It supports
|
8
|
+
# sending either parameterized or normal mail.
|
9
|
+
#
|
10
|
+
# Exceptions are rescued and handled by the mailer class.
|
11
|
+
class MailDeliveryJob < ActiveJob::Base # :nodoc:
|
12
|
+
queue_as { ActionMailer::Base.deliver_later_queue_name }
|
13
|
+
|
14
|
+
rescue_from StandardError, with: :handle_exception_with_mailer_class
|
15
|
+
|
16
|
+
def perform(mailer, mail_method, delivery_method, args:, params: nil) #:nodoc:
|
17
|
+
mailer_class = params ? mailer.constantize.with(params) : mailer.constantize
|
18
|
+
mailer_class.public_send(mail_method, *args).send(delivery_method)
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
# "Deserialize" the mailer class name by hand in case another argument
|
23
|
+
# (like a Global ID reference) raised DeserializationError.
|
24
|
+
def mailer_class
|
25
|
+
if mailer = Array(@serialized_arguments).first || Array(arguments).first
|
26
|
+
mailer.constantize
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def handle_exception_with_mailer_class(exception)
|
31
|
+
if klass = mailer_class
|
32
|
+
klass.handle_exception exception
|
33
|
+
else
|
34
|
+
raise exception
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -29,7 +29,7 @@ module ActionMailer
|
|
29
29
|
@mail_message ||= processed_mailer.message
|
30
30
|
end
|
31
31
|
|
32
|
-
# Unused except for delegator internals (dup,
|
32
|
+
# Unused except for delegator internals (dup, marshalling).
|
33
33
|
def __setobj__(mail_message) #:nodoc:
|
34
34
|
@mail_message = mail_message
|
35
35
|
end
|
@@ -135,10 +135,18 @@ module ActionMailer
|
|
135
135
|
"#deliver_later, 2. only touch the message *within your mailer " \
|
136
136
|
"method*, or 3. use a custom Active Job instead of #deliver_later."
|
137
137
|
else
|
138
|
-
args = @mailer_class.name, @action.to_s, delivery_method.to_s, *@args
|
139
138
|
job = @mailer_class.delivery_job
|
139
|
+
args = arguments_for(job, delivery_method)
|
140
140
|
job.set(options).perform_later(*args)
|
141
141
|
end
|
142
142
|
end
|
143
|
+
|
144
|
+
def arguments_for(delivery_job, delivery_method)
|
145
|
+
if delivery_job <= MailDeliveryJob
|
146
|
+
[@mailer_class.name, @action.to_s, delivery_method.to_s, args: @args]
|
147
|
+
else
|
148
|
+
[@mailer_class.name, @action.to_s, delivery_method.to_s, *@args]
|
149
|
+
end
|
150
|
+
end
|
143
151
|
end
|
144
152
|
end
|
@@ -121,6 +121,12 @@ module ActionMailer
|
|
121
121
|
end
|
122
122
|
end
|
123
123
|
|
124
|
+
class DeliveryJob < ActionMailer::DeliveryJob # :nodoc:
|
125
|
+
def perform(mailer, mail_method, delivery_method, params, *args)
|
126
|
+
mailer.constantize.with(params).public_send(mail_method, *args).send(delivery_method)
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
124
130
|
class MessageDelivery < ActionMailer::MessageDelivery # :nodoc:
|
125
131
|
def initialize(mailer_class, action, params, *args)
|
126
132
|
super(mailer_class, action, *args)
|
@@ -139,16 +145,27 @@ module ActionMailer
|
|
139
145
|
if processed?
|
140
146
|
super
|
141
147
|
else
|
142
|
-
|
143
|
-
|
148
|
+
job = delivery_job_class
|
149
|
+
args = arguments_for(job, delivery_method)
|
150
|
+
job.set(options).perform_later(*args)
|
144
151
|
end
|
145
152
|
end
|
146
|
-
end
|
147
153
|
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
154
|
+
def delivery_job_class
|
155
|
+
if @mailer_class.delivery_job <= MailDeliveryJob
|
156
|
+
@mailer_class.delivery_job
|
157
|
+
else
|
158
|
+
Parameterized::DeliveryJob
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
162
|
+
def arguments_for(delivery_job, delivery_method)
|
163
|
+
if delivery_job <= MailDeliveryJob
|
164
|
+
[@mailer_class.name, @action.to_s, delivery_method.to_s, params: @params, args: @args]
|
165
|
+
else
|
166
|
+
[@mailer_class.name, @action.to_s, delivery_method.to_s, @params, *@args]
|
167
|
+
end
|
168
|
+
end
|
152
169
|
end
|
153
170
|
end
|
154
171
|
end
|
@@ -31,22 +31,39 @@ module ActionMailer
|
|
31
31
|
interceptors.flatten.compact.each { |interceptor| register_preview_interceptor(interceptor) }
|
32
32
|
end
|
33
33
|
|
34
|
+
# Unregister one or more previously registered Interceptors.
|
35
|
+
def unregister_preview_interceptors(*interceptors)
|
36
|
+
interceptors.flatten.compact.each { |interceptor| unregister_preview_interceptor(interceptor) }
|
37
|
+
end
|
38
|
+
|
34
39
|
# Register an Interceptor which will be called before mail is previewed.
|
35
40
|
# Either a class or a string can be passed in as the Interceptor. If a
|
36
41
|
# string is passed in it will be constantized.
|
37
42
|
def register_preview_interceptor(interceptor)
|
38
|
-
preview_interceptor =
|
43
|
+
preview_interceptor = interceptor_class_for(interceptor)
|
44
|
+
|
45
|
+
unless preview_interceptors.include?(preview_interceptor)
|
46
|
+
preview_interceptors << preview_interceptor
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
# Unregister a previously registered Interceptor.
|
51
|
+
# Either a class or a string can be passed in as the Interceptor. If a
|
52
|
+
# string is passed in it will be constantized.
|
53
|
+
def unregister_preview_interceptor(interceptor)
|
54
|
+
preview_interceptors.delete(interceptor_class_for(interceptor))
|
55
|
+
end
|
56
|
+
|
57
|
+
private
|
58
|
+
|
59
|
+
def interceptor_class_for(interceptor)
|
39
60
|
case interceptor
|
40
61
|
when String, Symbol
|
41
62
|
interceptor.to_s.camelize.constantize
|
42
63
|
else
|
43
64
|
interceptor
|
44
65
|
end
|
45
|
-
|
46
|
-
unless preview_interceptors.include?(preview_interceptor)
|
47
|
-
preview_interceptors << preview_interceptor
|
48
66
|
end
|
49
|
-
end
|
50
67
|
end
|
51
68
|
end
|
52
69
|
|
@@ -46,10 +46,17 @@ module ActionMailer
|
|
46
46
|
register_preview_interceptors(options.delete(:preview_interceptors))
|
47
47
|
register_observers(options.delete(:observers))
|
48
48
|
|
49
|
+
if delivery_job = options.delete(:delivery_job)
|
50
|
+
self.delivery_job = delivery_job.constantize
|
51
|
+
end
|
52
|
+
|
49
53
|
options.each { |k, v| send("#{k}=", v) }
|
50
54
|
end
|
51
55
|
|
52
|
-
ActiveSupport.on_load(:action_dispatch_integration_test)
|
56
|
+
ActiveSupport.on_load(:action_dispatch_integration_test) do
|
57
|
+
include ActionMailer::TestHelper
|
58
|
+
include ActionMailer::TestCase::ClearTestDeliveries
|
59
|
+
end
|
53
60
|
end
|
54
61
|
|
55
62
|
initializer "action_mailer.compile_config_methods" do
|
@@ -28,13 +28,13 @@ module ActionMailer
|
|
28
28
|
#
|
29
29
|
# assert_emails 2 do
|
30
30
|
# ContactMailer.welcome.deliver_now
|
31
|
-
# ContactMailer.welcome.
|
31
|
+
# ContactMailer.welcome.deliver_later
|
32
32
|
# end
|
33
33
|
# end
|
34
|
-
def assert_emails(number)
|
34
|
+
def assert_emails(number, &block)
|
35
35
|
if block_given?
|
36
36
|
original_count = ActionMailer::Base.deliveries.size
|
37
|
-
|
37
|
+
perform_enqueued_jobs(only: ->(job) { delivery_job_filter(job) }, &block)
|
38
38
|
new_count = ActionMailer::Base.deliveries.size
|
39
39
|
assert_equal number, new_count - original_count, "#{number} emails expected, but #{new_count - original_count} were sent"
|
40
40
|
else
|
@@ -90,10 +90,23 @@ module ActionMailer
|
|
90
90
|
# end
|
91
91
|
# end
|
92
92
|
def assert_enqueued_emails(number, &block)
|
93
|
-
assert_enqueued_jobs
|
93
|
+
assert_enqueued_jobs(number, only: ->(job) { delivery_job_filter(job) }, &block)
|
94
94
|
end
|
95
95
|
|
96
|
-
# Asserts that
|
96
|
+
# Asserts that a specific email has been enqueued, optionally
|
97
|
+
# matching arguments.
|
98
|
+
#
|
99
|
+
# def test_email
|
100
|
+
# ContactMailer.welcome.deliver_later
|
101
|
+
# assert_enqueued_email_with ContactMailer, :welcome
|
102
|
+
# end
|
103
|
+
#
|
104
|
+
# def test_email_with_arguments
|
105
|
+
# ContactMailer.welcome("Hello", "Goodbye").deliver_later
|
106
|
+
# assert_enqueued_email_with ContactMailer, :welcome, args: ["Hello", "Goodbye"]
|
107
|
+
# end
|
108
|
+
#
|
109
|
+
# If a block is passed, that block should cause the specified email
|
97
110
|
# to be enqueued.
|
98
111
|
#
|
99
112
|
# def test_email_in_block
|
@@ -106,20 +119,17 @@ module ActionMailer
|
|
106
119
|
#
|
107
120
|
# def test_parameterized_email
|
108
121
|
# assert_enqueued_email_with ContactMailer, :welcome,
|
109
|
-
# args: {email: 'user@example.com} do
|
122
|
+
# args: {email: 'user@example.com'} do
|
110
123
|
# ContactMailer.with(email: 'user@example.com').welcome.deliver_later
|
111
124
|
# end
|
112
125
|
# end
|
113
126
|
def assert_enqueued_email_with(mailer, method, args: nil, queue: "mailers", &block)
|
114
|
-
if args.is_a?
|
115
|
-
|
116
|
-
args = [mailer.to_s, method.to_s, "deliver_now", args]
|
127
|
+
args = if args.is_a?(Hash)
|
128
|
+
[mailer.to_s, method.to_s, "deliver_now", params: args, args: []]
|
117
129
|
else
|
118
|
-
|
119
|
-
args = [mailer.to_s, method.to_s, "deliver_now", *args]
|
130
|
+
[mailer.to_s, method.to_s, "deliver_now", args: Array(args)]
|
120
131
|
end
|
121
|
-
|
122
|
-
assert_enqueued_with(job: job, args: args, queue: queue, &block)
|
132
|
+
assert_enqueued_with(job: mailer.delivery_job, args: args, queue: queue, &block)
|
123
133
|
end
|
124
134
|
|
125
135
|
# Asserts that no emails are enqueued for later delivery.
|
@@ -138,7 +148,15 @@ module ActionMailer
|
|
138
148
|
# end
|
139
149
|
# end
|
140
150
|
def assert_no_enqueued_emails(&block)
|
141
|
-
|
151
|
+
assert_enqueued_emails 0, &block
|
142
152
|
end
|
153
|
+
|
154
|
+
private
|
155
|
+
|
156
|
+
def delivery_job_filter(job)
|
157
|
+
job_class = job.is_a?(Hash) ? job.fetch(:job) : job.class
|
158
|
+
|
159
|
+
Base.descendants.map(&:delivery_job).include?(job_class)
|
160
|
+
end
|
143
161
|
end
|
144
162
|
end
|
data/lib/action_mailer.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
#--
|
4
|
-
# Copyright (c) 2004-
|
4
|
+
# Copyright (c) 2004-2019 David Heinemeier Hansson
|
5
5
|
#
|
6
6
|
# Permission is hereby granted, free of charge, to any person obtaining
|
7
7
|
# a copy of this software and associated documentation files (the
|
@@ -52,6 +52,7 @@ module ActionMailer
|
|
52
52
|
autoload :TestHelper
|
53
53
|
autoload :MessageDelivery
|
54
54
|
autoload :DeliveryJob
|
55
|
+
autoload :MailDeliveryJob
|
55
56
|
|
56
57
|
def self.eager_load!
|
57
58
|
super
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: actionmailer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 6.0.0.beta1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Heinemeier Hansson
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-01-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: actionpack
|
@@ -16,42 +16,42 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - '='
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 6.0.0.beta1
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - '='
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: 6.0.0.beta1
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: actionview
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - '='
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
33
|
+
version: 6.0.0.beta1
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - '='
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
40
|
+
version: 6.0.0.beta1
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: activejob
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - '='
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version:
|
47
|
+
version: 6.0.0.beta1
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - '='
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version:
|
54
|
+
version: 6.0.0.beta1
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: mail
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -86,8 +86,8 @@ dependencies:
|
|
86
86
|
- - "~>"
|
87
87
|
- !ruby/object:Gem::Version
|
88
88
|
version: '2.0'
|
89
|
-
description: Email on Rails. Compose, deliver,
|
90
|
-
|
89
|
+
description: Email on Rails. Compose, deliver, and test emails using the familiar
|
90
|
+
controller/view pattern. First-class support for multipart email and attachments.
|
91
91
|
email: david@loudthinking.com
|
92
92
|
executables: []
|
93
93
|
extensions: []
|
@@ -104,6 +104,7 @@ files:
|
|
104
104
|
- lib/action_mailer/gem_version.rb
|
105
105
|
- lib/action_mailer/inline_preview_interceptor.rb
|
106
106
|
- lib/action_mailer/log_subscriber.rb
|
107
|
+
- lib/action_mailer/mail_delivery_job.rb
|
107
108
|
- lib/action_mailer/mail_helper.rb
|
108
109
|
- lib/action_mailer/message_delivery.rb
|
109
110
|
- lib/action_mailer/parameterized.rb
|
@@ -121,9 +122,9 @@ homepage: http://rubyonrails.org
|
|
121
122
|
licenses:
|
122
123
|
- MIT
|
123
124
|
metadata:
|
124
|
-
source_code_uri: https://github.com/rails/rails/tree/
|
125
|
-
changelog_uri: https://github.com/rails/rails/blob/
|
126
|
-
post_install_message:
|
125
|
+
source_code_uri: https://github.com/rails/rails/tree/v6.0.0.beta1/actionmailer
|
126
|
+
changelog_uri: https://github.com/rails/rails/blob/v6.0.0.beta1/actionmailer/CHANGELOG.md
|
127
|
+
post_install_message:
|
127
128
|
rdoc_options: []
|
128
129
|
require_paths:
|
129
130
|
- lib
|
@@ -131,16 +132,16 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
131
132
|
requirements:
|
132
133
|
- - ">="
|
133
134
|
- !ruby/object:Gem::Version
|
134
|
-
version: 2.
|
135
|
+
version: 2.5.0
|
135
136
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
136
137
|
requirements:
|
137
|
-
- - "
|
138
|
+
- - ">"
|
138
139
|
- !ruby/object:Gem::Version
|
139
|
-
version:
|
140
|
+
version: 1.3.1
|
140
141
|
requirements:
|
141
142
|
- none
|
142
|
-
rubygems_version: 3.
|
143
|
-
signing_key:
|
143
|
+
rubygems_version: 3.0.1
|
144
|
+
signing_key:
|
144
145
|
specification_version: 4
|
145
|
-
summary: Email composition
|
146
|
+
summary: Email composition and delivery framework (part of Rails).
|
146
147
|
test_files: []
|