From 648f953b76d7b335f100309ad21e08d1283626d5 Mon Sep 17 00:00:00 2001 From: ihatov08 Date: Thu, 28 Oct 2021 23:33:22 +0900 Subject: [PATCH] add sample mailer --- app/mailers/sample_mailer.rb | 13 +++++++++++++ app/views/sample_mailer/hello.html.erb | 5 +++++ app/views/sample_mailer/hello.text.erb | 3 +++ test/mailers/previews/sample_mailer_preview.rb | 9 +++++++++ test/mailers/sample_mailer_test.rb | 12 ++++++++++++ 5 files changed, 42 insertions(+) create mode 100644 app/mailers/sample_mailer.rb create mode 100644 app/views/sample_mailer/hello.html.erb create mode 100644 app/views/sample_mailer/hello.text.erb create mode 100644 test/mailers/previews/sample_mailer_preview.rb create mode 100644 test/mailers/sample_mailer_test.rb diff --git a/app/mailers/sample_mailer.rb b/app/mailers/sample_mailer.rb new file mode 100644 index 0000000..632753f --- /dev/null +++ b/app/mailers/sample_mailer.rb @@ -0,0 +1,13 @@ +class SampleMailer < ApplicationMailer + + # Subject can be set in your I18n file at config/locales/en.yml + # with the following lookup: + # + # en.sample_mailer.hello.subject + # + def hello + @greeting = "Hi" + + mail to: "to@example.org" + end +end diff --git a/app/views/sample_mailer/hello.html.erb b/app/views/sample_mailer/hello.html.erb new file mode 100644 index 0000000..a84365a --- /dev/null +++ b/app/views/sample_mailer/hello.html.erb @@ -0,0 +1,5 @@ +

Sample#hello

+ +

+ <%= @greeting %>, find me in app/views/sample_mailer/hello.html.erb +

diff --git a/app/views/sample_mailer/hello.text.erb b/app/views/sample_mailer/hello.text.erb new file mode 100644 index 0000000..b471aee --- /dev/null +++ b/app/views/sample_mailer/hello.text.erb @@ -0,0 +1,3 @@ +Sample#hello + +<%= @greeting %>, find me in app/views/sample_mailer/hello.text.erb diff --git a/test/mailers/previews/sample_mailer_preview.rb b/test/mailers/previews/sample_mailer_preview.rb new file mode 100644 index 0000000..15e5d65 --- /dev/null +++ b/test/mailers/previews/sample_mailer_preview.rb @@ -0,0 +1,9 @@ +# Preview all emails at http://localhost:3000/rails/mailers/sample_mailer +class SampleMailerPreview < ActionMailer::Preview + + # Preview this email at http://localhost:3000/rails/mailers/sample_mailer/hello + def hello + SampleMailer.hello + end + +end diff --git a/test/mailers/sample_mailer_test.rb b/test/mailers/sample_mailer_test.rb new file mode 100644 index 0000000..a4e648b --- /dev/null +++ b/test/mailers/sample_mailer_test.rb @@ -0,0 +1,12 @@ +require "test_helper" + +class SampleMailerTest < ActionMailer::TestCase + test "hello" do + mail = SampleMailer.hello + assert_equal "Hello", mail.subject + assert_equal ["to@example.org"], mail.to + assert_equal ["from@example.com"], mail.from + assert_match "Hi", mail.body.encoded + end + +end