BigW Consortium Gitlab

email_receiver_worker_spec.rb 1.36 KB
Newer Older
Douwe Maan committed
1 2 3
require "spec_helper"

describe EmailReceiverWorker do
Douwe Maan committed
4
  let(:raw_message) { fixture_file('emails/valid_reply.eml') }
Douwe Maan committed
5 6 7

  context "when reply by email is enabled" do
    before do
8
      allow(Gitlab::IncomingEmail).to receive(:enabled?).and_return(true)
Douwe Maan committed
9 10 11 12 13 14 15 16 17 18 19
    end

    it "calls the email receiver" do
      expect(Gitlab::Email::Receiver).to receive(:new).with(raw_message).and_call_original
      expect_any_instance_of(Gitlab::Email::Receiver).to receive(:execute)

      described_class.new.perform(raw_message)
    end

    context "when an error occurs" do
      before do
20
        allow_any_instance_of(Gitlab::Email::Receiver).to receive(:execute).and_raise(Gitlab::Email::EmptyEmailError)
Douwe Maan committed
21 22 23
      end

      it "sends out a rejection email" do
Valery Sizov committed
24 25 26 27 28 29 30 31
        perform_enqueued_jobs do
          described_class.new.perform(raw_message)

          email = ActionMailer::Base.deliveries.last
          expect(email).not_to be_nil
          expect(email.to).to eq(["jake@adventuretime.ooo"])
          expect(email.subject).to include("Rejected")
        end
Douwe Maan committed
32 33 34 35 36 37
      end
    end
  end

  context "when reply by email is disabled" do
    before do
38
      allow(Gitlab::IncomingEmail).to receive(:enabled?).and_return(false)
Douwe Maan committed
39 40 41 42 43 44 45 46 47
    end

    it "doesn't call the email receiver" do
      expect(Gitlab::Email::Receiver).not_to receive(:new)

      described_class.new.perform(raw_message)
    end
  end
end