fixes bug Admin Mailer trends mail not displayed correctly (#39122)
This commit is contained in:
parent
89a32c3665
commit
8a9ea06dee
@ -34,9 +34,13 @@ class AdminMailer < ApplicationMailer
|
|||||||
end
|
end
|
||||||
|
|
||||||
def new_trends(links, tags, statuses)
|
def new_trends(links, tags, statuses)
|
||||||
@links = links
|
ActiveRecord::Associations::Preloader.new(records: [*links, *tags, *statuses], associations: [:trend]).call
|
||||||
@tags = tags
|
|
||||||
@statuses = statuses
|
@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)
|
mail subject: default_i18n_subject(instance: @instance)
|
||||||
end
|
end
|
||||||
|
|||||||
@ -17,7 +17,7 @@
|
|||||||
class: Scheduler::ScheduledStatusesScheduler
|
class: Scheduler::ScheduledStatusesScheduler
|
||||||
queue: scheduler
|
queue: scheduler
|
||||||
trends_refresh_scheduler:
|
trends_refresh_scheduler:
|
||||||
every: '5m'
|
every: ['5m', first_in: '4m']
|
||||||
class: Scheduler::Trends::RefreshScheduler
|
class: Scheduler::Trends::RefreshScheduler
|
||||||
queue: scheduler
|
queue: scheduler
|
||||||
trends_review_notifications_scheduler:
|
trends_review_notifications_scheduler:
|
||||||
|
|||||||
@ -71,16 +71,22 @@ RSpec.describe AdminMailer do
|
|||||||
|
|
||||||
describe '.new_trends' do
|
describe '.new_trends' do
|
||||||
let(:recipient) { Fabricate(:account, username: 'Snurf') }
|
let(:recipient) { Fabricate(:account, username: 'Snurf') }
|
||||||
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) }
|
let!(:tag) { Fabricate(:tag, display_name: 'Test Tag') }
|
||||||
let(:mail) { described_class.with(recipient: recipient).new_trends([link], [tag], [status]) }
|
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
|
before do
|
||||||
PreviewCardTrend.create!(preview_card: link)
|
|
||||||
StatusTrend.create!(status: status, account: Fabricate(:account))
|
|
||||||
TagTrend.create!(tag: tag)
|
|
||||||
recipient.user.update(locale: :en)
|
recipient.user.update(locale: :en)
|
||||||
|
status_trend
|
||||||
|
tag_trend
|
||||||
|
preview_card_trend
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'renders the email' do
|
it 'renders the email' do
|
||||||
@ -96,6 +102,41 @@ RSpec.describe AdminMailer do
|
|||||||
.and match(link.title)
|
.and match(link.title)
|
||||||
.and match(tag.display_name)
|
.and match(tag.display_name)
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
describe '.new_software_updates' do
|
describe '.new_software_updates' do
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user