diff options
author | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2018-07-16 12:23:15 +0300 |
---|---|---|
committer | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2018-07-16 12:23:15 +0300 |
commit | e682d941807f176ceeb8a639dc498b25560e853e (patch) | |
tree | db1c974617b73a416cc44ddf917e446b79377433 /spec/lib/gitlab/email | |
parent | fabf6a5634fa5d3c585d01a0d0dfac6c39dcbe8e (diff) |
Move existing email interceptors into the same module
Diffstat (limited to 'spec/lib/gitlab/email')
-rw-r--r-- | spec/lib/gitlab/email/hook/additional_headers_interceptor_spec.rb | 29 | ||||
-rw-r--r-- | spec/lib/gitlab/email/hook/disable_email_interceptor_spec.rb | 24 |
2 files changed, 53 insertions, 0 deletions
diff --git a/spec/lib/gitlab/email/hook/additional_headers_interceptor_spec.rb b/spec/lib/gitlab/email/hook/additional_headers_interceptor_spec.rb new file mode 100644 index 00000000000..ae61ece8029 --- /dev/null +++ b/spec/lib/gitlab/email/hook/additional_headers_interceptor_spec.rb @@ -0,0 +1,29 @@ +require 'spec_helper' + +describe Gitlab::Email::Hook::AdditionalHeadersInterceptor 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 diff --git a/spec/lib/gitlab/email/hook/disable_email_interceptor_spec.rb b/spec/lib/gitlab/email/hook/disable_email_interceptor_spec.rb new file mode 100644 index 00000000000..91aa3bc7c2e --- /dev/null +++ b/spec/lib/gitlab/email/hook/disable_email_interceptor_spec.rb @@ -0,0 +1,24 @@ +require 'spec_helper' + +describe Gitlab::Email::Hook::DisableEmailInterceptor do + before do + Mail.register_interceptor(described_class) + end + + it 'does not send emails' do + allow(Gitlab.config.gitlab).to receive(:email_enabled).and_return(false) + expect { deliver_mail }.not_to change(ActionMailer::Base.deliveries, :count) + end + + after do + # Removing interceptor from the list because unregister_interceptor is + # implemented in later version of mail gem + # See: https://github.com/mikel/mail/pull/705 + Mail.unregister_interceptor(described_class) + end + + def deliver_mail + key = create :personal_key + Notify.new_ssh_key_email(key.id) + end +end |