diff options
author | Lin Jen-Shin <godfat@godfat.org> | 2016-03-23 22:20:22 +0800 |
---|---|---|
committer | Lin Jen-Shin <godfat@godfat.org> | 2016-05-16 21:27:16 +0000 |
commit | 6cfd028278e7fe22c2776b9ce70a5b92223115f9 (patch) | |
tree | 4de7d86888196f30229d31bbb5c3eff3723a9e15 /spec/lib/gitlab/email/receiver_spec.rb | |
parent | 2375b437bd2f4287e04b11050aae011b314bcd6b (diff) | |
download | gitlab-ce-6cfd028278e7fe22c2776b9ce70a5b92223115f9.tar.gz |
Implement #3243 New Issue by email
So we extend Gitlab::Email::Receiver for this new behaviour,
however we might want to split it into another class for better
testing it.
Another issue is that, currently it's using this to parse project
identifier:
Gitlab::IncomingEmail.key_from_address
Which is using:
Gitlab.config.incoming_email.address
for the receiver name. This is probably `reply` because it's used
for replying to a specific issue. We might want to introduce another
config for this, or just use `reply` instead of `incoming`.
I'll prefer to introduce a new config for this, or just change
`reply` to `incoming` because it would make sense for replying to
there, too.
The email template used in tests were copied and modified from:
`emails/valid_reply.eml` which I hope is ok.
Diffstat (limited to 'spec/lib/gitlab/email/receiver_spec.rb')
-rw-r--r-- | spec/lib/gitlab/email/receiver_spec.rb | 66 |
1 files changed, 54 insertions, 12 deletions
diff --git a/spec/lib/gitlab/email/receiver_spec.rb b/spec/lib/gitlab/email/receiver_spec.rb index f381a3907f3..e7391a33751 100644 --- a/spec/lib/gitlab/email/receiver_spec.rb +++ b/spec/lib/gitlab/email/receiver_spec.rb @@ -15,6 +15,20 @@ describe Gitlab::Email::Receiver, lib: true do let!(:sent_notification) { SentNotification.record(noteable, user.id, reply_key) } let(:receiver) { described_class.new(email_raw) } + let(:markdown) { "![image](uploads/image.png)" } + + def setup_attachment + allow_any_instance_of(Gitlab::Email::AttachmentUploader).to receive(:execute).and_return( + [ + { + url: "uploads/image.png", + is_image: true, + alt: "image", + markdown: markdown + } + ] + ) + end context "when the recipient address doesn't include a reply key" do let(:email_raw) { fixture_file('emails/valid_reply.eml').gsub(reply_key, "") } @@ -108,19 +122,8 @@ describe Gitlab::Email::Receiver, lib: true do end context "when everything is fine" do - let(:markdown) { "![image](uploads/image.png)" } - before do - allow_any_instance_of(Gitlab::Email::AttachmentUploader).to receive(:execute).and_return( - [ - { - url: "uploads/image.png", - is_image: true, - alt: "image", - markdown: markdown - } - ] - ) + setup_attachment end it "creates a comment" do @@ -161,4 +164,43 @@ describe Gitlab::Email::Receiver, lib: true do end end end + + context "when it's trying to create a new issue" do + before do + setup_attachment + stub_incoming_email_setting(enabled: true, address: "incoming+%{key}@appmail.adventuretime.ooo") + end + + let(:sent_notification) {} + let!(:user) { create(:user, email: 'jake@adventuretime.ooo') } + let(:namespace) { create(:namespace, path: 'gitlabhq') } + let(:project) { create(:project, :public, namespace: namespace) } + let(:email_raw) { fixture_file('emails/valid_new_issue.eml') } + + context "when everything is fine" do + it "creates a new issue" do + expect { receiver.execute }.to change { project.issues.count }.by(1) + issue = project.issues.last + + expect(issue.author).to eq(user) + expect(issue.title).to eq('New Issue by email') + expect(issue.description).to include('reply by email') + expect(issue.description).to include(markdown) + end + end + + context "something is wrong" do + context "when the issue could not be saved" do + before do + project + + allow_any_instance_of(Issue).to receive(:persisted?).and_return(false) + end + + it "raises an InvalidIssueError" do + expect { receiver.execute }.to raise_error(Gitlab::Email::Receiver::InvalidIssueError) + end + end + end + end end |