blob: bbe5ef8b0681b2415c8ecc00cf1fb9b8174d6550 (
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
|
# frozen_string_literal: true
require 'spec_helper'
describe Mail::SMTPPool do
describe '.create_pool' do
it 'sets the default pool settings' do
expect(ConnectionPool).to receive(:new).with(size: 5, timeout: 5).once
described_class.create_pool
end
it 'allows overriding pool size and timeout' do
expect(ConnectionPool).to receive(:new).with(size: 3, timeout: 2).once
described_class.create_pool(pool_size: 3, pool_timeout: 2)
end
it 'creates an SMTP connection with the correct settings' do
settings = { address: 'smtp.example.com', port: '465' }
smtp_pool = described_class.create_pool(settings)
expect(Mail::SMTPPool::Connection).to receive(:new).with(settings).once.and_call_original
smtp_pool.checkout
end
end
describe '#initialize' do
it 'raises an error if a pool is not specified' do
expect { described_class.new({}) }.to raise_error(
ArgumentError, 'pool is required. You can create one using Mail::SMTPPool.create_pool.'
)
end
end
describe '#deliver!' do
let(:mail) do
Mail.new do
from 'mikel@test.lindsaar.net'
to 'you@test.lindsaar.net'
subject 'This is a test email'
body 'Test body'
end
end
after do
MockSMTP.clear_deliveries
end
it 'delivers mail using a connection from the pool' do
connection_pool = double(ConnectionPool)
connection = double(Mail::SMTPPool::Connection)
expect(connection_pool).to receive(:with).and_yield(connection)
expect(connection).to receive(:deliver!).with(mail)
described_class.new(pool: connection_pool).deliver!(mail)
end
it 'delivers mail' do
described_class.new(pool: described_class.create_pool).deliver!(mail)
expect(MockSMTP.deliveries.size).to eq(1)
end
context 'when called from Mail:Message' do
before do
mail.delivery_method(described_class, { pool: described_class.create_pool })
end
describe '#deliver' do
it 'delivers mail' do
mail.deliver
expect(MockSMTP.deliveries.size).to eq(1)
end
end
describe '#deliver!' do
it 'delivers mail' do
mail.deliver!
expect(MockSMTP.deliveries.size).to eq(1)
end
end
end
end
end
|