debian-mirror-gitlab/spec/lib/gitlab/email/receiver_spec.rb

48 lines
1.4 KiB
Ruby
Raw Normal View History

2016-09-13 17:45:13 +05:30
require 'spec_helper'
2015-09-25 12:07:36 +05:30
2017-09-10 17:25:29 +05:30
describe Gitlab::Email::Receiver do
2016-09-13 17:45:13 +05:30
include_context :email_shared_context
2015-09-25 12:07:36 +05:30
2017-08-17 22:00:37 +05:30
context "when the email contains a valid email address in a Delivered-To header" do
let(:email_raw) { fixture_file('emails/forwarded_new_issue.eml') }
let(:handler) { double(:handler) }
before do
stub_incoming_email_setting(enabled: true, address: "incoming+%{key}@appmail.adventuretime.ooo")
allow(handler).to receive(:execute)
allow(handler).to receive(:metrics_params)
end
it "finds the mail key" do
expect(Gitlab::Email::Handler).to receive(:for).with(an_instance_of(Mail::Message), 'gitlabhq/gitlabhq+auth_token').and_return(handler)
receiver.execute
end
end
2016-09-13 17:45:13 +05:30
context "when we cannot find a capable handler" do
let(:email_raw) { fixture_file('emails/valid_reply.eml').gsub(mail_key, "!!!") }
2015-09-25 12:07:36 +05:30
2017-08-17 22:00:37 +05:30
it "raises an UnknownIncomingEmail error" do
2016-09-13 17:45:13 +05:30
expect { receiver.execute }.to raise_error(Gitlab::Email::UnknownIncomingEmail)
2015-09-25 12:07:36 +05:30
end
end
context "when the email is blank" do
let(:email_raw) { "" }
it "raises an EmptyEmailError" do
2016-09-13 17:45:13 +05:30
expect { receiver.execute }.to raise_error(Gitlab::Email::EmptyEmailError)
2016-06-02 11:05:42 +05:30
end
2015-09-25 12:07:36 +05:30
end
2017-09-10 17:25:29 +05:30
context "when the email was auto generated" do
let(:email_raw) { fixture_file("emails/auto_reply.eml") }
it "raises an AutoGeneratedEmailError" do
expect { receiver.execute }.to raise_error(Gitlab::Email::AutoGeneratedEmailError)
end
end
2015-09-25 12:07:36 +05:30
end