summaryrefslogtreecommitdiff
path: root/spec/support/shared_contexts/email_shared_context.rb
blob: b4d061a821501bd831f24f675e0405e0a05e4cd3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# frozen_string_literal: true

shared_context :email_shared_context do
  let(:mail_key) { "59d8df8370b7e95c5a49fbf86aeb2c93" }
  let(:receiver) { Gitlab::Email::Receiver.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",
          alt: "image",
          markdown: markdown
        }
      ]
    )
  end
end

shared_examples :reply_processing_shared_examples do
  context "when the user could not be found" do
    before do
      user.destroy
    end

    it "raises a UserNotFoundError" do
      expect { receiver.execute }.to raise_error(Gitlab::Email::UserNotFoundError)
    end
  end

  context "when the user is not authorized to the project" do
    before do
      project.update_attribute(:visibility_level, Project::PRIVATE)
    end

    it "raises a ProjectNotFound" do
      expect { receiver.execute }.to raise_error(Gitlab::Email::ProjectNotFound)
    end
  end
end