actionmailer 7.0.8.7 → 7.1.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +109 -75
- data/MIT-LICENSE +1 -1
- data/README.rdoc +2 -2
- data/lib/action_mailer/base.rb +58 -46
- data/lib/action_mailer/callbacks.rb +31 -0
- data/lib/action_mailer/delivery_methods.rb +5 -3
- data/lib/action_mailer/deprecator.rb +7 -0
- data/lib/action_mailer/form_builder.rb +37 -0
- data/lib/action_mailer/gem_version.rb +4 -4
- data/lib/action_mailer/inline_preview_interceptor.rb +2 -0
- data/lib/action_mailer/log_subscriber.rb +7 -2
- data/lib/action_mailer/mail_delivery_job.rb +7 -2
- data/lib/action_mailer/mail_helper.rb +2 -0
- data/lib/action_mailer/message_delivery.rb +20 -12
- data/lib/action_mailer/parameterized.rb +7 -1
- data/lib/action_mailer/preview.rb +32 -8
- data/lib/action_mailer/queued_delivery.rb +12 -0
- data/lib/action_mailer/railtie.rb +11 -16
- data/lib/action_mailer/rescuable.rb +2 -0
- data/lib/action_mailer/test_case.rb +9 -4
- data/lib/action_mailer/test_helper.rb +134 -11
- data/lib/action_mailer/version.rb +1 -1
- data/lib/action_mailer.rb +11 -2
- data/lib/rails/generators/mailer/USAGE +12 -8
- metadata +18 -14
@@ -1,5 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require "active_support/core_ext/array/extract_options"
|
3
4
|
require "active_job"
|
4
5
|
|
5
6
|
module ActionMailer
|
@@ -33,10 +34,8 @@ module ActionMailer
|
|
33
34
|
# end
|
34
35
|
def assert_emails(number, &block)
|
35
36
|
if block_given?
|
36
|
-
|
37
|
-
|
38
|
-
new_count = ActionMailer::Base.deliveries.size
|
39
|
-
assert_equal number, new_count - original_count, "#{number} emails expected, but #{new_count - original_count} were sent"
|
37
|
+
diff = capture_emails(&block).length
|
38
|
+
assert_equal number, diff, "#{number} emails expected, but #{diff} were sent"
|
40
39
|
else
|
41
40
|
assert_equal number, ActionMailer::Base.deliveries.size
|
42
41
|
end
|
@@ -94,18 +93,50 @@ module ActionMailer
|
|
94
93
|
end
|
95
94
|
|
96
95
|
# Asserts that a specific email has been enqueued, optionally
|
97
|
-
# matching arguments.
|
96
|
+
# matching arguments and/or params.
|
98
97
|
#
|
99
98
|
# def test_email
|
100
99
|
# ContactMailer.welcome.deliver_later
|
101
100
|
# assert_enqueued_email_with ContactMailer, :welcome
|
102
101
|
# end
|
103
102
|
#
|
103
|
+
# def test_email_with_parameters
|
104
|
+
# ContactMailer.with(greeting: "Hello").welcome.deliver_later
|
105
|
+
# assert_enqueued_email_with ContactMailer, :welcome, args: { greeting: "Hello" }
|
106
|
+
# end
|
107
|
+
#
|
104
108
|
# def test_email_with_arguments
|
105
109
|
# ContactMailer.welcome("Hello", "Goodbye").deliver_later
|
106
110
|
# assert_enqueued_email_with ContactMailer, :welcome, args: ["Hello", "Goodbye"]
|
107
111
|
# end
|
108
112
|
#
|
113
|
+
# def test_email_with_named_arguments
|
114
|
+
# ContactMailer.welcome(greeting: "Hello", farewell: "Goodbye").deliver_later
|
115
|
+
# assert_enqueued_email_with ContactMailer, :welcome, args: [{ greeting: "Hello", farewell: "Goodbye" }]
|
116
|
+
# end
|
117
|
+
#
|
118
|
+
# def test_email_with_parameters_and_arguments
|
119
|
+
# ContactMailer.with(greeting: "Hello").welcome("Cheers", "Goodbye").deliver_later
|
120
|
+
# assert_enqueued_email_with ContactMailer, :welcome, params: { greeting: "Hello" }, args: ["Cheers", "Goodbye"]
|
121
|
+
# end
|
122
|
+
#
|
123
|
+
# def test_email_with_parameters_and_named_arguments
|
124
|
+
# ContactMailer.with(greeting: "Hello").welcome(farewell: "Goodbye").deliver_later
|
125
|
+
# assert_enqueued_email_with ContactMailer, :welcome, params: { greeting: "Hello" }, args: [{farewell: "Goodbye"}]
|
126
|
+
# end
|
127
|
+
#
|
128
|
+
# def test_email_with_parameterized_mailer
|
129
|
+
# ContactMailer.with(greeting: "Hello").welcome.deliver_later
|
130
|
+
# assert_enqueued_email_with ContactMailer.with(greeting: "Hello"), :welcome
|
131
|
+
# end
|
132
|
+
#
|
133
|
+
# def test_email_with_matchers
|
134
|
+
# ContactMailer.with(greeting: "Hello").welcome("Cheers", "Goodbye").deliver_later
|
135
|
+
# assert_enqueued_email_with ContactMailer, :welcome,
|
136
|
+
# params: ->(params) { /hello/i.match?(params[:greeting]) },
|
137
|
+
# args: ->(args) { /cheers/i.match?(args[0]) }
|
138
|
+
# end
|
139
|
+
#
|
109
140
|
# If a block is passed, that block should cause the specified email
|
110
141
|
# to be enqueued.
|
111
142
|
#
|
@@ -123,13 +154,43 @@ module ActionMailer
|
|
123
154
|
# ContactMailer.with(email: 'user@example.com').welcome.deliver_later
|
124
155
|
# end
|
125
156
|
# end
|
126
|
-
def assert_enqueued_email_with(mailer, method, args: nil, queue:
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
[mailer.to_s, method.to_s, "deliver_now", args: Array(args)]
|
157
|
+
def assert_enqueued_email_with(mailer, method, params: nil, args: nil, queue: nil, &block)
|
158
|
+
if mailer.is_a? ActionMailer::Parameterized::Mailer
|
159
|
+
params = mailer.instance_variable_get(:@params)
|
160
|
+
mailer = mailer.instance_variable_get(:@mailer)
|
131
161
|
end
|
132
|
-
|
162
|
+
|
163
|
+
if args.is_a?(Hash)
|
164
|
+
ActionMailer.deprecator.warn <<~MSG
|
165
|
+
Passing a Hash to the assert_enqueued_email_with :args kwarg causes the
|
166
|
+
Hash to be treated as params. This behavior is deprecated and will be
|
167
|
+
removed in Rails 7.2.
|
168
|
+
|
169
|
+
To specify a params Hash, use the :params kwarg:
|
170
|
+
|
171
|
+
assert_enqueued_email_with MyMailer, :my_method, params: { my_param: "value" }
|
172
|
+
|
173
|
+
Or, to specify named mailer args as a Hash, wrap the Hash in an array:
|
174
|
+
|
175
|
+
assert_enqueued_email_with MyMailer, :my_method, args: [{ my_arg: "value" }]
|
176
|
+
# OR
|
177
|
+
assert_enqueued_email_with MyMailer, :my_method, args: [my_arg: "value"]
|
178
|
+
MSG
|
179
|
+
|
180
|
+
params, args = args, nil
|
181
|
+
end
|
182
|
+
|
183
|
+
args = Array(args) unless args.is_a?(Proc)
|
184
|
+
queue ||= mailer.deliver_later_queue_name || ActiveJob::Base.default_queue_name
|
185
|
+
|
186
|
+
expected = ->(job_args) do
|
187
|
+
job_kwargs = job_args.extract_options!
|
188
|
+
|
189
|
+
[mailer.to_s, method.to_s, "deliver_now"] == job_args &&
|
190
|
+
params === job_kwargs[:params] && args === job_kwargs[:args]
|
191
|
+
end
|
192
|
+
|
193
|
+
assert_enqueued_with(job: mailer.delivery_job, args: expected, queue: queue.to_s, &block)
|
133
194
|
end
|
134
195
|
|
135
196
|
# Asserts that no emails are enqueued for later delivery.
|
@@ -151,6 +212,68 @@ module ActionMailer
|
|
151
212
|
assert_enqueued_emails 0, &block
|
152
213
|
end
|
153
214
|
|
215
|
+
# Delivers all enqueued emails. If a block is given, delivers all of the emails
|
216
|
+
# that were enqueued throughout the duration of the block. If a block is
|
217
|
+
# not given, delivers all the enqueued emails up to this point in the test.
|
218
|
+
#
|
219
|
+
# def test_deliver_enqueued_emails
|
220
|
+
# deliver_enqueued_emails do
|
221
|
+
# ContactMailer.welcome.deliver_later
|
222
|
+
# end
|
223
|
+
#
|
224
|
+
# assert_emails 1
|
225
|
+
# end
|
226
|
+
#
|
227
|
+
# def test_deliver_enqueued_emails_without_block
|
228
|
+
# ContactMailer.welcome.deliver_later
|
229
|
+
#
|
230
|
+
# deliver_enqueued_emails
|
231
|
+
#
|
232
|
+
# assert_emails 1
|
233
|
+
# end
|
234
|
+
#
|
235
|
+
# If the +:queue+ option is specified,
|
236
|
+
# then only the emails(s) enqueued to a specific queue will be performed.
|
237
|
+
#
|
238
|
+
# def test_deliver_enqueued_emails_with_queue
|
239
|
+
# deliver_enqueued_emails queue: :external_mailers do
|
240
|
+
# CustomerMailer.deliver_later_queue_name = :external_mailers
|
241
|
+
# CustomerMailer.welcome.deliver_later # will be performed
|
242
|
+
# EmployeeMailer.deliver_later_queue_name = :internal_mailers
|
243
|
+
# EmployeeMailer.welcome.deliver_later # will not be performed
|
244
|
+
# end
|
245
|
+
#
|
246
|
+
# assert_emails 1
|
247
|
+
# end
|
248
|
+
#
|
249
|
+
# If the +:at+ option is specified, then only delivers emails enqueued to deliver
|
250
|
+
# immediately or before the given time.
|
251
|
+
def deliver_enqueued_emails(queue: nil, at: nil, &block)
|
252
|
+
perform_enqueued_jobs(only: ->(job) { delivery_job_filter(job) }, queue: queue, at: at, &block)
|
253
|
+
end
|
254
|
+
|
255
|
+
# Returns any emails that are sent in the block.
|
256
|
+
#
|
257
|
+
# def test_emails
|
258
|
+
# emails = capture_emails do
|
259
|
+
# ContactMailer.welcome.deliver_now
|
260
|
+
# end
|
261
|
+
# assert_equal "Hi there", emails.first.subject
|
262
|
+
#
|
263
|
+
# emails = capture_emails do
|
264
|
+
# ContactMailer.welcome.deliver_now
|
265
|
+
# ContactMailer.welcome.deliver_later
|
266
|
+
# end
|
267
|
+
# assert_equal "Hi there", emails.first.subject
|
268
|
+
# end
|
269
|
+
def capture_emails(&block)
|
270
|
+
original_count = ActionMailer::Base.deliveries.size
|
271
|
+
deliver_enqueued_emails(&block)
|
272
|
+
new_count = ActionMailer::Base.deliveries.size
|
273
|
+
diff = new_count - original_count
|
274
|
+
ActionMailer::Base.deliveries.last(diff)
|
275
|
+
end
|
276
|
+
|
154
277
|
private
|
155
278
|
def delivery_job_filter(job)
|
156
279
|
job_class = job.is_a?(Hash) ? job.fetch(:job) : job.class
|
data/lib/action_mailer.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
#--
|
4
|
-
# Copyright (c)
|
4
|
+
# Copyright (c) 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
|
@@ -25,6 +25,7 @@
|
|
25
25
|
|
26
26
|
require "abstract_controller"
|
27
27
|
require "action_mailer/version"
|
28
|
+
require "action_mailer/deprecator"
|
28
29
|
|
29
30
|
# Common Active Support usage in Action Mailer
|
30
31
|
require "active_support"
|
@@ -34,6 +35,7 @@ require "active_support/core_ext/module/attr_internal"
|
|
34
35
|
require "active_support/core_ext/string/inflections"
|
35
36
|
require "active_support/lazy_load_hooks"
|
36
37
|
|
38
|
+
# :include: ../README.rdoc
|
37
39
|
module ActionMailer
|
38
40
|
extend ::ActiveSupport::Autoload
|
39
41
|
|
@@ -42,6 +44,7 @@ module ActionMailer
|
|
42
44
|
end
|
43
45
|
|
44
46
|
autoload :Base
|
47
|
+
autoload :Callbacks
|
45
48
|
autoload :DeliveryMethods
|
46
49
|
autoload :InlinePreviewInterceptor
|
47
50
|
autoload :MailHelper
|
@@ -52,12 +55,18 @@ module ActionMailer
|
|
52
55
|
autoload :TestHelper
|
53
56
|
autoload :MessageDelivery
|
54
57
|
autoload :MailDeliveryJob
|
58
|
+
autoload :QueuedDelivery
|
59
|
+
autoload :FormBuilder
|
55
60
|
|
56
61
|
def self.eager_load!
|
57
62
|
super
|
58
63
|
|
59
64
|
require "mail"
|
60
65
|
Mail.eager_autoload!
|
66
|
+
|
67
|
+
Base.descendants.each do |mailer|
|
68
|
+
mailer.eager_load! unless mailer.abstract?
|
69
|
+
end
|
61
70
|
end
|
62
71
|
end
|
63
72
|
|
@@ -65,6 +74,6 @@ autoload :Mime, "action_dispatch/http/mime_type"
|
|
65
74
|
|
66
75
|
ActiveSupport.on_load(:action_view) do
|
67
76
|
ActionView::Base.default_formats ||= Mime::SET.symbols
|
68
|
-
ActionView::Template
|
77
|
+
ActionView::Template.mime_types_implementation = Mime
|
69
78
|
ActionView::LookupContext::DetailsKey.clear
|
70
79
|
end
|
@@ -1,16 +1,20 @@
|
|
1
1
|
Description:
|
2
|
-
============
|
3
2
|
Generates a new mailer and its views. Passes the mailer name, either
|
4
3
|
CamelCased or under_scored, and an optional list of emails as arguments.
|
5
4
|
|
6
5
|
This generates a mailer class in app/mailers and invokes your template
|
7
6
|
engine and test framework generators.
|
8
7
|
|
9
|
-
|
10
|
-
|
11
|
-
|
8
|
+
Examples:
|
9
|
+
`bin/rails generate mailer sign_up`
|
10
|
+
|
11
|
+
creates a sign up mailer class, views, and test:
|
12
|
+
Mailer: app/mailers/sign_up_mailer.rb
|
13
|
+
Views: app/views/sign_up_mailer/signup.text.erb [...]
|
14
|
+
Test: test/mailers/sign_up_mailer_test.rb
|
15
|
+
|
16
|
+
`bin/rails generate mailer notifications sign_up forgot_password invoice`
|
17
|
+
|
18
|
+
creates a notifications mailer with sign_up, forgot_password, and invoice actions.
|
19
|
+
|
12
20
|
|
13
|
-
creates a Notifications mailer class, views, and test:
|
14
|
-
Mailer: app/mailers/notifications_mailer.rb
|
15
|
-
Views: app/views/notifications_mailer/signup.text.erb [...]
|
16
|
-
Test: test/mailers/notifications_mailer_test.rb
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: actionmailer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 7.
|
4
|
+
version: 7.1.5.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Heinemeier Hansson
|
@@ -16,56 +16,56 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - '='
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 7.
|
19
|
+
version: 7.1.5.1
|
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: 7.
|
26
|
+
version: 7.1.5.1
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: actionpack
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - '='
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: 7.
|
33
|
+
version: 7.1.5.1
|
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: 7.
|
40
|
+
version: 7.1.5.1
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: actionview
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - '='
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: 7.
|
47
|
+
version: 7.1.5.1
|
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: 7.
|
54
|
+
version: 7.1.5.1
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: activejob
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
59
|
- - '='
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: 7.
|
61
|
+
version: 7.1.5.1
|
62
62
|
type: :runtime
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - '='
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: 7.
|
68
|
+
version: 7.1.5.1
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: mail
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -134,14 +134,14 @@ dependencies:
|
|
134
134
|
requirements:
|
135
135
|
- - "~>"
|
136
136
|
- !ruby/object:Gem::Version
|
137
|
-
version: '2.
|
137
|
+
version: '2.2'
|
138
138
|
type: :runtime
|
139
139
|
prerelease: false
|
140
140
|
version_requirements: !ruby/object:Gem::Requirement
|
141
141
|
requirements:
|
142
142
|
- - "~>"
|
143
143
|
- !ruby/object:Gem::Version
|
144
|
-
version: '2.
|
144
|
+
version: '2.2'
|
145
145
|
description: Email on Rails. Compose, deliver, and test emails using the familiar
|
146
146
|
controller/view pattern. First-class support for multipart email and attachments.
|
147
147
|
email: david@loudthinking.com
|
@@ -154,8 +154,11 @@ files:
|
|
154
154
|
- README.rdoc
|
155
155
|
- lib/action_mailer.rb
|
156
156
|
- lib/action_mailer/base.rb
|
157
|
+
- lib/action_mailer/callbacks.rb
|
157
158
|
- lib/action_mailer/collector.rb
|
158
159
|
- lib/action_mailer/delivery_methods.rb
|
160
|
+
- lib/action_mailer/deprecator.rb
|
161
|
+
- lib/action_mailer/form_builder.rb
|
159
162
|
- lib/action_mailer/gem_version.rb
|
160
163
|
- lib/action_mailer/inline_preview_interceptor.rb
|
161
164
|
- lib/action_mailer/log_subscriber.rb
|
@@ -164,6 +167,7 @@ files:
|
|
164
167
|
- lib/action_mailer/message_delivery.rb
|
165
168
|
- lib/action_mailer/parameterized.rb
|
166
169
|
- lib/action_mailer/preview.rb
|
170
|
+
- lib/action_mailer/queued_delivery.rb
|
167
171
|
- lib/action_mailer/railtie.rb
|
168
172
|
- lib/action_mailer/rescuable.rb
|
169
173
|
- lib/action_mailer/test_case.rb
|
@@ -178,10 +182,10 @@ licenses:
|
|
178
182
|
- MIT
|
179
183
|
metadata:
|
180
184
|
bug_tracker_uri: https://github.com/rails/rails/issues
|
181
|
-
changelog_uri: https://github.com/rails/rails/blob/v7.
|
182
|
-
documentation_uri: https://api.rubyonrails.org/v7.
|
185
|
+
changelog_uri: https://github.com/rails/rails/blob/v7.1.5.1/actionmailer/CHANGELOG.md
|
186
|
+
documentation_uri: https://api.rubyonrails.org/v7.1.5.1/
|
183
187
|
mailing_list_uri: https://discuss.rubyonrails.org/c/rubyonrails-talk
|
184
|
-
source_code_uri: https://github.com/rails/rails/tree/v7.
|
188
|
+
source_code_uri: https://github.com/rails/rails/tree/v7.1.5.1/actionmailer
|
185
189
|
rubygems_mfa_required: 'true'
|
186
190
|
post_install_message:
|
187
191
|
rdoc_options: []
|