Only set Auto-Submitted header once
The emails on push feature reuses the same email object, to avoid the expensive work of generating the email body. This interceptor would previously set multiple values for the same header, as that's the mail gem's default behaviour when called with the same header more than once. We don't want to change the emails on push service (although it's the only place where this happens), but fixing the interceptor is just as sensible anyway.
This commit is contained in:
parent
9a58468bee
commit
eddc9e41a6
3 changed files with 26 additions and 6 deletions
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
title: Only set Auto-Submitted header once for emails on push
|
||||
merge_request:
|
||||
author:
|
||||
type: fixed
|
|
@ -1,8 +1,6 @@
|
|||
class AdditionalEmailHeadersInterceptor
|
||||
def self.delivering_email(message)
|
||||
message.headers(
|
||||
'Auto-Submitted' => 'auto-generated',
|
||||
'X-Auto-Response-Suppress' => 'All'
|
||||
)
|
||||
message.header['Auto-Submitted'] ||= 'auto-generated'
|
||||
message.header['X-Auto-Response-Suppress'] ||= 'All'
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,12 +1,29 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe AdditionalEmailHeadersInterceptor do
|
||||
it 'adds Auto-Submitted header' do
|
||||
mail = ActionMailer::Base.mail(to: 'test@mail.com', from: 'info@mail.com', body: 'hello').deliver
|
||||
let(:mail) do
|
||||
ActionMailer::Base.mail(to: 'test@mail.com', from: 'info@mail.com', body: 'hello')
|
||||
end
|
||||
|
||||
before do
|
||||
mail.deliver_now
|
||||
end
|
||||
|
||||
it 'adds Auto-Submitted header' do
|
||||
expect(mail.header['To'].value).to eq('test@mail.com')
|
||||
expect(mail.header['From'].value).to eq('info@mail.com')
|
||||
expect(mail.header['Auto-Submitted'].value).to eq('auto-generated')
|
||||
expect(mail.header['X-Auto-Response-Suppress'].value).to eq('All')
|
||||
end
|
||||
|
||||
context 'when the same mail object is sent twice' do
|
||||
before do
|
||||
mail.deliver_now
|
||||
end
|
||||
|
||||
it 'does not add the Auto-Submitted header twice' do
|
||||
expect(mail.header['Auto-Submitted'].value).to eq('auto-generated')
|
||||
expect(mail.header['X-Auto-Response-Suppress'].value).to eq('All')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue