Commit e44936f3 authored by Douwe Maan's avatar Douwe Maan

Test EmailReceiverWorker.

parent 991c9f6f
Return-Path: <FROM>
Return-Path: <from@example.com>
Received: from iceking.adventuretime.ooo ([unix socket]) by iceking (Cyrus v2.2.13-Debian-2.2.13-19+squeeze3) with LMTPA; Thu, 13 Jun 2013 17:03:50 -0400
Received: from mail-ie0-x234.google.com (mail-ie0-x234.google.com [IPv6:2607:f8b0:4001:c03::234]) by iceking.adventuretime.ooo (8.14.3/8.14.3/Debian-9.4) with ESMTP id r5DL3nFJ016967 (version=TLSv1/SSLv3 cipher=RC4-SHA bits=128 verify=NOT) for <TO>; Thu, 13 Jun 2013 17:03:50 -0400
Received: by mail-ie0-f180.google.com with SMTP id f4so21977375iea.25 for <TO>; Thu, 13 Jun 2013 14:03:48 -0700
Received: from mail-ie0-x234.google.com (mail-ie0-x234.google.com [IPv6:2607:f8b0:4001:c03::234]) by iceking.adventuretime.ooo (8.14.3/8.14.3/Debian-9.4) with ESMTP id r5DL3nFJ016967 (version=TLSv1/SSLv3 cipher=RC4-SHA bits=128 verify=NOT) for <to@example.com>; Thu, 13 Jun 2013 17:03:50 -0400
Received: by mail-ie0-f180.google.com with SMTP id f4so21977375iea.25 for <to@example.com>; Thu, 13 Jun 2013 14:03:48 -0700
Received: by 10.0.0.1 with HTTP; Thu, 13 Jun 2013 14:03:48 -0700
Date: Thu, 13 Jun 2013 17:03:48 -0400
From: Jake the Dog <FROM>
To: <TO>
From: Jake the Dog <from@example.com>
To: <to@example.com>
Message-ID: <CADkmRc+rNGAGGbV2iE5p918UVy4UyJqVcXRO2=otppgzduJSg@mail.gmail.com>
Subject: We should have a post-by-email-feature.
Mime-Version: 1.0
......
require "spec_helper"
describe EmailReceiverWorker do
def fixture_file(filename)
return '' if filename.blank?
file_path = File.expand_path(Rails.root + 'spec/fixtures/' + filename)
File.read(file_path)
end
let(:raw_message) { fixture_file('emails/valid_incoming.eml') }
context "when reply by email is enabled" do
before do
allow(Gitlab::ReplyByEmail).to receive(:enabled?).and_return(true)
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
allow_any_instance_of(Gitlab::Email::Receiver).to receive(:execute).and_raise(Gitlab::Email::Receiver::EmptyEmailError)
end
it "sends out a rejection email" do
described_class.new.perform(raw_message)
email = ActionMailer::Base.deliveries.last
expect(email).not_to be_nil
expect(email.to).to eq(["from@example.com"])
expect(email.subject).to include("Rejected")
end
end
end
context "when reply by email is disabled" do
before do
allow(Gitlab::ReplyByEmail).to receive(:enabled?).and_return(false)
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
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment