actionmailer 6.0.0
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 +7 -0
- data/CHANGELOG.md +96 -0
- data/MIT-LICENSE +21 -0
- data/README.rdoc +141 -0
- data/lib/action_mailer.rb +70 -0
- data/lib/action_mailer/base.rb +1026 -0
- data/lib/action_mailer/collector.rb +32 -0
- data/lib/action_mailer/delivery_job.rb +44 -0
- data/lib/action_mailer/delivery_methods.rb +82 -0
- data/lib/action_mailer/gem_version.rb +17 -0
- data/lib/action_mailer/inline_preview_interceptor.rb +57 -0
- data/lib/action_mailer/log_subscriber.rb +45 -0
- data/lib/action_mailer/mail_delivery_job.rb +38 -0
- data/lib/action_mailer/mail_helper.rb +72 -0
- data/lib/action_mailer/message_delivery.rb +152 -0
- data/lib/action_mailer/parameterized.rb +171 -0
- data/lib/action_mailer/preview.rb +143 -0
- data/lib/action_mailer/railtie.rb +93 -0
- data/lib/action_mailer/rescuable.rb +29 -0
- data/lib/action_mailer/test_case.rb +123 -0
- data/lib/action_mailer/test_helper.rb +162 -0
- data/lib/action_mailer/version.rb +11 -0
- data/lib/rails/generators/mailer/USAGE +17 -0
- data/lib/rails/generators/mailer/mailer_generator.rb +38 -0
- data/lib/rails/generators/mailer/templates/application_mailer.rb.tt +6 -0
- data/lib/rails/generators/mailer/templates/mailer.rb.tt +17 -0
- metadata +147 -0
@@ -0,0 +1,162 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "active_job"
|
4
|
+
|
5
|
+
module ActionMailer
|
6
|
+
# Provides helper methods for testing Action Mailer, including #assert_emails
|
7
|
+
# and #assert_no_emails.
|
8
|
+
module TestHelper
|
9
|
+
include ActiveJob::TestHelper
|
10
|
+
|
11
|
+
# Asserts that the number of emails sent matches the given number.
|
12
|
+
#
|
13
|
+
# def test_emails
|
14
|
+
# assert_emails 0
|
15
|
+
# ContactMailer.welcome.deliver_now
|
16
|
+
# assert_emails 1
|
17
|
+
# ContactMailer.welcome.deliver_now
|
18
|
+
# assert_emails 2
|
19
|
+
# end
|
20
|
+
#
|
21
|
+
# If a block is passed, that block should cause the specified number of
|
22
|
+
# emails to be sent.
|
23
|
+
#
|
24
|
+
# def test_emails_again
|
25
|
+
# assert_emails 1 do
|
26
|
+
# ContactMailer.welcome.deliver_now
|
27
|
+
# end
|
28
|
+
#
|
29
|
+
# assert_emails 2 do
|
30
|
+
# ContactMailer.welcome.deliver_now
|
31
|
+
# ContactMailer.welcome.deliver_later
|
32
|
+
# end
|
33
|
+
# end
|
34
|
+
def assert_emails(number, &block)
|
35
|
+
if block_given?
|
36
|
+
original_count = ActionMailer::Base.deliveries.size
|
37
|
+
perform_enqueued_jobs(only: ->(job) { delivery_job_filter(job) }, &block)
|
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"
|
40
|
+
else
|
41
|
+
assert_equal number, ActionMailer::Base.deliveries.size
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
# Asserts that no emails have been sent.
|
46
|
+
#
|
47
|
+
# def test_emails
|
48
|
+
# assert_no_emails
|
49
|
+
# ContactMailer.welcome.deliver_now
|
50
|
+
# assert_emails 1
|
51
|
+
# end
|
52
|
+
#
|
53
|
+
# If a block is passed, that block should not cause any emails to be sent.
|
54
|
+
#
|
55
|
+
# def test_emails_again
|
56
|
+
# assert_no_emails do
|
57
|
+
# # No emails should be sent from this block
|
58
|
+
# end
|
59
|
+
# end
|
60
|
+
#
|
61
|
+
# Note: This assertion is simply a shortcut for:
|
62
|
+
#
|
63
|
+
# assert_emails 0, &block
|
64
|
+
def assert_no_emails(&block)
|
65
|
+
assert_emails 0, &block
|
66
|
+
end
|
67
|
+
|
68
|
+
# Asserts that the number of emails enqueued for later delivery matches
|
69
|
+
# the given number.
|
70
|
+
#
|
71
|
+
# def test_emails
|
72
|
+
# assert_enqueued_emails 0
|
73
|
+
# ContactMailer.welcome.deliver_later
|
74
|
+
# assert_enqueued_emails 1
|
75
|
+
# ContactMailer.welcome.deliver_later
|
76
|
+
# assert_enqueued_emails 2
|
77
|
+
# end
|
78
|
+
#
|
79
|
+
# If a block is passed, that block should cause the specified number of
|
80
|
+
# emails to be enqueued.
|
81
|
+
#
|
82
|
+
# def test_emails_again
|
83
|
+
# assert_enqueued_emails 1 do
|
84
|
+
# ContactMailer.welcome.deliver_later
|
85
|
+
# end
|
86
|
+
#
|
87
|
+
# assert_enqueued_emails 2 do
|
88
|
+
# ContactMailer.welcome.deliver_later
|
89
|
+
# ContactMailer.welcome.deliver_later
|
90
|
+
# end
|
91
|
+
# end
|
92
|
+
def assert_enqueued_emails(number, &block)
|
93
|
+
assert_enqueued_jobs(number, only: ->(job) { delivery_job_filter(job) }, &block)
|
94
|
+
end
|
95
|
+
|
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
|
110
|
+
# to be enqueued.
|
111
|
+
#
|
112
|
+
# def test_email_in_block
|
113
|
+
# assert_enqueued_email_with ContactMailer, :welcome do
|
114
|
+
# ContactMailer.welcome.deliver_later
|
115
|
+
# end
|
116
|
+
# end
|
117
|
+
#
|
118
|
+
# If +args+ is provided as a Hash, a parameterized email is matched.
|
119
|
+
#
|
120
|
+
# def test_parameterized_email
|
121
|
+
# assert_enqueued_email_with ContactMailer, :welcome,
|
122
|
+
# args: {email: 'user@example.com'} do
|
123
|
+
# ContactMailer.with(email: 'user@example.com').welcome.deliver_later
|
124
|
+
# end
|
125
|
+
# end
|
126
|
+
def assert_enqueued_email_with(mailer, method, args: nil, queue: "mailers", &block)
|
127
|
+
args = if args.is_a?(Hash)
|
128
|
+
[mailer.to_s, method.to_s, "deliver_now", params: args, args: []]
|
129
|
+
else
|
130
|
+
[mailer.to_s, method.to_s, "deliver_now", args: Array(args)]
|
131
|
+
end
|
132
|
+
assert_enqueued_with(job: mailer.delivery_job, args: args, queue: queue, &block)
|
133
|
+
end
|
134
|
+
|
135
|
+
# Asserts that no emails are enqueued for later delivery.
|
136
|
+
#
|
137
|
+
# def test_no_emails
|
138
|
+
# assert_no_enqueued_emails
|
139
|
+
# ContactMailer.welcome.deliver_later
|
140
|
+
# assert_enqueued_emails 1
|
141
|
+
# end
|
142
|
+
#
|
143
|
+
# If a block is provided, it should not cause any emails to be enqueued.
|
144
|
+
#
|
145
|
+
# def test_no_emails
|
146
|
+
# assert_no_enqueued_emails do
|
147
|
+
# # No emails should be enqueued from this block
|
148
|
+
# end
|
149
|
+
# end
|
150
|
+
def assert_no_enqueued_emails(&block)
|
151
|
+
assert_enqueued_emails 0, &block
|
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
|
161
|
+
end
|
162
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
Description:
|
2
|
+
============
|
3
|
+
Stubs out a new mailer and its views. Passes the mailer name, either
|
4
|
+
CamelCased or under_scored, and an optional list of emails as arguments.
|
5
|
+
|
6
|
+
This generates a mailer class in app/mailers and invokes your template
|
7
|
+
engine and test framework generators.
|
8
|
+
|
9
|
+
Example:
|
10
|
+
========
|
11
|
+
rails generate mailer Notifications signup forgot_password invoice
|
12
|
+
|
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
|
17
|
+
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Rails
|
4
|
+
module Generators
|
5
|
+
class MailerGenerator < NamedBase
|
6
|
+
source_root File.expand_path("templates", __dir__)
|
7
|
+
|
8
|
+
argument :actions, type: :array, default: [], banner: "method method"
|
9
|
+
|
10
|
+
check_class_collision suffix: "Mailer"
|
11
|
+
|
12
|
+
def create_mailer_file
|
13
|
+
template "mailer.rb", File.join("app/mailers", class_path, "#{file_name}_mailer.rb")
|
14
|
+
|
15
|
+
in_root do
|
16
|
+
if behavior == :invoke && !File.exist?(application_mailer_file_name)
|
17
|
+
template "application_mailer.rb", application_mailer_file_name
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
hook_for :template_engine, :test_framework
|
23
|
+
|
24
|
+
private
|
25
|
+
def file_name # :doc:
|
26
|
+
@_file_name ||= super.sub(/_mailer\z/i, "")
|
27
|
+
end
|
28
|
+
|
29
|
+
def application_mailer_file_name
|
30
|
+
@_application_mailer_file_name ||= if mountable_engine?
|
31
|
+
"app/mailers/#{namespaced_path}/application_mailer.rb"
|
32
|
+
else
|
33
|
+
"app/mailers/application_mailer.rb"
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
<% module_namespacing do -%>
|
2
|
+
class <%= class_name %>Mailer < ApplicationMailer
|
3
|
+
<% actions.each do |action| -%>
|
4
|
+
|
5
|
+
# Subject can be set in your I18n file at config/locales/en.yml
|
6
|
+
# with the following lookup:
|
7
|
+
#
|
8
|
+
# en.<%= file_path.tr("/",".") %>_mailer.<%= action %>.subject
|
9
|
+
#
|
10
|
+
def <%= action %>
|
11
|
+
@greeting = "Hi"
|
12
|
+
|
13
|
+
mail to: "to@example.org"
|
14
|
+
end
|
15
|
+
<% end -%>
|
16
|
+
end
|
17
|
+
<% end -%>
|
metadata
ADDED
@@ -0,0 +1,147 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: actionmailer
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 6.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- David Heinemeier Hansson
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-08-16 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: actionpack
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 6.0.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 6.0.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: actionview
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 6.0.0
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 6.0.0
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: activejob
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 6.0.0
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 6.0.0
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: mail
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '2.5'
|
62
|
+
- - ">="
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: 2.5.4
|
65
|
+
type: :runtime
|
66
|
+
prerelease: false
|
67
|
+
version_requirements: !ruby/object:Gem::Requirement
|
68
|
+
requirements:
|
69
|
+
- - "~>"
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: '2.5'
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: 2.5.4
|
75
|
+
- !ruby/object:Gem::Dependency
|
76
|
+
name: rails-dom-testing
|
77
|
+
requirement: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - "~>"
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '2.0'
|
82
|
+
type: :runtime
|
83
|
+
prerelease: false
|
84
|
+
version_requirements: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - "~>"
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '2.0'
|
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
|
+
email: david@loudthinking.com
|
92
|
+
executables: []
|
93
|
+
extensions: []
|
94
|
+
extra_rdoc_files: []
|
95
|
+
files:
|
96
|
+
- CHANGELOG.md
|
97
|
+
- MIT-LICENSE
|
98
|
+
- README.rdoc
|
99
|
+
- lib/action_mailer.rb
|
100
|
+
- lib/action_mailer/base.rb
|
101
|
+
- lib/action_mailer/collector.rb
|
102
|
+
- lib/action_mailer/delivery_job.rb
|
103
|
+
- lib/action_mailer/delivery_methods.rb
|
104
|
+
- lib/action_mailer/gem_version.rb
|
105
|
+
- lib/action_mailer/inline_preview_interceptor.rb
|
106
|
+
- lib/action_mailer/log_subscriber.rb
|
107
|
+
- lib/action_mailer/mail_delivery_job.rb
|
108
|
+
- lib/action_mailer/mail_helper.rb
|
109
|
+
- lib/action_mailer/message_delivery.rb
|
110
|
+
- lib/action_mailer/parameterized.rb
|
111
|
+
- lib/action_mailer/preview.rb
|
112
|
+
- lib/action_mailer/railtie.rb
|
113
|
+
- lib/action_mailer/rescuable.rb
|
114
|
+
- lib/action_mailer/test_case.rb
|
115
|
+
- lib/action_mailer/test_helper.rb
|
116
|
+
- lib/action_mailer/version.rb
|
117
|
+
- lib/rails/generators/mailer/USAGE
|
118
|
+
- lib/rails/generators/mailer/mailer_generator.rb
|
119
|
+
- lib/rails/generators/mailer/templates/application_mailer.rb.tt
|
120
|
+
- lib/rails/generators/mailer/templates/mailer.rb.tt
|
121
|
+
homepage: https://rubyonrails.org
|
122
|
+
licenses:
|
123
|
+
- MIT
|
124
|
+
metadata:
|
125
|
+
source_code_uri: https://github.com/rails/rails/tree/v6.0.0/actionmailer
|
126
|
+
changelog_uri: https://github.com/rails/rails/blob/v6.0.0/actionmailer/CHANGELOG.md
|
127
|
+
post_install_message:
|
128
|
+
rdoc_options: []
|
129
|
+
require_paths:
|
130
|
+
- lib
|
131
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
132
|
+
requirements:
|
133
|
+
- - ">="
|
134
|
+
- !ruby/object:Gem::Version
|
135
|
+
version: 2.5.0
|
136
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
137
|
+
requirements:
|
138
|
+
- - ">="
|
139
|
+
- !ruby/object:Gem::Version
|
140
|
+
version: '0'
|
141
|
+
requirements:
|
142
|
+
- none
|
143
|
+
rubygems_version: 3.0.1
|
144
|
+
signing_key:
|
145
|
+
specification_version: 4
|
146
|
+
summary: Email composition and delivery framework (part of Rails).
|
147
|
+
test_files: []
|