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

This commit is contained in:
Pia B. 2026-05-28 22:14:31 +02:00 committed by GitHub
parent 89a32c3665
commit 8a9ea06dee
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 56 additions and 11 deletions

View File

@ -34,9 +34,13 @@ class AdminMailer < ApplicationMailer
end
def new_trends(links, tags, statuses)
@links = links
@tags = tags
@statuses = statuses
ActiveRecord::Associations::Preloader.new(records: [*links, *tags, *statuses], associations: [:trend]).call
@links = links.filter { |link| link.trend.present? }
@tags = tags.filter { |tag| tag.trend.present? }
@statuses = statuses.filter { |status| status.trend.present? }
return unless @links.any? || @tags.any? || @statuses.any?
mail subject: default_i18n_subject(instance: @instance)
end

View File

@ -17,7 +17,7 @@
class: Scheduler::ScheduledStatusesScheduler
queue: scheduler
trends_refresh_scheduler:
every: '5m'
every: ['5m', first_in: '4m']
class: Scheduler::Trends::RefreshScheduler
queue: scheduler
trends_review_notifications_scheduler:

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