Add coverage for missing status scenario in NotificationMailer (#32256)

This commit is contained in:
Matt Jankowski 2024-10-04 10:15:14 -04:00 committed by GitHub
parent e4e07b1c34
commit ebdeac0731
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 15 additions and 1 deletions

View File

@ -86,7 +86,7 @@ class NotificationMailer < ApplicationMailer
end end
def thread_by_conversation! def thread_by_conversation!
return if @status.conversation.nil? return if @status&.conversation.nil?
conversation_message_id = "<conversation-#{@status.conversation.id}.#{@status.conversation.created_at.to_date}@#{Rails.configuration.x.local_domain}>" conversation_message_id = "<conversation-#{@status.conversation.id}.#{@status.conversation.created_at.to_date}@#{Rails.configuration.x.local_domain}>"

View File

@ -14,6 +14,17 @@ RSpec.describe NotificationMailer do
end end
end end
shared_examples 'delivery without status' do
context 'when notification target_status is missing' do
before { allow(notification).to receive(:target_status).and_return(nil) }
it 'does not deliver mail' do
emails = capture_emails { mail.deliver_now }
expect(emails).to be_empty
end
end
end
let(:receiver) { Fabricate(:user, account_attributes: { username: 'alice' }) } let(:receiver) { Fabricate(:user, account_attributes: { username: 'alice' }) }
let(:sender) { Fabricate(:account, username: 'bob') } let(:sender) { Fabricate(:account, username: 'bob') }
let(:foreign_status) { Fabricate(:status, account: sender, text: 'The body of the foreign status') } let(:foreign_status) { Fabricate(:status, account: sender, text: 'The body of the foreign status') }
@ -37,6 +48,7 @@ RSpec.describe NotificationMailer do
end end
include_examples 'delivery to non functional user' include_examples 'delivery to non functional user'
include_examples 'delivery without status'
end end
describe 'follow' do describe 'follow' do
@ -75,6 +87,7 @@ RSpec.describe NotificationMailer do
end end
include_examples 'delivery to non functional user' include_examples 'delivery to non functional user'
include_examples 'delivery without status'
end end
describe 'reblog' do describe 'reblog' do
@ -95,6 +108,7 @@ RSpec.describe NotificationMailer do
end end
include_examples 'delivery to non functional user' include_examples 'delivery to non functional user'
include_examples 'delivery without status'
end end
describe 'follow_request' do describe 'follow_request' do