BigW Consortium Gitlab

build_email_worker_spec.rb 923 Bytes
Newer Older
1 2 3 4 5 6 7
require 'spec_helper'

describe BuildEmailWorker do
  include RepoHelpers

  let(:build) { create(:ci_build) }
  let(:user) { create(:user) }
8
  let(:data) { Gitlab::DataBuilder::Build.build(build) }
9 10 11 12 13 14 15 16 17 18

  subject { BuildEmailWorker.new }

  before do
    allow(build).to receive(:execute_hooks).and_return(false)
    build.success
  end

  describe "#perform" do
    it "sends mail" do
Kamil Trzcinski committed
19
      subject.perform(build.id, [user.email], data.stringify_keys)
20 21 22 23 24 25 26

      email = ActionMailer::Base.deliveries.last
      expect(email.subject).to include('Build success for')
      expect(email.to).to eq([user.email])
    end

    it "gracefully handles an input SMTP error" do
27
      reset_delivered_emails!
28 29
      allow(Notify).to receive(:build_success_email).and_raise(Net::SMTPFatalError)

Kamil Trzcinski committed
30
      subject.perform(build.id, [user.email], data.stringify_keys)
31 32 33 34 35

      expect(ActionMailer::Base.deliveries.count).to eq(0)
    end
  end
end