From e8d2b37cb96acd2fa48380d2c3ca35e0577687f9 Mon Sep 17 00:00:00 2001 From: James Mead Date: Wed, 10 Jan 2024 22:59:33 +0000 Subject: [PATCH] Do not notify artist of purchase if sending is suppressed --- app/mailers/purchase_mailer.rb | 1 + test/mailers/purchase_mailer_test.rb | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/app/mailers/purchase_mailer.rb b/app/mailers/purchase_mailer.rb index f83658fb..9c401f56 100644 --- a/app/mailers/purchase_mailer.rb +++ b/app/mailers/purchase_mailer.rb @@ -13,6 +13,7 @@ def notify_artist @purchase = params[:purchase] return unless (@user = @purchase.album.artist.user) + return if @user.suppress_sending? mail to: @user.email, subject: "You have sold a copy of #{@purchase.album.title}" end diff --git a/test/mailers/purchase_mailer_test.rb b/test/mailers/purchase_mailer_test.rb index 7fc8c505..cc5d0d27 100644 --- a/test/mailers/purchase_mailer_test.rb +++ b/test/mailers/purchase_mailer_test.rb @@ -63,4 +63,14 @@ class PurchaseMailerTest < ActionMailer::TestCase mail = PurchaseMailer.with(purchase:).notify_artist assert_includes mail.body.to_s, edit_payout_detail_url end + + test 'do not notify artist of purchase if sending is suppressed' do + user = build(:user, sending_suppressed_at: Time.current) + album = build(:album) + user.artists << album.artist + purchase = build(:purchase, album:, price: 7.00) + + PurchaseMailer.with(purchase:).notify_artist.deliver_now! + assert_emails 0 + end end