BigW Consortium Gitlab

disable_email_interceptor_spec.rb 686 Bytes
Newer Older
Marin Jankovski committed
1 2
require 'spec_helper'

Douwe Maan committed
3
describe DisableEmailInterceptor, lib: true do
Marin Jankovski committed
4
  before do
5
    Mail.register_interceptor(DisableEmailInterceptor)
Marin Jankovski committed
6 7 8
  end

  it 'should not send emails' do
9
    allow(Gitlab.config.gitlab).to receive(:email_enabled).and_return(false)
10
    expect { deliver_mail }.not_to change(ActionMailer::Base.deliveries, :count)
Marin Jankovski committed
11 12 13
  end

  after do
14 15 16
    # Removing interceptor from the list because unregister_interceptor is
    # implemented in later version of mail gem
    # See: https://github.com/mikel/mail/pull/705
17
    Mail.unregister_interceptor(DisableEmailInterceptor)
Marin Jankovski committed
18 19 20 21 22 23 24
  end

  def deliver_mail
    key = create :personal_key
    Notify.new_ssh_key_email(key.id)
  end
end