Skip to content

Commit ebdeac0

Browse files
authored
Add coverage for missing status scenario in NotificationMailer (mastodon#32256)
1 parent e4e07b1 commit ebdeac0

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

app/mailers/notification_mailer.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ def set_list_headers!
8686
end
8787

8888
def thread_by_conversation!
89-
return if @status.conversation.nil?
89+
return if @status&.conversation.nil?
9090

9191
conversation_message_id = "<conversation-#{@status.conversation.id}.#{@status.conversation.created_at.to_date}@#{Rails.configuration.x.local_domain}>"
9292

spec/mailers/notification_mailer_spec.rb

+14
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,17 @@
1414
end
1515
end
1616

17+
shared_examples 'delivery without status' do
18+
context 'when notification target_status is missing' do
19+
before { allow(notification).to receive(:target_status).and_return(nil) }
20+
21+
it 'does not deliver mail' do
22+
emails = capture_emails { mail.deliver_now }
23+
expect(emails).to be_empty
24+
end
25+
end
26+
end
27+
1728
let(:receiver) { Fabricate(:user, account_attributes: { username: 'alice' }) }
1829
let(:sender) { Fabricate(:account, username: 'bob') }
1930
let(:foreign_status) { Fabricate(:status, account: sender, text: 'The body of the foreign status') }
@@ -37,6 +48,7 @@
3748
end
3849

3950
include_examples 'delivery to non functional user'
51+
include_examples 'delivery without status'
4052
end
4153

4254
describe 'follow' do
@@ -75,6 +87,7 @@
7587
end
7688

7789
include_examples 'delivery to non functional user'
90+
include_examples 'delivery without status'
7891
end
7992

8093
describe 'reblog' do
@@ -95,6 +108,7 @@
95108
end
96109

97110
include_examples 'delivery to non functional user'
111+
include_examples 'delivery without status'
98112
end
99113

100114
describe 'follow_request' do

0 commit comments

Comments
 (0)