Welcome to mirror list, hosted at ThFree Co, Russian Federation.

incoming_email_spec.rb « gitlab « lib « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: acd6634058ffb3adcbdc40e7c8fac9d47b922e56 (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
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Gitlab::IncomingEmail do
  let(:setting_name) { :incoming_email }

  it_behaves_like 'common email methods'

  describe 'self.key_from_address' do
    before do
      stub_incoming_email_setting(address: 'replies+%{key}@example.com')
    end

    it "returns reply key" do
      expect(described_class.key_from_address("replies+key@example.com")).to eq("key")
    end

    it 'does not match emails with extra bits' do
      expect(described_class.key_from_address('somereplies+somekey@example.com.someotherdomain.com')).to be nil
    end

    context 'when a custom wildcard address is used' do
      let(:wildcard_address) { 'custom.address+%{key}@example.com' }

      it 'finds key if email matches address pattern' do
        key = described_class.key_from_address(
          'custom.address+foo@example.com', wildcard_address: wildcard_address
        )
        expect(key).to eq('foo')
      end
    end
  end
end