omg-actionmailer 8.0.0.alpha2

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.
@@ -0,0 +1,264 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "active_support/core_ext/array/extract_options"
4
+ require "active_job"
5
+
6
+ module ActionMailer
7
+ # Provides helper methods for testing Action Mailer, including #assert_emails
8
+ # and #assert_no_emails.
9
+ module TestHelper
10
+ include ActiveJob::TestHelper
11
+
12
+ # Asserts that the number of emails sent matches the given number.
13
+ #
14
+ # def test_emails
15
+ # assert_emails 0
16
+ # ContactMailer.welcome.deliver_now
17
+ # assert_emails 1
18
+ # ContactMailer.welcome.deliver_now
19
+ # assert_emails 2
20
+ # end
21
+ #
22
+ # If a block is passed, that block should cause the specified number of
23
+ # emails to be sent.
24
+ #
25
+ # def test_emails_again
26
+ # assert_emails 1 do
27
+ # ContactMailer.welcome.deliver_now
28
+ # end
29
+ #
30
+ # assert_emails 2 do
31
+ # ContactMailer.welcome.deliver_now
32
+ # ContactMailer.welcome.deliver_later
33
+ # end
34
+ # end
35
+ def assert_emails(number, &block)
36
+ if block_given?
37
+ diff = capture_emails(&block).length
38
+ assert_equal number, diff, "#{number} emails expected, but #{diff} were sent"
39
+ else
40
+ assert_equal number, ActionMailer::Base.deliveries.size
41
+ end
42
+ end
43
+
44
+ # Asserts that no emails have been sent.
45
+ #
46
+ # def test_emails
47
+ # assert_no_emails
48
+ # ContactMailer.welcome.deliver_now
49
+ # assert_emails 1
50
+ # end
51
+ #
52
+ # If a block is passed, that block should not cause any emails to be sent.
53
+ #
54
+ # def test_emails_again
55
+ # assert_no_emails do
56
+ # # No emails should be sent from this block
57
+ # end
58
+ # end
59
+ #
60
+ # Note: This assertion is simply a shortcut for:
61
+ #
62
+ # assert_emails 0, &block
63
+ def assert_no_emails(&block)
64
+ assert_emails 0, &block
65
+ end
66
+
67
+ # Asserts that the number of emails enqueued for later delivery matches
68
+ # the given number.
69
+ #
70
+ # def test_emails
71
+ # assert_enqueued_emails 0
72
+ # ContactMailer.welcome.deliver_later
73
+ # assert_enqueued_emails 1
74
+ # ContactMailer.welcome.deliver_later
75
+ # assert_enqueued_emails 2
76
+ # end
77
+ #
78
+ # If a block is passed, that block should cause the specified number of
79
+ # emails to be enqueued.
80
+ #
81
+ # def test_emails_again
82
+ # assert_enqueued_emails 1 do
83
+ # ContactMailer.welcome.deliver_later
84
+ # end
85
+ #
86
+ # assert_enqueued_emails 2 do
87
+ # ContactMailer.welcome.deliver_later
88
+ # ContactMailer.welcome.deliver_later
89
+ # end
90
+ # end
91
+ def assert_enqueued_emails(number, &block)
92
+ assert_enqueued_jobs(number, only: ->(job) { delivery_job_filter(job) }, &block)
93
+ end
94
+
95
+ # Asserts that a specific email has been enqueued, optionally
96
+ # matching arguments and/or params.
97
+ #
98
+ # def test_email
99
+ # ContactMailer.welcome.deliver_later
100
+ # assert_enqueued_email_with ContactMailer, :welcome
101
+ # end
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
+ #
108
+ # def test_email_with_arguments
109
+ # ContactMailer.welcome("Hello", "Goodbye").deliver_later
110
+ # assert_enqueued_email_with ContactMailer, :welcome, args: ["Hello", "Goodbye"]
111
+ # end
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
+ #
140
+ # If a block is passed, that block should cause the specified email
141
+ # to be enqueued.
142
+ #
143
+ # def test_email_in_block
144
+ # assert_enqueued_email_with ContactMailer, :welcome do
145
+ # ContactMailer.welcome.deliver_later
146
+ # end
147
+ # end
148
+ #
149
+ # If +args+ is provided as a Hash, a parameterized email is matched.
150
+ #
151
+ # def test_parameterized_email
152
+ # assert_enqueued_email_with ContactMailer, :welcome,
153
+ # args: {email: 'user@example.com'} do
154
+ # ContactMailer.with(email: 'user@example.com').welcome.deliver_later
155
+ # end
156
+ # end
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)
161
+ end
162
+
163
+ args = Array(args) unless args.is_a?(Proc)
164
+ queue ||= mailer.deliver_later_queue_name || ActiveJob::Base.default_queue_name
165
+
166
+ expected = ->(job_args) do
167
+ job_kwargs = job_args.extract_options!
168
+
169
+ [mailer.to_s, method.to_s, "deliver_now"] == job_args &&
170
+ params === job_kwargs[:params] && args === job_kwargs[:args]
171
+ end
172
+
173
+ assert_enqueued_with(job: mailer.delivery_job, args: expected, queue: queue.to_s, &block)
174
+ end
175
+
176
+ # Asserts that no emails are enqueued for later delivery.
177
+ #
178
+ # def test_no_emails
179
+ # assert_no_enqueued_emails
180
+ # ContactMailer.welcome.deliver_later
181
+ # assert_enqueued_emails 1
182
+ # end
183
+ #
184
+ # If a block is provided, it should not cause any emails to be enqueued.
185
+ #
186
+ # def test_no_emails
187
+ # assert_no_enqueued_emails do
188
+ # # No emails should be enqueued from this block
189
+ # end
190
+ # end
191
+ def assert_no_enqueued_emails(&block)
192
+ assert_enqueued_emails 0, &block
193
+ end
194
+
195
+ # Delivers all enqueued emails. If a block is given, delivers all of the emails
196
+ # that were enqueued throughout the duration of the block. If a block is
197
+ # not given, delivers all the enqueued emails up to this point in the test.
198
+ #
199
+ # def test_deliver_enqueued_emails
200
+ # deliver_enqueued_emails do
201
+ # ContactMailer.welcome.deliver_later
202
+ # end
203
+ #
204
+ # assert_emails 1
205
+ # end
206
+ #
207
+ # def test_deliver_enqueued_emails_without_block
208
+ # ContactMailer.welcome.deliver_later
209
+ #
210
+ # deliver_enqueued_emails
211
+ #
212
+ # assert_emails 1
213
+ # end
214
+ #
215
+ # If the +:queue+ option is specified,
216
+ # then only the emails(s) enqueued to a specific queue will be performed.
217
+ #
218
+ # def test_deliver_enqueued_emails_with_queue
219
+ # deliver_enqueued_emails queue: :external_mailers do
220
+ # CustomerMailer.deliver_later_queue_name = :external_mailers
221
+ # CustomerMailer.welcome.deliver_later # will be performed
222
+ # EmployeeMailer.deliver_later_queue_name = :internal_mailers
223
+ # EmployeeMailer.welcome.deliver_later # will not be performed
224
+ # end
225
+ #
226
+ # assert_emails 1
227
+ # end
228
+ #
229
+ # If the +:at+ option is specified, then only delivers emails enqueued to deliver
230
+ # immediately or before the given time.
231
+ def deliver_enqueued_emails(queue: nil, at: nil, &block)
232
+ perform_enqueued_jobs(only: ->(job) { delivery_job_filter(job) }, queue: queue, at: at, &block)
233
+ end
234
+
235
+ # Returns any emails that are sent in the block.
236
+ #
237
+ # def test_emails
238
+ # emails = capture_emails do
239
+ # ContactMailer.welcome.deliver_now
240
+ # end
241
+ # assert_equal "Hi there", emails.first.subject
242
+ #
243
+ # emails = capture_emails do
244
+ # ContactMailer.welcome.deliver_now
245
+ # ContactMailer.welcome.deliver_later
246
+ # end
247
+ # assert_equal "Hi there", emails.first.subject
248
+ # end
249
+ def capture_emails(&block)
250
+ original_count = ActionMailer::Base.deliveries.size
251
+ deliver_enqueued_emails(&block)
252
+ new_count = ActionMailer::Base.deliveries.size
253
+ diff = new_count - original_count
254
+ ActionMailer::Base.deliveries.last(diff)
255
+ end
256
+
257
+ private
258
+ def delivery_job_filter(job)
259
+ job_class = job.is_a?(Hash) ? job.fetch(:job) : job.class
260
+
261
+ Base.descendants.map(&:delivery_job).include?(job_class)
262
+ end
263
+ end
264
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "gem_version"
4
+
5
+ module ActionMailer
6
+ # Returns the currently loaded version of Action Mailer as a
7
+ # +Gem::Version+.
8
+ def self.version
9
+ gem_version
10
+ end
11
+ end
@@ -0,0 +1,79 @@
1
+ # frozen_string_literal: true
2
+
3
+ #--
4
+ # Copyright (c) David Heinemeier Hansson
5
+ #
6
+ # Permission is hereby granted, free of charge, to any person obtaining
7
+ # a copy of this software and associated documentation files (the
8
+ # "Software"), to deal in the Software without restriction, including
9
+ # without limitation the rights to use, copy, modify, merge, publish,
10
+ # distribute, sublicense, and/or sell copies of the Software, and to
11
+ # permit persons to whom the Software is furnished to do so, subject to
12
+ # the following conditions:
13
+ #
14
+ # The above copyright notice and this permission notice shall be
15
+ # included in all copies or substantial portions of the Software.
16
+ #
17
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24
+ #++
25
+
26
+ require "abstract_controller"
27
+ require "action_mailer/version"
28
+ require "action_mailer/deprecator"
29
+
30
+ # Common Active Support usage in Action Mailer
31
+ require "active_support"
32
+ require "active_support/rails"
33
+ require "active_support/core_ext/class"
34
+ require "active_support/core_ext/module/attr_internal"
35
+ require "active_support/core_ext/string/inflections"
36
+ require "active_support/lazy_load_hooks"
37
+
38
+ # :include: ../README.rdoc
39
+ module ActionMailer
40
+ extend ::ActiveSupport::Autoload
41
+
42
+ eager_autoload do
43
+ autoload :Collector
44
+ end
45
+
46
+ autoload :Base
47
+ autoload :Callbacks
48
+ autoload :DeliveryMethods
49
+ autoload :InlinePreviewInterceptor
50
+ autoload :MailHelper
51
+ autoload :Parameterized
52
+ autoload :Preview
53
+ autoload :Previews, "action_mailer/preview"
54
+ autoload :TestCase
55
+ autoload :TestHelper
56
+ autoload :MessageDelivery
57
+ autoload :MailDeliveryJob
58
+ autoload :QueuedDelivery
59
+ autoload :FormBuilder
60
+
61
+ def self.eager_load!
62
+ super
63
+
64
+ require "mail"
65
+ Mail.eager_autoload!
66
+
67
+ Base.descendants.each do |mailer|
68
+ mailer.eager_load! unless mailer.abstract?
69
+ end
70
+ end
71
+ end
72
+
73
+ autoload :Mime, "action_dispatch/http/mime_type"
74
+
75
+ ActiveSupport.on_load(:action_view) do
76
+ ActionView::Base.default_formats ||= Mime::SET.symbols
77
+ ActionView::Template.mime_types_implementation = Mime
78
+ ActionView::LookupContext::DetailsKey.clear
79
+ end
@@ -0,0 +1,20 @@
1
+ Description:
2
+ Generates a new mailer and its views. Passes the mailer name, either
3
+ CamelCased or under_scored, and an optional list of emails as arguments.
4
+
5
+ This generates a mailer class in app/mailers and invokes your template
6
+ engine and test framework generators.
7
+
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
+
20
+
@@ -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,6 @@
1
+ <% module_namespacing do -%>
2
+ class ApplicationMailer < ActionMailer::Base
3
+ default from: 'from@example.com'
4
+ layout 'mailer'
5
+ end
6
+ <% end %>
@@ -0,0 +1,19 @@
1
+ <% module_namespacing do -%>
2
+ class <%= class_name %>Mailer < ApplicationMailer
3
+ <% actions.each_with_index do |action, index| -%>
4
+ <% if index != 0 -%>
5
+
6
+ <% end -%>
7
+ # Subject can be set in your I18n file at config/locales/en.yml
8
+ # with the following lookup:
9
+ #
10
+ # en.<%= file_path.tr("/",".") %>_mailer.<%= action %>.subject
11
+ #
12
+ def <%= action %>
13
+ @greeting = "Hi"
14
+
15
+ mail to: "to@example.org"
16
+ end
17
+ <% end -%>
18
+ end
19
+ <% end -%>
metadata ADDED
@@ -0,0 +1,162 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: omg-actionmailer
3
+ version: !ruby/object:Gem::Version
4
+ version: 8.0.0.alpha2
5
+ platform: ruby
6
+ authors:
7
+ - David Heinemeier Hansson
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2024-09-17 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: omg-activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '='
18
+ - !ruby/object:Gem::Version
19
+ version: 8.0.0.alpha2
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '='
25
+ - !ruby/object:Gem::Version
26
+ version: 8.0.0.alpha2
27
+ - !ruby/object:Gem::Dependency
28
+ name: omg-actionpack
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '='
32
+ - !ruby/object:Gem::Version
33
+ version: 8.0.0.alpha2
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '='
39
+ - !ruby/object:Gem::Version
40
+ version: 8.0.0.alpha2
41
+ - !ruby/object:Gem::Dependency
42
+ name: omg-actionview
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '='
46
+ - !ruby/object:Gem::Version
47
+ version: 8.0.0.alpha2
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '='
53
+ - !ruby/object:Gem::Version
54
+ version: 8.0.0.alpha2
55
+ - !ruby/object:Gem::Dependency
56
+ name: omg-activejob
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '='
60
+ - !ruby/object:Gem::Version
61
+ version: 8.0.0.alpha2
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '='
67
+ - !ruby/object:Gem::Version
68
+ version: 8.0.0.alpha2
69
+ - !ruby/object:Gem::Dependency
70
+ name: mail
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: 2.8.0
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: 2.8.0
83
+ - !ruby/object:Gem::Dependency
84
+ name: rails-dom-testing
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '2.2'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '2.2'
97
+ description: Email on Rails. Compose, deliver, and test emails using the familiar
98
+ controller/view pattern. First-class support for multipart email and attachments.
99
+ email: david@loudthinking.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - CHANGELOG.md
105
+ - MIT-LICENSE
106
+ - README.rdoc
107
+ - lib/action_mailer.rb
108
+ - lib/action_mailer/base.rb
109
+ - lib/action_mailer/callbacks.rb
110
+ - lib/action_mailer/collector.rb
111
+ - lib/action_mailer/delivery_methods.rb
112
+ - lib/action_mailer/deprecator.rb
113
+ - lib/action_mailer/form_builder.rb
114
+ - lib/action_mailer/gem_version.rb
115
+ - lib/action_mailer/inline_preview_interceptor.rb
116
+ - lib/action_mailer/log_subscriber.rb
117
+ - lib/action_mailer/mail_delivery_job.rb
118
+ - lib/action_mailer/mail_helper.rb
119
+ - lib/action_mailer/message_delivery.rb
120
+ - lib/action_mailer/parameterized.rb
121
+ - lib/action_mailer/preview.rb
122
+ - lib/action_mailer/queued_delivery.rb
123
+ - lib/action_mailer/railtie.rb
124
+ - lib/action_mailer/rescuable.rb
125
+ - lib/action_mailer/test_case.rb
126
+ - lib/action_mailer/test_helper.rb
127
+ - lib/action_mailer/version.rb
128
+ - lib/rails/generators/mailer/USAGE
129
+ - lib/rails/generators/mailer/mailer_generator.rb
130
+ - lib/rails/generators/mailer/templates/application_mailer.rb.tt
131
+ - lib/rails/generators/mailer/templates/mailer.rb.tt
132
+ homepage: https://rubyonrails.org
133
+ licenses:
134
+ - MIT
135
+ metadata:
136
+ bug_tracker_uri: https://github.com/rails/rails/issues
137
+ changelog_uri: https://github.com/rails/rails/blob/v8.0.0.alpha2/actionmailer/CHANGELOG.md
138
+ documentation_uri: https://api.rubyonrails.org/v8.0.0.alpha2/
139
+ mailing_list_uri: https://discuss.rubyonrails.org/c/rubyonrails-talk
140
+ source_code_uri: https://github.com/rails/rails/tree/v8.0.0.alpha2/actionmailer
141
+ rubygems_mfa_required: 'true'
142
+ post_install_message:
143
+ rdoc_options: []
144
+ require_paths:
145
+ - lib
146
+ required_ruby_version: !ruby/object:Gem::Requirement
147
+ requirements:
148
+ - - ">="
149
+ - !ruby/object:Gem::Version
150
+ version: 3.1.0
151
+ required_rubygems_version: !ruby/object:Gem::Requirement
152
+ requirements:
153
+ - - ">="
154
+ - !ruby/object:Gem::Version
155
+ version: '0'
156
+ requirements:
157
+ - none
158
+ rubygems_version: 3.5.11
159
+ signing_key:
160
+ specification_version: 4
161
+ summary: Email composition and delivery framework (part of Rails).
162
+ test_files: []