Unify queue_mail and mail in admin mailer new trends spec (#39207)

This commit is contained in:
Matt Jankowski 2026-05-29 05:16:19 -04:00 committed by GitHub
parent 6d3182a6eb
commit e2754b0bc2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -74,19 +74,15 @@ RSpec.describe AdminMailer do
let!(:link) { Fabricate(:preview_card, trendable: true, language: 'en') } let!(:link) { Fabricate(:preview_card, trendable: true, language: 'en') }
let!(:status) { Fabricate(:status) } let!(:status) { Fabricate(:status) }
let!(:tag) { Fabricate(:tag, display_name: 'Test Tag') } let!(:tag) { Fabricate(:tag, display_name: 'Test Tag') }
let!(:other_tag) { Fabricate(:tag, display_name: 'Test Tag') } let!(:other_tag) { Fabricate(:tag, display_name: 'Other Test Tag') }
let!(:another_tag) { Fabricate(:tag, display_name: 'Test Tag') } let(:mail) { described_class.with(recipient: recipient).new_trends([link], [tag, other_tag], [status]) }
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(:other_tag_trend) { Fabricate(:tag_trend, tag: other_tag) }
let(:preview_card_trend) { Fabricate(:preview_card_trend, preview_card: link) }
before do before do
recipient.user.update(locale: :en) recipient.user.update(locale: :en)
status_trend Fabricate(:status_trend, status: status, account: Fabricate(:account))
tag_trend Fabricate(:tag_trend, tag: tag)
preview_card_trend Fabricate(:preview_card_trend, preview_card: link)
end end
it 'renders the email' do it 'renders the email' do
@ -104,37 +100,40 @@ RSpec.describe AdminMailer do
end end
context 'when between queueing and sending trends gets deleted' do 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 before do
recipient.user.update(locale: :en) recipient.user.update(locale: :en)
end end
it 'sends the email when all but one trends were deleted without the respective tag or status or link' do it 'sends the email when all but one trends were deleted without the respective tag or status or link' do
other_tag_trend other_tag_trend
expect(queue_mail.successfully_enqueued?).to be(true) expect(mail.deliver_later!)
.to be_successfully_enqueued
TagTrend.delete_all TagTrend.delete_all
StatusTrend.delete_all StatusTrend.delete_all
expect { queue_mail.perform_now }.to send_email( expect { mail.deliver }
to: recipient.user_email, .to send_email(
from: 'notifications@localhost', to: recipient.user_email,
subject: I18n.t('admin_mailer.new_trends.subject', instance: Rails.configuration.x.local_domain) 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/) )
expect(mail.body)
.to have_text(/The following items need a review before they can be displayed publicly/)
.and match(link.title) .and match(link.title)
expect(mail.body).to_not match(ActivityPub::TagManager.instance.url_for(status)) .and not_include(ActivityPub::TagManager.instance.url_for(status))
expect(mail.body).to_not match(tag.display_name) .and not_include(tag.display_name)
end end
it 'returns nil when no trends are present' do it 'returns nil when no trends are present' do
expect(queue_mail.successfully_enqueued?).to be(true) expect(mail.deliver_later!)
.to be_successfully_enqueued
TagTrend.delete_all TagTrend.delete_all
StatusTrend.delete_all StatusTrend.delete_all
PreviewCardTrend.delete_all PreviewCardTrend.delete_all
expect { queue_mail.perform_now }.to_not send_email expect { mail.deliver }
.to_not send_email
end end
end end
end end