gitlab-org--gitlab-foss/spec/lib/additional_email_headers_interceptor_spec.rb
Sean McGivern eddc9e41a6 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.
2017-10-30 13:50:19 +00:00

29 lines
849 B
Ruby

require 'spec_helper'
describe AdditionalEmailHeadersInterceptor do
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