fixes bug Admin Mailer trends mail not displayed correctly (#39122)

This commit is contained in:
Pia B. authored and GitHub committed 2026-05-28 20:14:31 +00:00
1 parent 89a32c3665
commit 8a9ea06dee
3 files changed
+56 -11

No files matched your search

+48 -7
View File
@@ -71,16 +71,22 @@ RSpec.describe AdminMailer do
describe '.new_trends' do
let(:recipient) { Fabricate(:account, username: 'Snurf') }
let(:link) { Fabricate(:preview_card, trendable: true, language: 'en') }
let(:status) { Fabricate(:status) }
let(:tag) { Fabricate(:tag) }
let(:mail) { described_class.with(recipient: recipient).new_trends([link], [tag], [status]) }
let!(:link) { Fabricate(:preview_card, trendable: true, language: 'en') }
let!(:status) { Fabricate(:status) }
let!(:tag) { Fabricate(:tag, display_name: 'Test Tag') }
let!(:other_tag) { Fabricate(:tag, display_name: 'Test Tag') }
let!(:another_tag) { Fabricate(:tag, display_name: 'Test Tag') }
let(:mail) { described_class.with(recipient: recipient).new_trends([link], [tag, other_tag, another_tag], [status]) }
let(:status_trend) { Fabricate(:status_trend, status: status, account: Fabricate(:account)) }
let(:tag_trend) { Fabricate(:tag_trend, tag: tag) }
let(:other_tag_trend) { Fabricate(:tag_trend, tag: other_tag) }
let(:preview_card_trend) { Fabricate(:preview_card_trend, preview_card: link) }
before do
PreviewCardTrend.create!(preview_card: link)
StatusTrend.create!(status: status, account: Fabricate(:account))
TagTrend.create!(tag: tag)
recipient.user.update(locale: :en)
status_trend
tag_trend
preview_card_trend
end
it 'renders the email' do
@@ -96,6 +102,41 @@ RSpec.describe AdminMailer do
.and match(link.title)
.and match(tag.display_name)
end
context 'when between queueing and sending trends gets deleted' do
let(:queue_mail) { described_class.with(recipient: recipient).new_trends([link], [tag, other_tag], [status]).deliver_later! }
before do
recipient.user.update(locale: :en)
end
it 'sends the email when all but one trends were deleted without the respective tag or status or link' do
other_tag_trend
expect(queue_mail.successfully_enqueued?).to be(true)
TagTrend.delete_all
StatusTrend.delete_all
expect { queue_mail.perform_now }.to send_email(
to: recipient.user_email,
from: 'notifications@localhost',
subject: I18n.t('admin_mailer.new_trends.subject', instance: Rails.configuration.x.local_domain)
)
expect(mail.body).to have_text(/The following items need a review before they can be displayed publicly/)
.and match(link.title)
expect(mail.body).to_not match(ActivityPub::TagManager.instance.url_for(status))
expect(mail.body).to_not match(tag.display_name)
end
it 'returns nil when no trends are present' do
expect(queue_mail.successfully_enqueued?).to be(true)
TagTrend.delete_all
StatusTrend.delete_all
PreviewCardTrend.delete_all
expect { queue_mail.perform_now }.to_not send_email
end
end
end
describe '.new_software_updates' do