aboutsummaryrefslogtreecommitdiffstats
path: root/actionmailer/test/mailers
diff options
context:
space:
mode:
Diffstat (limited to 'actionmailer/test/mailers')
-rw-r--r--actionmailer/test/mailers/asset_mailer.rb9
-rw-r--r--actionmailer/test/mailers/base_mailer.rb150
-rw-r--r--actionmailer/test/mailers/caching_mailer.rb25
-rw-r--r--actionmailer/test/mailers/delayed_mailer.rb28
-rw-r--r--actionmailer/test/mailers/params_mailer.rb13
-rw-r--r--actionmailer/test/mailers/proc_mailer.rb25
6 files changed, 250 insertions, 0 deletions
diff --git a/actionmailer/test/mailers/asset_mailer.rb b/actionmailer/test/mailers/asset_mailer.rb
new file mode 100644
index 0000000000..7a9aba2629
--- /dev/null
+++ b/actionmailer/test/mailers/asset_mailer.rb
@@ -0,0 +1,9 @@
+# frozen_string_literal: true
+
+class AssetMailer < ActionMailer::Base
+ self.mailer_name = "asset_mailer"
+
+ def welcome
+ mail
+ end
+end
diff --git a/actionmailer/test/mailers/base_mailer.rb b/actionmailer/test/mailers/base_mailer.rb
new file mode 100644
index 0000000000..c1bb48cc96
--- /dev/null
+++ b/actionmailer/test/mailers/base_mailer.rb
@@ -0,0 +1,150 @@
+# frozen_string_literal: true
+
+class BaseMailer < ActionMailer::Base
+ self.mailer_name = "base_mailer"
+
+ default to: "system@test.lindsaar.net",
+ from: "jose@test.plataformatec.com",
+ reply_to: "mikel@test.lindsaar.net"
+
+ def welcome(hash = {})
+ headers["X-SPAM"] = "Not SPAM"
+ mail({ subject: "The first email on new API!" }.merge!(hash))
+ end
+
+ def welcome_with_headers(hash = {})
+ headers hash
+ mail
+ end
+
+ def welcome_from_another_path(path)
+ mail(template_name: "welcome", template_path: path)
+ end
+
+ def welcome_without_deliveries
+ mail(template_name: "welcome")
+ mail.perform_deliveries = false
+ end
+
+ def html_only(hash = {})
+ mail(hash)
+ end
+
+ def plain_text_only(hash = {})
+ mail(hash)
+ end
+
+ def inline_attachment
+ attachments.inline["logo.png"] = "\312\213\254\232"
+ mail
+ end
+
+ def attachment_with_content(hash = {})
+ attachments["invoice.pdf"] = "This is test File content"
+ mail(hash)
+ end
+
+ def attachment_with_hash
+ attachments["invoice.jpg"] = { data: ::Base64.encode64("\312\213\254\232)b"),
+ mime_type: "image/x-jpg",
+ transfer_encoding: "base64" }
+ mail
+ end
+
+ def attachment_with_hash_default_encoding
+ attachments["invoice.jpg"] = { data: "\312\213\254\232)b",
+ mime_type: "image/x-jpg" }
+ mail
+ end
+
+ def implicit_multipart(hash = {})
+ attachments["invoice.pdf"] = "This is test File content" if hash.delete(:attachments)
+ mail(hash)
+ end
+
+ def implicit_with_locale(hash = {})
+ mail(hash)
+ end
+
+ def explicit_multipart(hash = {})
+ attachments["invoice.pdf"] = "This is test File content" if hash.delete(:attachments)
+ mail(hash) do |format|
+ format.text { render plain: "TEXT Explicit Multipart" }
+ format.html { render plain: "HTML Explicit Multipart" }
+ end
+ end
+
+ def explicit_multipart_templates(hash = {})
+ mail(hash) do |format|
+ format.html
+ format.text
+ end
+ end
+
+ def explicit_multipart_with_any(hash = {})
+ mail(hash) do |format|
+ format.any(:text, :html) { render plain: "Format with any!" }
+ end
+ end
+
+ def explicit_without_specifying_format_with_any(hash = {})
+ mail(hash) do |format|
+ format.any
+ end
+ end
+
+ def explicit_multipart_with_options(include_html = false)
+ mail do |format|
+ format.text(content_transfer_encoding: "base64") { render "welcome" }
+ format.html { render "welcome" } if include_html
+ end
+ end
+
+ def explicit_multipart_with_one_template(hash = {})
+ mail(hash) do |format|
+ format.html
+ format.text
+ end
+ end
+
+ def implicit_different_template(template_name = "")
+ mail(template_name: template_name)
+ end
+
+ def implicit_different_template_with_block(template_name = "")
+ mail(template_name: template_name) do |format|
+ format.text
+ format.html
+ end
+ end
+
+ def explicit_different_template(template_name = "")
+ mail do |format|
+ format.text { render template: "#{mailer_name}/#{template_name}" }
+ format.html { render template: "#{mailer_name}/#{template_name}" }
+ end
+ end
+
+ def different_layout(layout_name = "")
+ mail do |format|
+ format.text { render layout: layout_name }
+ format.html { render layout: layout_name }
+ end
+ end
+
+ def email_with_translations
+ mail body: render("email_with_translations", formats: [:html])
+ end
+
+ def without_mail_call
+ end
+
+ def with_nil_as_return_value
+ mail(template_name: "welcome")
+ nil
+ end
+
+ def with_subject_interpolations
+ mail(subject: default_i18n_subject(rapper_or_impersonator: "Slim Shady"), body: "")
+ end
+end
diff --git a/actionmailer/test/mailers/caching_mailer.rb b/actionmailer/test/mailers/caching_mailer.rb
new file mode 100644
index 0000000000..02f0c6c103
--- /dev/null
+++ b/actionmailer/test/mailers/caching_mailer.rb
@@ -0,0 +1,25 @@
+# frozen_string_literal: true
+
+class CachingMailer < ActionMailer::Base
+ self.mailer_name = "caching_mailer"
+
+ def fragment_cache
+ mail(subject: "welcome", template_name: "fragment_cache")
+ end
+
+ def fragment_cache_in_partials
+ mail(subject: "welcome", template_name: "fragment_cache_in_partials")
+ end
+
+ def skip_fragment_cache_digesting
+ mail(subject: "welcome", template_name: "skip_fragment_cache_digesting")
+ end
+
+ def fragment_caching_options
+ mail(subject: "welcome", template_name: "fragment_caching_options")
+ end
+
+ def multipart_cache
+ mail(subject: "welcome", template_name: "multipart_cache")
+ end
+end
diff --git a/actionmailer/test/mailers/delayed_mailer.rb b/actionmailer/test/mailers/delayed_mailer.rb
new file mode 100644
index 0000000000..b0f5ecc2fb
--- /dev/null
+++ b/actionmailer/test/mailers/delayed_mailer.rb
@@ -0,0 +1,28 @@
+# frozen_string_literal: true
+
+require "active_job/arguments"
+
+class DelayedMailerError < StandardError; end
+
+class DelayedMailer < ActionMailer::Base
+ cattr_accessor :last_error
+ cattr_accessor :last_rescue_from_instance
+
+ rescue_from DelayedMailerError do |error|
+ @@last_error = error
+ @@last_rescue_from_instance = self
+ end
+
+ rescue_from ActiveJob::DeserializationError do |error|
+ @@last_error = error
+ @@last_rescue_from_instance = self
+ end
+
+ def test_message(*)
+ mail(from: "test-sender@test.com", to: "test-receiver@test.com", subject: "Test Subject", body: "Test Body")
+ end
+
+ def test_raise(klass_name)
+ raise klass_name.constantize, "boom"
+ end
+end
diff --git a/actionmailer/test/mailers/params_mailer.rb b/actionmailer/test/mailers/params_mailer.rb
new file mode 100644
index 0000000000..84aa336311
--- /dev/null
+++ b/actionmailer/test/mailers/params_mailer.rb
@@ -0,0 +1,13 @@
+# frozen_string_literal: true
+
+class ParamsMailer < ActionMailer::Base
+ before_action { @inviter, @invitee = params[:inviter], params[:invitee] }
+
+ default to: Proc.new { @invitee }, from: -> { @inviter }
+
+ def invitation
+ mail(subject: "Welcome to the project!") do |format|
+ format.text { render plain: "So says #{@inviter}" }
+ end
+ end
+end
diff --git a/actionmailer/test/mailers/proc_mailer.rb b/actionmailer/test/mailers/proc_mailer.rb
new file mode 100644
index 0000000000..76e730bb79
--- /dev/null
+++ b/actionmailer/test/mailers/proc_mailer.rb
@@ -0,0 +1,25 @@
+# frozen_string_literal: true
+
+class ProcMailer < ActionMailer::Base
+ default to: "system@test.lindsaar.net",
+ "X-Proc-Method" => Proc.new { Time.now.to_i.to_s },
+ subject: Proc.new { give_a_greeting },
+ "x-has-to-proc" => :symbol,
+ "X-Lambda-Arity-0" => ->() { "0" },
+ "X-Lambda-Arity-1-arg" => ->(arg) { arg.computed_value },
+ "X-Lambda-Arity-1-self" => ->(_) { self.computed_value }
+
+ def welcome
+ mail
+ end
+
+ def computed_value
+ "complex_value"
+ end
+
+ private
+
+ def give_a_greeting
+ "Thanks for signing up this afternoon"
+ end
+end