actionmailer 4.2.11.3 → 5.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 +5 -5
- data/CHANGELOG.md +48 -118
- data/MIT-LICENSE +1 -1
- data/README.rdoc +2 -3
- data/lib/action_mailer.rb +1 -1
- data/lib/action_mailer/base.rb +120 -116
- data/lib/action_mailer/delivery_job.rb +2 -2
- data/lib/action_mailer/delivery_methods.rb +4 -1
- data/lib/action_mailer/gem_version.rb +5 -5
- data/lib/action_mailer/inline_preview_interceptor.rb +3 -3
- data/lib/action_mailer/log_subscriber.rb +5 -5
- data/lib/action_mailer/mail_helper.rb +13 -1
- data/lib/action_mailer/message_delivery.rb +8 -25
- data/lib/action_mailer/preview.rb +7 -7
- data/lib/action_mailer/railtie.rb +6 -1
- data/lib/action_mailer/test_case.rb +6 -7
- data/lib/action_mailer/test_helper.rb +53 -2
- data/lib/rails/generators/mailer/USAGE +3 -3
- data/lib/rails/generators/mailer/mailer_generator.rb +8 -5
- data/lib/rails/generators/mailer/templates/mailer.rb +2 -2
- metadata +15 -14
- data/lib/rails/generators/mailer/templates/application_mailer.rb +0 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 56789d48fc0a0b2b154ceb49bce402209a6bedad
|
4
|
+
data.tar.gz: fbbbdcb930198d46970bc07307ab65e8ebc4c0ba
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1dcf35b84d00a94840c13730e7abc5b955ac16c8685f7de2ebc00bb7f5a9d093e202c216a9b717c9e91ce4fea9c56b7cc2da028cd31ad66ae216d19f8aa9cdb4
|
7
|
+
data.tar.gz: 58f33f59b8549216c0ff7a8ca623b94c9c755802c40f3f897a2190b9a14e7b08d75ae0d144b44a5ee1860d8fcfd52be1164dc0dcdca1cbdcaac6b0bc939886dc
|
data/CHANGELOG.md
CHANGED
@@ -1,78 +1,28 @@
|
|
1
|
-
## Rails
|
1
|
+
## Rails 5.0.0.beta1 (December 18, 2015) ##
|
2
2
|
|
3
3
|
* No changes.
|
4
4
|
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
* No changes.
|
9
|
-
|
10
|
-
|
11
|
-
## Rails 4.2.11.1 (March 11, 2019) ##
|
12
|
-
|
13
|
-
* No changes.
|
14
|
-
|
15
|
-
|
16
|
-
## Rails 4.2.11 (November 27, 2018) ##
|
17
|
-
|
18
|
-
* No changes.
|
19
|
-
|
20
|
-
|
21
|
-
## Rails 4.2.10 (September 27, 2017) ##
|
22
|
-
|
23
|
-
* No changes.
|
24
|
-
|
25
|
-
|
26
|
-
## Rails 4.2.9 (June 26, 2017) ##
|
27
|
-
|
28
|
-
* No changes.
|
29
|
-
|
30
|
-
|
31
|
-
## Rails 4.2.8 (February 21, 2017) ##
|
32
|
-
|
33
|
-
* No changes.
|
34
|
-
|
35
|
-
|
36
|
-
## Rails 4.2.7 (July 12, 2016) ##
|
37
|
-
|
38
|
-
* Removes `-t` from default Sendmail arguments to match the underlying
|
39
|
-
`Mail::Sendmail` setting.
|
40
|
-
|
41
|
-
*Clayton Liggitt*
|
42
|
-
|
43
|
-
|
44
|
-
## Rails 4.2.6 (March 07, 2016) ##
|
45
|
-
|
46
|
-
* No changes.
|
6
|
+
* `config.force_ssl = true` will set
|
7
|
+
`config.action_mailer.default_url_options = { protocol: 'https' }`
|
47
8
|
|
9
|
+
*Andrew Kampjes*
|
48
10
|
|
49
|
-
|
50
|
-
|
51
|
-
* No changes.
|
52
|
-
|
53
|
-
|
54
|
-
## Rails 4.2.5.1 (January 25, 2015) ##
|
55
|
-
|
56
|
-
* No changes.
|
11
|
+
* Add `config.action_mailer.deliver_later_queue_name` configuration to set the
|
12
|
+
mailer queue name.
|
57
13
|
|
58
|
-
|
59
|
-
## Rails 4.2.5 (November 12, 2015) ##
|
60
|
-
|
61
|
-
* No changes.
|
62
|
-
|
63
|
-
|
64
|
-
## Rails 4.2.4 (August 24, 2015) ##
|
65
|
-
|
66
|
-
* No Changes *
|
67
|
-
|
68
|
-
|
69
|
-
## Rails 4.2.3 (June 25, 2015) ##
|
14
|
+
*Chris McGrath*
|
70
15
|
|
71
16
|
* `assert_emails` in block form use the given number as expected value.
|
72
17
|
This makes the error message much easier to understand.
|
73
18
|
|
74
19
|
*Yuji Yaginuma*
|
75
20
|
|
21
|
+
* Add support for inline images in mailer previews by using an interceptor
|
22
|
+
class to convert cid: urls in image src attributes to data urls.
|
23
|
+
|
24
|
+
*Andrew White*
|
25
|
+
|
76
26
|
* Mailer preview now uses `url_for` to fix links to emails for apps running on
|
77
27
|
a subdirectory.
|
78
28
|
|
@@ -89,79 +39,59 @@
|
|
89
39
|
|
90
40
|
*Yves Senn*
|
91
41
|
|
42
|
+
* Add `assert_enqueued_emails` and `assert_no_enqueued_emails`.
|
92
43
|
|
93
|
-
|
94
|
-
|
95
|
-
* No Changes *
|
96
|
-
|
97
|
-
|
98
|
-
## Rails 4.2.1 (March 19, 2015) ##
|
44
|
+
Example:
|
99
45
|
|
100
|
-
|
46
|
+
def test_emails
|
47
|
+
assert_enqueued_emails 2 do
|
48
|
+
ContactMailer.welcome.deliver_later
|
49
|
+
ContactMailer.welcome.deliver_later
|
50
|
+
end
|
51
|
+
end
|
101
52
|
|
53
|
+
def test_no_emails
|
54
|
+
assert_no_enqueued_emails do
|
55
|
+
# No emails enqueued here
|
56
|
+
end
|
57
|
+
end
|
102
58
|
|
103
|
-
|
59
|
+
*George Claghorn*
|
104
60
|
|
105
|
-
* `
|
106
|
-
|
107
|
-
some spam detection engines. Mailers now inherit from `ApplicationMailer`
|
108
|
-
which sets the default layout.
|
61
|
+
* Add `_mailer` suffix to mailers created via generator, following the same
|
62
|
+
naming convention used in controllers and jobs.
|
109
63
|
|
110
|
-
*
|
64
|
+
*Carlos Souza*
|
111
65
|
|
112
|
-
*
|
113
|
-
Passing `only_path: false` is no longer needed.
|
66
|
+
* Remove deprecate `*_path` helpers in email views.
|
114
67
|
|
115
|
-
|
68
|
+
*Rafael Mendonça França*
|
116
69
|
|
117
|
-
|
70
|
+
* Remove deprecated `deliver` and `deliver!` methods.
|
118
71
|
|
119
|
-
*
|
72
|
+
*claudiob*
|
120
73
|
|
121
|
-
|
74
|
+
* Template lookup now respects default locale and I18n fallbacks.
|
122
75
|
|
123
|
-
|
76
|
+
Given the following templates:
|
124
77
|
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
using the new Active Job framework in Rails and will use the queue that you
|
129
|
-
have configured in Rails.
|
78
|
+
mailer/demo.html.erb
|
79
|
+
mailer/demo.en.html.erb
|
80
|
+
mailer/demo.pt.html.erb
|
130
81
|
|
131
|
-
|
82
|
+
Before this change, for a locale that doesn't have its associated file, the
|
83
|
+
`mailer/demo.html.erb` would be rendered even if `en` was the default locale.
|
132
84
|
|
133
|
-
|
85
|
+
Now `mailer/demo.en.html.erb` has precedence over the file without locale.
|
134
86
|
|
135
|
-
|
87
|
+
Also, it is possible to give a fallback.
|
136
88
|
|
137
|
-
|
138
|
-
|
139
|
-
helper is recommended instead.
|
89
|
+
mailer/demo.pt.html.erb
|
90
|
+
mailer/demo.pt-BR.html.erb
|
140
91
|
|
141
|
-
|
142
|
-
|
143
|
-
* Raise an exception when attachments are added after `mail` is called.
|
144
|
-
This is a safeguard to prevent invalid emails.
|
145
|
-
|
146
|
-
Fixes #16163.
|
147
|
-
|
148
|
-
*Yves Senn*
|
92
|
+
So if the locale is `pt-PT`, `mailer/demo.pt.html.erb` will be rendered given
|
93
|
+
the right I18n fallback configuration.
|
149
94
|
|
150
|
-
*
|
151
|
-
|
152
|
-
This configuration option can be used to enable the mail preview in
|
153
|
-
environments other than development (such as staging).
|
154
|
-
|
155
|
-
Defaults to `true` in development and `false` elsewhere.
|
156
|
-
|
157
|
-
*Leonard Garvey*
|
158
|
-
|
159
|
-
* Allow preview interceptors to be registered through
|
160
|
-
`config.action_mailer.preview_interceptors`.
|
161
|
-
|
162
|
-
See #15739.
|
163
|
-
|
164
|
-
*Yves Senn*
|
95
|
+
*Rafael Mendonça França*
|
165
96
|
|
166
|
-
Please check [4-
|
167
|
-
for previous changes.
|
97
|
+
Please check [4-2-stable](https://github.com/rails/rails/blob/4-2-stable/actionmailer/CHANGELOG.md) for previous changes.
|
data/MIT-LICENSE
CHANGED
data/README.rdoc
CHANGED
@@ -146,11 +146,11 @@ The Base class has the full list of configuration options. Here's an example:
|
|
146
146
|
|
147
147
|
The latest version of Action Mailer can be installed with RubyGems:
|
148
148
|
|
149
|
-
|
149
|
+
$ gem install actionmailer
|
150
150
|
|
151
151
|
Source code can be downloaded as part of the Rails project on GitHub
|
152
152
|
|
153
|
-
* https://github.com/rails/rails/tree/
|
153
|
+
* https://github.com/rails/rails/tree/master/actionmailer
|
154
154
|
|
155
155
|
|
156
156
|
== License
|
@@ -173,4 +173,3 @@ Bug reports can be filed for the Ruby on Rails project here:
|
|
173
173
|
Feature requests should be discussed on the rails-core mailing list here:
|
174
174
|
|
175
175
|
* https://groups.google.com/forum/?fromgroups#!forum/rubyonrails-core
|
176
|
-
|
data/lib/action_mailer.rb
CHANGED
data/lib/action_mailer/base.rb
CHANGED
@@ -21,11 +21,11 @@ module ActionMailer
|
|
21
21
|
# the mailer views, options on the mail itself such as the <tt>:from</tt> address, and attachments.
|
22
22
|
#
|
23
23
|
# class ApplicationMailer < ActionMailer::Base
|
24
|
-
# default from: 'from@
|
24
|
+
# default from: 'from@example.com'
|
25
25
|
# layout 'mailer'
|
26
26
|
# end
|
27
27
|
#
|
28
|
-
# class
|
28
|
+
# class NotifierMailer < ApplicationMailer
|
29
29
|
# default from: 'no-reply@example.com',
|
30
30
|
# return_path: 'system@example.com'
|
31
31
|
#
|
@@ -88,7 +88,7 @@ module ActionMailer
|
|
88
88
|
#
|
89
89
|
# To define a template to be used with a mailing, create an <tt>.erb</tt> file with the same
|
90
90
|
# name as the method in your mailer model. For example, in the mailer defined above, the template at
|
91
|
-
# <tt>app/views/
|
91
|
+
# <tt>app/views/notifier_mailer/welcome.text.erb</tt> would be used to generate the email.
|
92
92
|
#
|
93
93
|
# Variables defined in the methods of your mailer model are accessible as instance variables in their
|
94
94
|
# corresponding view.
|
@@ -132,32 +132,32 @@ module ActionMailer
|
|
132
132
|
#
|
133
133
|
# config.action_mailer.default_url_options = { host: "example.com" }
|
134
134
|
#
|
135
|
-
#
|
136
|
-
# <tt>only_path: false</tt> option when using <tt>url_for</tt>. Since the <tt>url_for</tt> view helper
|
137
|
-
# will generate relative URLs by default when a <tt>:host</tt> option isn't explicitly provided, passing
|
138
|
-
# <tt>only_path: false</tt> will ensure that absolute URLs are generated.
|
135
|
+
# By default when <tt>config.force_ssl</tt> is true, URLs generated for hosts will use the HTTPS protocol.
|
139
136
|
#
|
140
137
|
# = Sending mail
|
141
138
|
#
|
142
|
-
# Once a mailer action and template are defined, you can deliver your message or
|
143
|
-
# for
|
139
|
+
# Once a mailer action and template are defined, you can deliver your message or defer its creation and
|
140
|
+
# delivery for later:
|
144
141
|
#
|
145
|
-
#
|
146
|
-
# mail =
|
147
|
-
# mail.deliver_now
|
142
|
+
# NotifierMailer.welcome(User.first).deliver_now # sends the email
|
143
|
+
# mail = NotifierMailer.welcome(User.first) # => an ActionMailer::MessageDelivery object
|
144
|
+
# mail.deliver_now # generates and sends the email now
|
148
145
|
#
|
149
|
-
# The <tt>ActionMailer::MessageDelivery</tt> class is a wrapper around a
|
150
|
-
# you want direct access to
|
151
|
-
# the <tt>ActionMailer::MessageDelivery</tt> object.
|
146
|
+
# The <tt>ActionMailer::MessageDelivery</tt> class is a wrapper around a delegate that will call
|
147
|
+
# your method to generate the mail. If you want direct access to delegator, or <tt>Mail::Message</tt>,
|
148
|
+
# you can call the <tt>message</tt> method on the <tt>ActionMailer::MessageDelivery</tt> object.
|
152
149
|
#
|
153
|
-
#
|
150
|
+
# NotifierMailer.welcome(User.first).message # => a Mail::Message object
|
154
151
|
#
|
155
|
-
# Action Mailer is nicely integrated with Active Job so you can send emails in the background
|
156
|
-
# of the request-response cycle, so the user doesn't have to wait on it):
|
152
|
+
# Action Mailer is nicely integrated with Active Job so you can generate and send emails in the background
|
153
|
+
# (example: outside of the request-response cycle, so the user doesn't have to wait on it):
|
157
154
|
#
|
158
|
-
#
|
155
|
+
# NotifierMailer.welcome(User.first).deliver_later # enqueue the email sending to Active Job
|
156
|
+
#
|
157
|
+
# Note that <tt>deliver_later</tt> will execute your method from the background job.
|
159
158
|
#
|
160
159
|
# You never instantiate your mailer class. Rather, you just call the method you defined on the class itself.
|
160
|
+
# All instance methods are expected to return a message object to be sent.
|
161
161
|
#
|
162
162
|
# = Multipart Emails
|
163
163
|
#
|
@@ -184,7 +184,7 @@ module ActionMailer
|
|
184
184
|
#
|
185
185
|
# Sending attachment in emails is easy:
|
186
186
|
#
|
187
|
-
# class
|
187
|
+
# class NotifierMailer < ApplicationMailer
|
188
188
|
# def welcome(recipient)
|
189
189
|
# attachments['free_book.pdf'] = File.read('path/to/file.pdf')
|
190
190
|
# mail(to: recipient, subject: "New account information")
|
@@ -200,7 +200,7 @@ module ActionMailer
|
|
200
200
|
# If you need to send attachments with no content, you need to create an empty view for it,
|
201
201
|
# or add an empty body parameter like this:
|
202
202
|
#
|
203
|
-
# class
|
203
|
+
# class NotifierMailer < ApplicationMailer
|
204
204
|
# def welcome(recipient)
|
205
205
|
# attachments['free_book.pdf'] = File.read('path/to/file.pdf')
|
206
206
|
# mail(to: recipient, subject: "New account information", body: "")
|
@@ -212,7 +212,7 @@ module ActionMailer
|
|
212
212
|
# You can also specify that a file should be displayed inline with other HTML. This is useful
|
213
213
|
# if you want to display a corporate logo or a photo.
|
214
214
|
#
|
215
|
-
# class
|
215
|
+
# class NotifierMailer < ApplicationMailer
|
216
216
|
# def welcome(recipient)
|
217
217
|
# attachments.inline['photo.png'] = File.read('path/to/photo.png')
|
218
218
|
# mail(to: recipient, subject: "Here is what we look like")
|
@@ -251,7 +251,7 @@ module ActionMailer
|
|
251
251
|
# Action Mailer provides some intelligent defaults for your emails, these are usually specified in a
|
252
252
|
# default method inside the class definition:
|
253
253
|
#
|
254
|
-
# class
|
254
|
+
# class NotifierMailer < ApplicationMailer
|
255
255
|
# default sender: 'system@example.com'
|
256
256
|
# end
|
257
257
|
#
|
@@ -259,8 +259,8 @@ module ActionMailer
|
|
259
259
|
# <tt>ActionMailer::Base</tt> sets the following:
|
260
260
|
#
|
261
261
|
# * <tt>mime_version: "1.0"</tt>
|
262
|
-
# * <tt>charset: "UTF-8"
|
263
|
-
# * <tt>content_type: "text/plain"
|
262
|
+
# * <tt>charset: "UTF-8"</tt>
|
263
|
+
# * <tt>content_type: "text/plain"</tt>
|
264
264
|
# * <tt>parts_order: [ "text/plain", "text/enriched", "text/html" ]</tt>
|
265
265
|
#
|
266
266
|
# <tt>parts_order</tt> and <tt>charset</tt> are not actually valid <tt>Mail::Message</tt> header fields,
|
@@ -269,7 +269,7 @@ module ActionMailer
|
|
269
269
|
# As you can pass in any header, you need to either quote the header as a string, or pass it in as
|
270
270
|
# an underscored symbol, so the following will work:
|
271
271
|
#
|
272
|
-
# class
|
272
|
+
# class NotifierMailer < ApplicationMailer
|
273
273
|
# default 'Content-Transfer-Encoding' => '7bit',
|
274
274
|
# content_description: 'This is a description'
|
275
275
|
# end
|
@@ -277,7 +277,7 @@ module ActionMailer
|
|
277
277
|
# Finally, Action Mailer also supports passing <tt>Proc</tt> objects into the default hash, so you
|
278
278
|
# can define methods that evaluate as the message is being generated:
|
279
279
|
#
|
280
|
-
# class
|
280
|
+
# class NotifierMailer < ApplicationMailer
|
281
281
|
# default 'X-Special-Header' => Proc.new { my_method }
|
282
282
|
#
|
283
283
|
# private
|
@@ -288,7 +288,7 @@ module ActionMailer
|
|
288
288
|
# end
|
289
289
|
#
|
290
290
|
# Note that the proc is evaluated right at the start of the mail message generation, so if you
|
291
|
-
# set something in the
|
291
|
+
# set something in the default using a proc, and then set the same thing inside of your
|
292
292
|
# mailer method, it will get over written by the mailer method.
|
293
293
|
#
|
294
294
|
# It is also possible to set these default options that will be used in all mailers through
|
@@ -302,7 +302,7 @@ module ActionMailer
|
|
302
302
|
# This may be useful, for example, when you want to add default inline attachments for all
|
303
303
|
# messages sent out by a certain mailer class:
|
304
304
|
#
|
305
|
-
# class
|
305
|
+
# class NotifierMailer < ApplicationMailer
|
306
306
|
# before_action :add_inline_attachment!
|
307
307
|
#
|
308
308
|
# def welcome
|
@@ -321,8 +321,9 @@ module ActionMailer
|
|
321
321
|
# callbacks in the same manner that you would use callbacks in classes that
|
322
322
|
# inherit from <tt>ActionController::Base</tt>.
|
323
323
|
#
|
324
|
-
# Note that unless you have a specific reason to do so, you should prefer
|
325
|
-
# rather than after_action in your
|
324
|
+
# Note that unless you have a specific reason to do so, you should prefer
|
325
|
+
# using <tt>before_action</tt> rather than <tt>after_action</tt> in your
|
326
|
+
# Action Mailer classes so that headers are parsed properly.
|
326
327
|
#
|
327
328
|
# = Previewing emails
|
328
329
|
#
|
@@ -330,9 +331,9 @@ module ActionMailer
|
|
330
331
|
# <tt>ActionMailer::Base.preview_path</tt>. Since most emails do something interesting
|
331
332
|
# with database data, you'll need to write some scenarios to load messages with fake data:
|
332
333
|
#
|
333
|
-
# class
|
334
|
+
# class NotifierMailerPreview < ActionMailer::Preview
|
334
335
|
# def welcome
|
335
|
-
#
|
336
|
+
# NotifierMailer.welcome(User.first)
|
336
337
|
# end
|
337
338
|
# end
|
338
339
|
#
|
@@ -414,6 +415,8 @@ module ActionMailer
|
|
414
415
|
#
|
415
416
|
# * <tt>deliveries</tt> - Keeps an array of all the emails sent out through the Action Mailer with
|
416
417
|
# <tt>delivery_method :test</tt>. Most useful for unit and functional testing.
|
418
|
+
#
|
419
|
+
# * <tt>deliver_later_queue_name</tt> - The name of the queue used with <tt>deliver_later</tt>.
|
417
420
|
class Base < AbstractController::Base
|
418
421
|
include DeliveryMethods
|
419
422
|
include Previews
|
@@ -438,8 +441,6 @@ module ActionMailer
|
|
438
441
|
|
439
442
|
helper ActionMailer::MailHelper
|
440
443
|
|
441
|
-
private_class_method :new #:nodoc:
|
442
|
-
|
443
444
|
class_attribute :default_params
|
444
445
|
self.default_params = {
|
445
446
|
mime_version: "1.0",
|
@@ -463,29 +464,25 @@ module ActionMailer
|
|
463
464
|
# Either a class, string or symbol can be passed in as the Observer.
|
464
465
|
# If a string or symbol is passed in it will be camelized and constantized.
|
465
466
|
def register_observer(observer)
|
466
|
-
|
467
|
-
when String, Symbol
|
468
|
-
observer.to_s.camelize.constantize
|
469
|
-
else
|
470
|
-
observer
|
471
|
-
end
|
472
|
-
|
473
|
-
Mail.register_observer(delivery_observer)
|
467
|
+
Mail.register_observer(observer_class_for(observer))
|
474
468
|
end
|
475
469
|
|
476
470
|
# Register an Interceptor which will be called before mail is sent.
|
477
471
|
# Either a class, string or symbol can be passed in as the Interceptor.
|
478
472
|
# If a string or symbol is passed in it will be camelized and constantized.
|
479
473
|
def register_interceptor(interceptor)
|
480
|
-
|
481
|
-
|
482
|
-
|
483
|
-
|
484
|
-
|
485
|
-
|
486
|
-
|
487
|
-
|
474
|
+
Mail.register_interceptor(observer_class_for(interceptor))
|
475
|
+
end
|
476
|
+
|
477
|
+
def observer_class_for(value) # :nodoc:
|
478
|
+
case value
|
479
|
+
when String, Symbol
|
480
|
+
value.to_s.camelize.constantize
|
481
|
+
else
|
482
|
+
value
|
483
|
+
end
|
488
484
|
end
|
485
|
+
private :observer_class_for
|
489
486
|
|
490
487
|
# Returns the name of current mailer. This method is also being used as a path for a view lookup.
|
491
488
|
# If this is an anonymous mailer, this method will return +anonymous+ instead.
|
@@ -544,10 +541,6 @@ module ActionMailer
|
|
544
541
|
end
|
545
542
|
end
|
546
543
|
|
547
|
-
def respond_to?(method, include_private = false) #:nodoc:
|
548
|
-
super || action_methods.include?(method.to_s)
|
549
|
-
end
|
550
|
-
|
551
544
|
protected
|
552
545
|
|
553
546
|
def set_payload_for_mail(payload, mail) #:nodoc:
|
@@ -569,6 +562,12 @@ module ActionMailer
|
|
569
562
|
super
|
570
563
|
end
|
571
564
|
end
|
565
|
+
|
566
|
+
private
|
567
|
+
|
568
|
+
def respond_to_missing?(method, include_all = false) #:nodoc:
|
569
|
+
action_methods.include?(method.to_s)
|
570
|
+
end
|
572
571
|
end
|
573
572
|
|
574
573
|
attr_internal :message
|
@@ -577,11 +576,10 @@ module ActionMailer
|
|
577
576
|
# will be initialized according to the named method. If not, the mailer will
|
578
577
|
# remain uninitialized (useful when you only need to invoke the "receive"
|
579
578
|
# method, for instance).
|
580
|
-
def initialize
|
579
|
+
def initialize
|
581
580
|
super()
|
582
581
|
@_mail_was_called = false
|
583
582
|
@_message = Mail.new
|
584
|
-
process(method_name, *args) if method_name
|
585
583
|
end
|
586
584
|
|
587
585
|
def process(method_name, *args) #:nodoc:
|
@@ -591,8 +589,6 @@ module ActionMailer
|
|
591
589
|
}
|
592
590
|
|
593
591
|
ActiveSupport::Notifications.instrument("process.action_mailer", payload) do
|
594
|
-
lookup_context.skip_default_locale!
|
595
|
-
|
596
592
|
super
|
597
593
|
@_message = NullMail.new unless @_mail_was_called
|
598
594
|
end
|
@@ -662,18 +658,18 @@ module ActionMailer
|
|
662
658
|
#
|
663
659
|
# mail.attachments['filename.jpg'] = File.read('/path/to/filename.jpg')
|
664
660
|
#
|
665
|
-
# If you do this, then Mail will take the file name and work out the mime type
|
666
|
-
# set the Content-Type, Content-Disposition, Content-Transfer-Encoding
|
667
|
-
#
|
661
|
+
# If you do this, then Mail will take the file name and work out the mime type.
|
662
|
+
# It will also set the Content-Type, Content-Disposition, Content-Transfer-Encoding
|
663
|
+
# and encode the contents of the attachment in Base64.
|
668
664
|
#
|
669
665
|
# You can also specify overrides if you want by passing a hash instead of a string:
|
670
666
|
#
|
671
667
|
# mail.attachments['filename.jpg'] = {mime_type: 'application/x-gzip',
|
672
668
|
# content: File.read('/path/to/filename.jpg')}
|
673
669
|
#
|
674
|
-
# If you want to use
|
675
|
-
#
|
676
|
-
#
|
670
|
+
# If you want to use encoding other than Base64 then you will need to pass encoding
|
671
|
+
# type along with the pre-encoded content as Mail doesn't know how to decode the
|
672
|
+
# data:
|
677
673
|
#
|
678
674
|
# file_content = SpecialEncode(File.read('/path/to/filename.jpg'))
|
679
675
|
# mail.attachments['filename.jpg'] = {mime_type: 'application/x-gzip',
|
@@ -798,52 +794,40 @@ module ActionMailer
|
|
798
794
|
# end
|
799
795
|
#
|
800
796
|
def mail(headers = {}, &block)
|
801
|
-
return
|
802
|
-
|
803
|
-
m = @_message
|
797
|
+
return message if @_mail_was_called && headers.blank? && !block
|
804
798
|
|
805
799
|
# At the beginning, do not consider class default for content_type
|
806
800
|
content_type = headers[:content_type]
|
807
801
|
|
808
|
-
|
809
|
-
default_values = {}
|
810
|
-
self.class.default.each do |k,v|
|
811
|
-
default_values[k] = v.is_a?(Proc) ? instance_eval(&v) : v
|
812
|
-
end
|
813
|
-
|
814
|
-
# Handle defaults
|
815
|
-
headers = headers.reverse_merge(default_values)
|
816
|
-
headers[:subject] ||= default_i18n_subject
|
802
|
+
headers = apply_defaults(headers)
|
817
803
|
|
818
804
|
# Apply charset at the beginning so all fields are properly quoted
|
819
|
-
|
805
|
+
message.charset = charset = headers[:charset]
|
820
806
|
|
821
807
|
# Set configure delivery behavior
|
822
|
-
wrap_delivery_behavior!(headers
|
808
|
+
wrap_delivery_behavior!(headers[:delivery_method], headers[:delivery_method_options])
|
823
809
|
|
824
|
-
|
825
|
-
assignable = headers.except(:parts_order, :content_type, :body, :template_name, :template_path)
|
826
|
-
assignable.each { |k, v| m[k] = v }
|
810
|
+
assign_headers_to_message(message, headers)
|
827
811
|
|
828
812
|
# Render the templates and blocks
|
829
813
|
responses = collect_responses(headers, &block)
|
830
814
|
@_mail_was_called = true
|
831
815
|
|
832
|
-
create_parts_from_responses(
|
816
|
+
create_parts_from_responses(message, responses)
|
833
817
|
|
834
818
|
# Setup content type, reapply charset and handle parts order
|
835
|
-
|
836
|
-
|
819
|
+
message.content_type = set_content_type(message, content_type, headers[:content_type])
|
820
|
+
message.charset = charset
|
837
821
|
|
838
|
-
if
|
839
|
-
|
840
|
-
|
822
|
+
if message.multipart?
|
823
|
+
message.body.set_sort_order(headers[:parts_order])
|
824
|
+
message.body.sort_parts!
|
841
825
|
end
|
842
826
|
|
843
|
-
|
827
|
+
message
|
844
828
|
end
|
845
829
|
|
846
|
-
|
830
|
+
protected
|
847
831
|
|
848
832
|
# Used by #mail to set the content type of the message.
|
849
833
|
#
|
@@ -860,7 +844,7 @@ module ActionMailer
|
|
860
844
|
when user_content_type.present?
|
861
845
|
user_content_type
|
862
846
|
when m.has_attachments?
|
863
|
-
if m.attachments.detect
|
847
|
+
if m.attachments.detect(&:inline?)
|
864
848
|
["multipart", "related", params]
|
865
849
|
else
|
866
850
|
["multipart", "mixed", params]
|
@@ -881,45 +865,70 @@ module ActionMailer
|
|
881
865
|
I18n.t(:subject, interpolations.merge(scope: [mailer_scope, action_name], default: action_name.humanize))
|
882
866
|
end
|
883
867
|
|
884
|
-
|
885
|
-
|
868
|
+
# Emails do not support relative path links.
|
869
|
+
def self.supports_path?
|
870
|
+
false
|
871
|
+
end
|
872
|
+
|
873
|
+
private
|
874
|
+
|
875
|
+
def apply_defaults(headers)
|
876
|
+
default_values = self.class.default.map do |key, value|
|
877
|
+
[
|
878
|
+
key,
|
879
|
+
value.is_a?(Proc) ? instance_eval(&value) : value
|
880
|
+
]
|
881
|
+
end.to_h
|
882
|
+
|
883
|
+
headers_with_defaults = headers.reverse_merge(default_values)
|
884
|
+
headers_with_defaults[:subject] ||= default_i18n_subject
|
885
|
+
headers_with_defaults
|
886
|
+
end
|
887
|
+
|
888
|
+
def assign_headers_to_message(message, headers)
|
889
|
+
assignable = headers.except(:parts_order, :content_type, :body, :template_name,
|
890
|
+
:template_path, :delivery_method, :delivery_method_options)
|
891
|
+
assignable.each { |k, v| message[k] = v }
|
892
|
+
end
|
886
893
|
|
894
|
+
def collect_responses(headers)
|
887
895
|
if block_given?
|
888
896
|
collector = ActionMailer::Collector.new(lookup_context) { render(action_name) }
|
889
897
|
yield(collector)
|
890
|
-
|
898
|
+
collector.responses
|
891
899
|
elsif headers[:body]
|
892
|
-
|
900
|
+
[{
|
893
901
|
body: headers.delete(:body),
|
894
902
|
content_type: self.class.default[:content_type] || "text/plain"
|
895
|
-
}
|
903
|
+
}]
|
896
904
|
else
|
897
|
-
|
898
|
-
|
905
|
+
collect_responses_from_templates(headers)
|
906
|
+
end
|
907
|
+
end
|
899
908
|
|
900
|
-
|
901
|
-
|
909
|
+
def collect_responses_from_templates(headers)
|
910
|
+
templates_path = headers[:template_path] || self.class.mailer_name
|
911
|
+
templates_name = headers[:template_name] || action_name
|
902
912
|
|
903
|
-
|
904
|
-
|
905
|
-
|
906
|
-
|
907
|
-
|
913
|
+
each_template(Array(templates_path), templates_name).map do |template|
|
914
|
+
self.formats = template.formats
|
915
|
+
{
|
916
|
+
body: render(template: template),
|
917
|
+
content_type: template.type.to_s
|
918
|
+
}
|
908
919
|
end
|
909
|
-
|
910
|
-
responses
|
911
920
|
end
|
912
921
|
|
913
|
-
def each_template(paths, name, &block)
|
922
|
+
def each_template(paths, name, &block)
|
914
923
|
templates = lookup_context.find_all(name, paths)
|
915
924
|
if templates.empty?
|
916
925
|
raise ActionView::MissingTemplate.new(paths, name, paths, false, 'mailer')
|
917
926
|
else
|
918
|
-
templates.uniq
|
927
|
+
templates.uniq(&:formats).each(&block)
|
919
928
|
end
|
920
929
|
end
|
921
930
|
|
922
|
-
def create_parts_from_responses(m, responses)
|
931
|
+
def create_parts_from_responses(m, responses)
|
923
932
|
if responses.size == 1 && !m.has_attachments?
|
924
933
|
responses[0].each { |k,v| m[k] = v }
|
925
934
|
elsif responses.size > 1 && m.has_attachments?
|
@@ -932,17 +941,12 @@ module ActionMailer
|
|
932
941
|
end
|
933
942
|
end
|
934
943
|
|
935
|
-
def insert_part(container, response, charset)
|
944
|
+
def insert_part(container, response, charset)
|
936
945
|
response[:charset] ||= charset
|
937
946
|
part = Mail::Part.new(response)
|
938
947
|
container.add_part(part)
|
939
948
|
end
|
940
949
|
|
941
|
-
# Emails do not support relative path links.
|
942
|
-
def self.supports_path?
|
943
|
-
false
|
944
|
-
end
|
945
|
-
|
946
950
|
ActiveSupport.run_load_hooks(:action_mailer, self)
|
947
951
|
end
|
948
952
|
end
|
@@ -4,9 +4,9 @@ module ActionMailer
|
|
4
4
|
# The <tt>ActionMailer::DeliveryJob</tt> class is used when you
|
5
5
|
# want to send emails outside of the request-response cycle.
|
6
6
|
class DeliveryJob < ActiveJob::Base # :nodoc:
|
7
|
-
queue_as
|
7
|
+
queue_as { ActionMailer::Base.deliver_later_queue_name }
|
8
8
|
|
9
|
-
def perform(mailer, mail_method, delivery_method, *args)
|
9
|
+
def perform(mailer, mail_method, delivery_method, *args) #:nodoc:
|
10
10
|
mailer.constantize.public_send(mail_method, *args).send(delivery_method)
|
11
11
|
end
|
12
12
|
end
|
@@ -16,6 +16,9 @@ module ActionMailer
|
|
16
16
|
cattr_accessor :perform_deliveries
|
17
17
|
self.perform_deliveries = true
|
18
18
|
|
19
|
+
cattr_accessor :deliver_later_queue_name
|
20
|
+
self.deliver_later_queue_name = :mailers
|
21
|
+
|
19
22
|
self.delivery_methods = {}.freeze
|
20
23
|
self.delivery_method = :smtp
|
21
24
|
|
@@ -33,7 +36,7 @@ module ActionMailer
|
|
33
36
|
|
34
37
|
add_delivery_method :sendmail, Mail::Sendmail,
|
35
38
|
location: '/usr/sbin/sendmail',
|
36
|
-
arguments: '-i'
|
39
|
+
arguments: '-i -t'
|
37
40
|
|
38
41
|
add_delivery_method :test, Mail::TestMailer
|
39
42
|
end
|
@@ -1,14 +1,14 @@
|
|
1
1
|
module ActionMailer
|
2
|
-
# Returns the version of the currently loaded Action Mailer as a <tt>Gem::Version</tt
|
2
|
+
# Returns the version of the currently loaded Action Mailer as a <tt>Gem::Version</tt>.
|
3
3
|
def self.gem_version
|
4
4
|
Gem::Version.new VERSION::STRING
|
5
5
|
end
|
6
6
|
|
7
7
|
module VERSION
|
8
|
-
MAJOR =
|
9
|
-
MINOR =
|
10
|
-
TINY =
|
11
|
-
PRE = "
|
8
|
+
MAJOR = 5
|
9
|
+
MINOR = 0
|
10
|
+
TINY = 0
|
11
|
+
PRE = "beta1"
|
12
12
|
|
13
13
|
STRING = [MAJOR, MINOR, TINY, PRE].compact.join(".")
|
14
14
|
end
|
@@ -5,10 +5,10 @@ module ActionMailer
|
|
5
5
|
# that use inline cid: style urls to data: style urls so that they are visible
|
6
6
|
# when previewing a HTML email in a web browser.
|
7
7
|
#
|
8
|
-
# This interceptor is
|
9
|
-
#
|
8
|
+
# This interceptor is enabled by default. To disable it, delete it from the
|
9
|
+
# <tt>ActionMailer::Base.preview_interceptors</tt> array:
|
10
10
|
#
|
11
|
-
# ActionMailer::Base.
|
11
|
+
# ActionMailer::Base.preview_interceptors.delete(ActionMailer::InlinePreviewInterceptor)
|
12
12
|
#
|
13
13
|
class InlinePreviewInterceptor
|
14
14
|
PATTERN = /src=(?:"cid:[^"]+"|'cid:[^']+')/i
|
@@ -2,13 +2,13 @@ require 'active_support/log_subscriber'
|
|
2
2
|
|
3
3
|
module ActionMailer
|
4
4
|
# Implements the ActiveSupport::LogSubscriber for logging notifications when
|
5
|
-
# email is delivered
|
5
|
+
# email is delivered or received.
|
6
6
|
class LogSubscriber < ActiveSupport::LogSubscriber
|
7
7
|
# An email was delivered.
|
8
8
|
def deliver(event)
|
9
9
|
info do
|
10
10
|
recipients = Array(event.payload[:to]).join(', ')
|
11
|
-
"
|
11
|
+
"Sent mail to #{recipients} (#{event.duration.round(1)}ms)"
|
12
12
|
end
|
13
13
|
|
14
14
|
debug { event.payload[:mail] }
|
@@ -16,7 +16,7 @@ module ActionMailer
|
|
16
16
|
|
17
17
|
# An email was received.
|
18
18
|
def receive(event)
|
19
|
-
info { "
|
19
|
+
info { "Received mail (#{event.duration.round(1)}ms)" }
|
20
20
|
debug { event.payload[:mail] }
|
21
21
|
end
|
22
22
|
|
@@ -25,11 +25,11 @@ module ActionMailer
|
|
25
25
|
debug do
|
26
26
|
mailer = event.payload[:mailer]
|
27
27
|
action = event.payload[:action]
|
28
|
-
"
|
28
|
+
"#{mailer}##{action}: processed outbound mail in #{event.duration.round(1)}ms"
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
32
|
-
# Use the logger configured for ActionMailer::Base
|
32
|
+
# Use the logger configured for ActionMailer::Base.
|
33
33
|
def logger
|
34
34
|
ActionMailer::Base.logger
|
35
35
|
end
|
@@ -4,7 +4,17 @@ module ActionMailer
|
|
4
4
|
# attachments list.
|
5
5
|
module MailHelper
|
6
6
|
# Take the text and format it, indented two spaces for each line, and
|
7
|
-
# wrapped at 72 columns
|
7
|
+
# wrapped at 72 columns:
|
8
|
+
#
|
9
|
+
# text = <<-TEXT
|
10
|
+
# This is
|
11
|
+
# the paragraph.
|
12
|
+
#
|
13
|
+
# * item1 * item2
|
14
|
+
# TEXT
|
15
|
+
#
|
16
|
+
# block_format text
|
17
|
+
# # => " This is the paragraph.\n\n * item1\n * item2\n"
|
8
18
|
def block_format(text)
|
9
19
|
formatted = text.split(/\n\r?\n/).collect { |paragraph|
|
10
20
|
format_paragraph(paragraph)
|
@@ -33,6 +43,8 @@ module ActionMailer
|
|
33
43
|
end
|
34
44
|
|
35
45
|
# Returns +text+ wrapped at +len+ columns and indented +indent+ spaces.
|
46
|
+
# By default column length +len+ equals 72 characters and indent
|
47
|
+
# +indent+ equal two spaces.
|
36
48
|
#
|
37
49
|
# my_text = 'Here is a sample text with more than 40 characters'
|
38
50
|
#
|
@@ -1,5 +1,4 @@
|
|
1
1
|
require 'delegate'
|
2
|
-
require 'active_support/core_ext/string/filters'
|
3
2
|
|
4
3
|
module ActionMailer
|
5
4
|
|
@@ -22,7 +21,11 @@ module ActionMailer
|
|
22
21
|
end
|
23
22
|
|
24
23
|
def __getobj__ #:nodoc:
|
25
|
-
@obj ||=
|
24
|
+
@obj ||= begin
|
25
|
+
mailer = @mailer.new
|
26
|
+
mailer.process @mail_method, *@args
|
27
|
+
mailer.message
|
28
|
+
end
|
26
29
|
end
|
27
30
|
|
28
31
|
def __setobj__(obj) #:nodoc:
|
@@ -61,9 +64,9 @@ module ActionMailer
|
|
61
64
|
#
|
62
65
|
# Options:
|
63
66
|
#
|
64
|
-
# * <tt>:wait</tt> - Enqueue the email to be delivered with a delay
|
65
|
-
# * <tt>:wait_until</tt> - Enqueue the email to be delivered at (after) a specific date / time
|
66
|
-
# * <tt>:queue</tt> - Enqueue the email on the specified queue
|
67
|
+
# * <tt>:wait</tt> - Enqueue the email to be delivered with a delay.
|
68
|
+
# * <tt>:wait_until</tt> - Enqueue the email to be delivered at (after) a specific date / time.
|
69
|
+
# * <tt>:queue</tt> - Enqueue the email on the specified queue.
|
67
70
|
def deliver_later(options={})
|
68
71
|
enqueue_delivery :deliver_now, options
|
69
72
|
end
|
@@ -85,26 +88,6 @@ module ActionMailer
|
|
85
88
|
message.deliver
|
86
89
|
end
|
87
90
|
|
88
|
-
def deliver! #:nodoc:
|
89
|
-
ActiveSupport::Deprecation.warn(<<-MSG.squish)
|
90
|
-
`#deliver!` is deprecated and will be removed in Rails 5. Use
|
91
|
-
`#deliver_now!` to deliver immediately or `#deliver_later!` to
|
92
|
-
deliver through Active Job.
|
93
|
-
MSG
|
94
|
-
|
95
|
-
deliver_now!
|
96
|
-
end
|
97
|
-
|
98
|
-
def deliver #:nodoc:
|
99
|
-
ActiveSupport::Deprecation.warn(<<-MSG.squish)
|
100
|
-
`#deliver` is deprecated and will be removed in Rails 5. Use
|
101
|
-
`#deliver_now` to deliver immediately or `#deliver_later` to
|
102
|
-
deliver through Active Job.
|
103
|
-
MSG
|
104
|
-
|
105
|
-
deliver_now
|
106
|
-
end
|
107
|
-
|
108
91
|
private
|
109
92
|
|
110
93
|
def enqueue_delivery(delivery_method, options={})
|
@@ -21,7 +21,7 @@ module ActionMailer
|
|
21
21
|
|
22
22
|
# :nodoc:
|
23
23
|
mattr_accessor :preview_interceptors, instance_writer: false
|
24
|
-
self.preview_interceptors = []
|
24
|
+
self.preview_interceptors = [ActionMailer::InlinePreviewInterceptor]
|
25
25
|
end
|
26
26
|
|
27
27
|
module ClassMethods
|
@@ -52,7 +52,7 @@ module ActionMailer
|
|
52
52
|
extend ActiveSupport::DescendantsTracker
|
53
53
|
|
54
54
|
class << self
|
55
|
-
# Returns all mailer preview classes
|
55
|
+
# Returns all mailer preview classes.
|
56
56
|
def all
|
57
57
|
load_previews if descendants.empty?
|
58
58
|
descendants
|
@@ -68,27 +68,27 @@ module ActionMailer
|
|
68
68
|
message
|
69
69
|
end
|
70
70
|
|
71
|
-
# Returns all of the available email previews
|
71
|
+
# Returns all of the available email previews.
|
72
72
|
def emails
|
73
73
|
public_instance_methods(false).map(&:to_s).sort
|
74
74
|
end
|
75
75
|
|
76
|
-
# Returns true if the email exists
|
76
|
+
# Returns true if the email exists.
|
77
77
|
def email_exists?(email)
|
78
78
|
emails.include?(email)
|
79
79
|
end
|
80
80
|
|
81
|
-
# Returns true if the preview exists
|
81
|
+
# Returns true if the preview exists.
|
82
82
|
def exists?(preview)
|
83
83
|
all.any?{ |p| p.preview_name == preview }
|
84
84
|
end
|
85
85
|
|
86
|
-
# Find a mailer preview by its underscored class name
|
86
|
+
# Find a mailer preview by its underscored class name.
|
87
87
|
def find(preview)
|
88
88
|
all.find{ |p| p.preview_name == preview }
|
89
89
|
end
|
90
90
|
|
91
|
-
# Returns the underscored name of the mailer preview without the suffix
|
91
|
+
# Returns the underscored name of the mailer preview without the suffix.
|
92
92
|
def preview_name
|
93
93
|
name.sub(/Preview$/, '').underscore
|
94
94
|
end
|
@@ -16,6 +16,11 @@ module ActionMailer
|
|
16
16
|
paths = app.config.paths
|
17
17
|
options = app.config.action_mailer
|
18
18
|
|
19
|
+
if app.config.force_ssl
|
20
|
+
options.default_url_options ||= {}
|
21
|
+
options.default_url_options[:protocol] ||= 'https'
|
22
|
+
end
|
23
|
+
|
19
24
|
options.assets_dir ||= paths["public"].first
|
20
25
|
options.javascripts_dir ||= paths["public/javascripts"].first
|
21
26
|
options.stylesheets_dir ||= paths["public/stylesheets"].first
|
@@ -41,7 +46,7 @@ module ActionMailer
|
|
41
46
|
options.each { |k,v| send("#{k}=", v) }
|
42
47
|
|
43
48
|
if options.show_previews
|
44
|
-
app.routes.
|
49
|
+
app.routes.prepend do
|
45
50
|
get '/rails/mailers' => "rails/mailers#index"
|
46
51
|
get '/rails/mailers/*path' => "rails/mailers#preview"
|
47
52
|
end
|
@@ -57,29 +57,28 @@ module ActionMailer
|
|
57
57
|
|
58
58
|
protected
|
59
59
|
|
60
|
-
def initialize_test_deliveries
|
60
|
+
def initialize_test_deliveries # :nodoc:
|
61
61
|
set_delivery_method :test
|
62
62
|
@old_perform_deliveries = ActionMailer::Base.perform_deliveries
|
63
63
|
ActionMailer::Base.perform_deliveries = true
|
64
|
-
ActionMailer::Base.deliveries.clear
|
65
64
|
end
|
66
65
|
|
67
|
-
def restore_test_deliveries
|
66
|
+
def restore_test_deliveries # :nodoc:
|
68
67
|
restore_delivery_method
|
69
68
|
ActionMailer::Base.perform_deliveries = @old_perform_deliveries
|
69
|
+
ActionMailer::Base.deliveries.clear
|
70
70
|
end
|
71
71
|
|
72
|
-
def set_delivery_method(method)
|
72
|
+
def set_delivery_method(method) # :nodoc:
|
73
73
|
@old_delivery_method = ActionMailer::Base.delivery_method
|
74
74
|
ActionMailer::Base.delivery_method = method
|
75
75
|
end
|
76
76
|
|
77
|
-
def restore_delivery_method
|
78
|
-
ActionMailer::Base.deliveries.clear
|
77
|
+
def restore_delivery_method # :nodoc:
|
79
78
|
ActionMailer::Base.delivery_method = @old_delivery_method
|
80
79
|
end
|
81
80
|
|
82
|
-
def set_expected_mail
|
81
|
+
def set_expected_mail # :nodoc:
|
83
82
|
@expected = Mail.new
|
84
83
|
@expected.content_type ["text", "plain", { "charset" => charset }]
|
85
84
|
@expected.mime_version = '1.0'
|
@@ -1,7 +1,11 @@
|
|
1
|
+
require 'active_job'
|
2
|
+
|
1
3
|
module ActionMailer
|
2
4
|
# Provides helper methods for testing Action Mailer, including #assert_emails
|
3
|
-
# and #assert_no_emails
|
5
|
+
# and #assert_no_emails.
|
4
6
|
module TestHelper
|
7
|
+
include ActiveJob::TestHelper
|
8
|
+
|
5
9
|
# Asserts that the number of emails sent matches the given number.
|
6
10
|
#
|
7
11
|
# def test_emails
|
@@ -36,7 +40,7 @@ module ActionMailer
|
|
36
40
|
end
|
37
41
|
end
|
38
42
|
|
39
|
-
#
|
43
|
+
# Asserts that no emails have been sent.
|
40
44
|
#
|
41
45
|
# def test_emails
|
42
46
|
# assert_no_emails
|
@@ -58,5 +62,52 @@ module ActionMailer
|
|
58
62
|
def assert_no_emails(&block)
|
59
63
|
assert_emails 0, &block
|
60
64
|
end
|
65
|
+
|
66
|
+
# Asserts that the number of emails enqueued for later delivery matches
|
67
|
+
# the given number.
|
68
|
+
#
|
69
|
+
# def test_emails
|
70
|
+
# assert_enqueued_emails 0
|
71
|
+
# ContactMailer.welcome.deliver_later
|
72
|
+
# assert_enqueued_emails 1
|
73
|
+
# ContactMailer.welcome.deliver_later
|
74
|
+
# assert_enqueued_emails 2
|
75
|
+
# end
|
76
|
+
#
|
77
|
+
# If a block is passed, that block should cause the specified number of
|
78
|
+
# emails to be enqueued.
|
79
|
+
#
|
80
|
+
# def test_emails_again
|
81
|
+
# assert_enqueued_emails 1 do
|
82
|
+
# ContactMailer.welcome.deliver_later
|
83
|
+
# end
|
84
|
+
#
|
85
|
+
# assert_enqueued_emails 2 do
|
86
|
+
# ContactMailer.welcome.deliver_later
|
87
|
+
# ContactMailer.welcome.deliver_later
|
88
|
+
# end
|
89
|
+
# end
|
90
|
+
def assert_enqueued_emails(number, &block)
|
91
|
+
assert_enqueued_jobs number, only: ActionMailer::DeliveryJob, &block
|
92
|
+
end
|
93
|
+
|
94
|
+
# Asserts that no emails are enqueued for later delivery.
|
95
|
+
#
|
96
|
+
# def test_no_emails
|
97
|
+
# assert_no_enqueued_emails
|
98
|
+
# ContactMailer.welcome.deliver_later
|
99
|
+
# assert_enqueued_emails 1
|
100
|
+
# end
|
101
|
+
#
|
102
|
+
# If a block is provided, it should not cause any emails to be enqueued.
|
103
|
+
#
|
104
|
+
# def test_no_emails
|
105
|
+
# assert_no_enqueued_emails do
|
106
|
+
# # No emails should be enqueued from this block
|
107
|
+
# end
|
108
|
+
# end
|
109
|
+
def assert_no_enqueued_emails(&block)
|
110
|
+
assert_no_enqueued_jobs only: ActionMailer::DeliveryJob, &block
|
111
|
+
end
|
61
112
|
end
|
62
113
|
end
|
@@ -11,7 +11,7 @@ Example:
|
|
11
11
|
rails generate mailer Notifications signup forgot_password invoice
|
12
12
|
|
13
13
|
creates a Notifications mailer class, views, and test:
|
14
|
-
Mailer: app/mailers/
|
15
|
-
Views: app/views/
|
16
|
-
Test: test/mailers/
|
14
|
+
Mailer: app/mailers/notifications_mailer.rb
|
15
|
+
Views: app/views/notifications_mailer/signup.text.erb [...]
|
16
|
+
Test: test/mailers/notifications_mailer_test.rb
|
17
17
|
|
@@ -4,16 +4,19 @@ module Rails
|
|
4
4
|
source_root File.expand_path("../templates", __FILE__)
|
5
5
|
|
6
6
|
argument :actions, type: :array, default: [], banner: "method method"
|
7
|
-
|
7
|
+
|
8
|
+
check_class_collision suffix: "Mailer"
|
8
9
|
|
9
10
|
def create_mailer_file
|
10
|
-
template "mailer.rb", File.join('app/mailers', class_path, "#{file_name}.rb")
|
11
|
-
if self.behavior == :invoke
|
12
|
-
template "application_mailer.rb", 'app/mailers/application_mailer.rb'
|
13
|
-
end
|
11
|
+
template "mailer.rb", File.join('app/mailers', class_path, "#{file_name}_mailer.rb")
|
14
12
|
end
|
15
13
|
|
16
14
|
hook_for :template_engine, :test_framework
|
15
|
+
|
16
|
+
protected
|
17
|
+
def file_name
|
18
|
+
@_file_name ||= super.gsub(/\_mailer/i, '')
|
19
|
+
end
|
17
20
|
end
|
18
21
|
end
|
19
22
|
end
|
@@ -1,11 +1,11 @@
|
|
1
1
|
<% module_namespacing do -%>
|
2
|
-
class <%= class_name %> < ApplicationMailer
|
2
|
+
class <%= class_name %>Mailer < ApplicationMailer
|
3
3
|
<% actions.each do |action| -%>
|
4
4
|
|
5
5
|
# Subject can be set in your I18n file at config/locales/en.yml
|
6
6
|
# with the following lookup:
|
7
7
|
#
|
8
|
-
# en.<%= file_path.tr("/",".")
|
8
|
+
# en.<%= file_path.tr("/",".") %>_mailer.<%= action %>.subject
|
9
9
|
#
|
10
10
|
def <%= action %>
|
11
11
|
@greeting = "Hi"
|
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: 5.0.0.beta1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Heinemeier Hansson
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-12-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: 5.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: 5.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: 5.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: 5.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: 5.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: 5.0.0.beta1
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: mail
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -119,9 +119,8 @@ files:
|
|
119
119
|
- lib/action_mailer/version.rb
|
120
120
|
- lib/rails/generators/mailer/USAGE
|
121
121
|
- lib/rails/generators/mailer/mailer_generator.rb
|
122
|
-
- lib/rails/generators/mailer/templates/application_mailer.rb
|
123
122
|
- lib/rails/generators/mailer/templates/mailer.rb
|
124
|
-
homepage: http://
|
123
|
+
homepage: http://rubyonrails.org
|
125
124
|
licenses:
|
126
125
|
- MIT
|
127
126
|
metadata: {}
|
@@ -133,16 +132,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
133
132
|
requirements:
|
134
133
|
- - ">="
|
135
134
|
- !ruby/object:Gem::Version
|
136
|
-
version:
|
135
|
+
version: 2.2.2
|
137
136
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
138
137
|
requirements:
|
139
|
-
- - "
|
138
|
+
- - ">"
|
140
139
|
- !ruby/object:Gem::Version
|
141
|
-
version:
|
140
|
+
version: 1.3.1
|
142
141
|
requirements:
|
143
142
|
- none
|
144
|
-
|
143
|
+
rubyforge_project:
|
144
|
+
rubygems_version: 2.5.1
|
145
145
|
signing_key:
|
146
146
|
specification_version: 4
|
147
147
|
summary: Email composition, delivery, and receiving framework (part of Rails).
|
148
148
|
test_files: []
|
149
|
+
has_rdoc:
|