summaryrefslogtreecommitdiff
path: root/spec/workers
diff options
context:
space:
mode:
authorDouwe Maan <douwe@gitlab.com>2015-08-20 11:47:09 -0700
committerDouwe Maan <douwe@gitlab.com>2015-08-20 11:47:09 -0700
commite44936f3ed4799714fc36a342c1dbab1d50f0ffc (patch)
tree974bc1efbeeae4cb82dc8bbf3fc2879c7ee075b0 /spec/workers
parent991c9f6fdab46909fbbe652b1c88a6521a969c02 (diff)
downloadgitlab-ce-e44936f3ed4799714fc36a342c1dbab1d50f0ffc.tar.gz
Test EmailReceiverWorker.
Diffstat (limited to 'spec/workers')
-rw-r--r--spec/workers/email_receiver_worker_spec.rb51
1 files changed, 51 insertions, 0 deletions
diff --git a/spec/workers/email_receiver_worker_spec.rb b/spec/workers/email_receiver_worker_spec.rb
new file mode 100644
index 00000000000..109a7b3eb1d
--- /dev/null
+++ b/spec/workers/email_receiver_worker_spec.rb
@@ -0,0 +1,51 @@
+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