FIX: Add topic deleted check to email/sender (#9166)

It already had a deleted post check and log reason, add a topic one too to avoid errors
This commit is contained in:
Martin Brennan
2020-03-13 10:04:15 +10:00
committed by GitHub
parent 4d7f6749be
commit 2237ba8c9d
4 changed files with 27 additions and 5 deletions

View File

@ -443,6 +443,25 @@ describe Email::Sender do
end
context 'with a deleted topic' do
it 'should skip sending the email' do
post = Fabricate(:post, topic: Fabricate(:topic, deleted_at: 1.day.ago))
message = Mail::Message.new to: 'disc@ourse.org', body: 'some content'
message.header['X-Discourse-Post-Id'] = post.id
message.header['X-Discourse-Topic-Id'] = post.topic_id
message.expects(:deliver_now).never
email_sender = Email::Sender.new(message, :valid_type)
expect { email_sender.send }.to change { SkippedEmailLog.count }
log = SkippedEmailLog.last
expect(log.reason_type).to eq(SkippedEmailLog.reason_types[:sender_topic_deleted])
end
end
context 'with a user' do
let(:message) do
message = Mail::Message.new to: 'eviltrout@test.domain', body: 'test body'