From 9681897e9ace534c4559fa9be20aa86af1a42e13 Mon Sep 17 00:00:00 2001 From: Star Rauchenberger Date: Sat, 7 Dec 2024 10:33:07 -0500 Subject: Add daily upvote email like AO3 kudos --- test/mailers/previews/vote_mailer_preview.rb | 11 +++++++++++ test/mailers/vote_mailer_test.rb | 12 ++++++++++++ 2 files changed, 23 insertions(+) create mode 100644 test/mailers/previews/vote_mailer_preview.rb create mode 100644 test/mailers/vote_mailer_test.rb (limited to 'test/mailers') diff --git a/test/mailers/previews/vote_mailer_preview.rb b/test/mailers/previews/vote_mailer_preview.rb new file mode 100644 index 0000000..dfc5da1 --- /dev/null +++ b/test/mailers/previews/vote_mailer_preview.rb @@ -0,0 +1,11 @@ +# Preview all emails at http://localhost:3000/rails/mailers/vote_mailer +class VoteMailerPreview < ActionMailer::Preview + + # Preview this email at http://localhost:3000/rails/mailers/vote_mailer/daily_report_email + def daily_report_email + # Duplicating logic from the task... love it + votes = Vote.where("created_at > ?", 1.day.ago).where(upvote: 1).all + VoteMailer.with(votes: votes).daily_report_email + end + +end diff --git a/test/mailers/vote_mailer_test.rb b/test/mailers/vote_mailer_test.rb new file mode 100644 index 0000000..efe8236 --- /dev/null +++ b/test/mailers/vote_mailer_test.rb @@ -0,0 +1,12 @@ +require "test_helper" + +class VoteMailerTest < ActionMailer::TestCase + test "daily_report_email" do + mail = VoteMailer.daily_report_email + assert_equal "Daily report email", mail.subject + assert_equal ["to@example.org"], mail.to + assert_equal ["from@example.com"], mail.from + assert_match "Hi", mail.body.encoded + end + +end -- cgit 1.4.1