letter_opener 1.0.0 → 1.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/CHANGELOG.md +67 -9
- data/Gemfile +1 -1
- data/README.rdoc +33 -1
- data/lib/letter_opener/configuration.rb +10 -0
- data/lib/letter_opener/delivery_method.rb +24 -3
- data/lib/letter_opener/message.rb +46 -18
- data/lib/letter_opener/railtie.rb +6 -1
- data/lib/letter_opener/templates/default.html.erb +138 -0
- data/lib/letter_opener/templates/light.html.erb +11 -0
- data/lib/letter_opener.rb +14 -8
- data/spec/letter_opener/delivery_method_spec.rb +199 -46
- data/spec/letter_opener/message_spec.rb +196 -11
- data/spec/spec_helper.rb +0 -2
- metadata +30 -35
- data/lib/letter_opener/message.html.erb +0 -108
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
require "spec_helper"
|
|
2
2
|
|
|
3
3
|
describe LetterOpener::DeliveryMethod do
|
|
4
|
-
let(:location)
|
|
4
|
+
let(:location) { File.expand_path('../../../tmp/letter_opener', __FILE__) }
|
|
5
|
+
|
|
6
|
+
let(:plain_file) { Dir["#{location}/*/plain.html"].first }
|
|
7
|
+
let(:plain) { CGI.unescape_html(File.read(plain_file)) }
|
|
5
8
|
|
|
6
9
|
before do
|
|
7
|
-
Launchy.
|
|
10
|
+
allow(Launchy).to receive(:open)
|
|
8
11
|
FileUtils.rm_rf(location)
|
|
9
12
|
context = self
|
|
10
13
|
|
|
@@ -14,58 +17,97 @@ describe LetterOpener::DeliveryMethod do
|
|
|
14
17
|
end
|
|
15
18
|
|
|
16
19
|
it 'raises an exception if no location passed' do
|
|
17
|
-
|
|
18
|
-
|
|
20
|
+
expect { LetterOpener::DeliveryMethod.new }.to raise_exception(LetterOpener::DeliveryMethod::InvalidOption)
|
|
21
|
+
expect { LetterOpener::DeliveryMethod.new(location: "foo") }.to_not raise_exception
|
|
19
22
|
end
|
|
20
23
|
|
|
21
|
-
context '
|
|
22
|
-
|
|
23
|
-
|
|
24
|
+
context 'integration' do
|
|
25
|
+
before do
|
|
26
|
+
expect(Launchy).to receive(:open).and_call_original
|
|
27
|
+
ENV['LAUNCHY_DRY_RUN'] = 'true'
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
context 'normal location path' do
|
|
31
|
+
it 'opens email' do
|
|
32
|
+
expect($stdout).to receive(:puts)
|
|
33
|
+
expect {
|
|
34
|
+
Mail.deliver do
|
|
35
|
+
to 'Bar bar@example.com'
|
|
36
|
+
from 'Foo foo@example.com'
|
|
37
|
+
body 'World! http://example.com'
|
|
38
|
+
end
|
|
39
|
+
}.not_to raise_error
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
context 'with spaces in location path' do
|
|
44
|
+
let(:location) { File.expand_path('../../../tmp/letter_opener with space', __FILE__) }
|
|
45
|
+
|
|
46
|
+
it 'opens email' do
|
|
47
|
+
expect($stdout).to receive(:puts)
|
|
48
|
+
expect {
|
|
49
|
+
Mail.deliver do
|
|
50
|
+
to 'Bar bar@example.com'
|
|
51
|
+
from 'Foo foo@example.com'
|
|
52
|
+
body 'World! http://example.com'
|
|
53
|
+
end
|
|
54
|
+
}.not_to raise_error
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
end
|
|
24
58
|
|
|
59
|
+
context 'content' do
|
|
25
60
|
context 'plain' do
|
|
26
61
|
before do
|
|
27
|
-
Launchy.
|
|
62
|
+
expect(Launchy).to receive(:open)
|
|
28
63
|
|
|
29
64
|
Mail.deliver do
|
|
30
|
-
from 'Foo foo@example.com'
|
|
31
|
-
|
|
32
|
-
|
|
65
|
+
from 'Foo <foo@example.com>'
|
|
66
|
+
sender 'Baz <baz@example.com>'
|
|
67
|
+
reply_to 'No Reply <no-reply@example.com>'
|
|
68
|
+
to 'Bar <bar@example.com>'
|
|
69
|
+
cc 'Qux <qux@example.com>'
|
|
70
|
+
bcc 'Qux <qux@example.com>'
|
|
33
71
|
subject 'Hello'
|
|
34
72
|
body 'World! http://example.com'
|
|
35
73
|
end
|
|
36
74
|
end
|
|
37
75
|
|
|
38
76
|
it 'creates plain html document' do
|
|
39
|
-
File.exist?(plain_file).
|
|
77
|
+
expect(File.exist?(plain_file)).to be_truthy
|
|
40
78
|
end
|
|
41
79
|
|
|
42
80
|
it 'saves From field' do
|
|
43
|
-
plain.
|
|
81
|
+
expect(plain).to include("Foo <foo@example.com>")
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
it 'saves Sender field' do
|
|
85
|
+
expect(plain).to include("Baz <baz@example.com>")
|
|
44
86
|
end
|
|
45
87
|
|
|
46
88
|
it 'saves Reply-to field' do
|
|
47
|
-
plain.
|
|
89
|
+
expect(plain).to include("No Reply <no-reply@example.com>")
|
|
48
90
|
end
|
|
49
91
|
|
|
50
92
|
it 'saves To field' do
|
|
51
|
-
plain.
|
|
93
|
+
expect(plain).to include("Bar <bar@example.com>")
|
|
52
94
|
end
|
|
53
95
|
|
|
54
96
|
it 'saves Subject field' do
|
|
55
|
-
plain.
|
|
97
|
+
expect(plain).to include("Hello")
|
|
56
98
|
end
|
|
57
99
|
|
|
58
100
|
it 'saves Body with autolink' do
|
|
59
|
-
plain.
|
|
101
|
+
expect(plain).to include('World! <a href="http://example.com">http://example.com</a>')
|
|
60
102
|
end
|
|
61
103
|
end
|
|
62
104
|
|
|
63
105
|
context 'multipart' do
|
|
64
106
|
let(:rich_file) { Dir["#{location}/*/rich.html"].first }
|
|
65
|
-
let(:rich) { File.read(rich_file) }
|
|
107
|
+
let(:rich) { CGI.unescape_html(File.read(rich_file)) }
|
|
66
108
|
|
|
67
109
|
before do
|
|
68
|
-
Launchy.
|
|
110
|
+
expect(Launchy).to receive(:open)
|
|
69
111
|
|
|
70
112
|
Mail.deliver do
|
|
71
113
|
from 'foo@example.com'
|
|
@@ -82,41 +124,43 @@ describe LetterOpener::DeliveryMethod do
|
|
|
82
124
|
end
|
|
83
125
|
|
|
84
126
|
it 'creates plain html document' do
|
|
85
|
-
File.exist?(plain_file).
|
|
127
|
+
expect(File.exist?(plain_file)).to be_truthy
|
|
86
128
|
end
|
|
87
129
|
|
|
88
130
|
it 'creates rich html document' do
|
|
89
|
-
File.exist?(rich_file).
|
|
131
|
+
expect(File.exist?(rich_file)).to be_truthy
|
|
90
132
|
end
|
|
91
133
|
|
|
92
134
|
it 'shows link to rich html version' do
|
|
93
|
-
plain.
|
|
135
|
+
expect(plain).to include("View HTML version")
|
|
94
136
|
end
|
|
95
137
|
|
|
96
138
|
it 'saves text part' do
|
|
97
|
-
plain.
|
|
139
|
+
expect(plain).to include("This is <plain> text")
|
|
98
140
|
end
|
|
99
141
|
|
|
100
142
|
it 'saves html part' do
|
|
101
|
-
rich.
|
|
143
|
+
expect(rich).to include("<h1>This is HTML</h1>")
|
|
102
144
|
end
|
|
103
145
|
|
|
104
146
|
it 'saves escaped Subject field' do
|
|
105
|
-
plain.
|
|
147
|
+
expect(plain).to include("Many parts with <html>")
|
|
148
|
+
end
|
|
149
|
+
|
|
150
|
+
it 'shows subject as title' do
|
|
151
|
+
expect(rich).to include("<title>Many parts with <html></title>")
|
|
106
152
|
end
|
|
107
153
|
end
|
|
108
154
|
end
|
|
109
155
|
|
|
110
156
|
context 'document with spaces in name' do
|
|
111
157
|
let(:location) { File.expand_path('../../../tmp/letter_opener with space', __FILE__) }
|
|
112
|
-
let(:file) { Dir["#{location}/*/plain.html"].first }
|
|
113
|
-
let(:plain) { File.read(file) }
|
|
114
158
|
|
|
115
159
|
before do
|
|
116
|
-
Launchy.
|
|
160
|
+
expect(Launchy).to receive(:open)
|
|
117
161
|
|
|
118
162
|
Mail.deliver do
|
|
119
|
-
from 'Foo foo@example.com'
|
|
163
|
+
from 'Foo <foo@example.com>'
|
|
120
164
|
to 'bar@example.com'
|
|
121
165
|
subject 'Hello'
|
|
122
166
|
body 'World!'
|
|
@@ -124,20 +168,17 @@ describe LetterOpener::DeliveryMethod do
|
|
|
124
168
|
end
|
|
125
169
|
|
|
126
170
|
it 'creates plain html document' do
|
|
127
|
-
File.exist?(
|
|
171
|
+
File.exist?(plain_file)
|
|
128
172
|
end
|
|
129
173
|
|
|
130
174
|
it 'saves From filed' do
|
|
131
|
-
plain.
|
|
175
|
+
expect(plain).to include("Foo <foo@example.com>")
|
|
132
176
|
end
|
|
133
177
|
end
|
|
134
178
|
|
|
135
179
|
context 'using deliver! method' do
|
|
136
|
-
let(:plain_file) { Dir["#{location}/*/plain.html"].first }
|
|
137
|
-
let(:plain) { File.read(plain_file) }
|
|
138
|
-
|
|
139
180
|
before do
|
|
140
|
-
Launchy.
|
|
181
|
+
expect(Launchy).to receive(:open)
|
|
141
182
|
Mail.new do
|
|
142
183
|
from 'foo@example.com'
|
|
143
184
|
to 'bar@example.com'
|
|
@@ -147,23 +188,23 @@ describe LetterOpener::DeliveryMethod do
|
|
|
147
188
|
end
|
|
148
189
|
|
|
149
190
|
it 'creates plain html document' do
|
|
150
|
-
File.exist?(plain_file).
|
|
191
|
+
expect(File.exist?(plain_file)).to be_truthy
|
|
151
192
|
end
|
|
152
193
|
|
|
153
194
|
it 'saves From field' do
|
|
154
|
-
plain.
|
|
195
|
+
expect(plain).to include("foo@example.com")
|
|
155
196
|
end
|
|
156
197
|
|
|
157
198
|
it 'saves To field' do
|
|
158
|
-
plain.
|
|
199
|
+
expect(plain).to include("bar@example.com")
|
|
159
200
|
end
|
|
160
201
|
|
|
161
202
|
it 'saves Subject field' do
|
|
162
|
-
plain.
|
|
203
|
+
expect(plain).to include("Hello")
|
|
163
204
|
end
|
|
164
205
|
|
|
165
206
|
it 'saves Body field' do
|
|
166
|
-
plain.
|
|
207
|
+
expect(plain).to include("World!")
|
|
167
208
|
end
|
|
168
209
|
end
|
|
169
210
|
|
|
@@ -182,12 +223,12 @@ describe LetterOpener::DeliveryMethod do
|
|
|
182
223
|
|
|
183
224
|
it 'creates attachments dir with attachment' do
|
|
184
225
|
attachment = Dir["#{location}/*/attachments/#{File.basename(__FILE__)}"].first
|
|
185
|
-
File.
|
|
226
|
+
expect(File.exist?(attachment)).to be_truthy
|
|
186
227
|
end
|
|
187
228
|
|
|
188
229
|
it 'saves attachment name' do
|
|
189
230
|
plain = File.read(Dir["#{location}/*/plain.html"].first)
|
|
190
|
-
plain.
|
|
231
|
+
expect(plain).to include(File.basename(__FILE__))
|
|
191
232
|
end
|
|
192
233
|
end
|
|
193
234
|
|
|
@@ -210,14 +251,126 @@ describe LetterOpener::DeliveryMethod do
|
|
|
210
251
|
|
|
211
252
|
it 'creates attachments dir with attachment' do
|
|
212
253
|
attachment = Dir["#{location}/*/attachments/#{File.basename(__FILE__)}"].first
|
|
213
|
-
File.
|
|
254
|
+
expect(File.exist?(attachment)).to be_truthy
|
|
214
255
|
end
|
|
215
256
|
|
|
216
257
|
it 'replaces inline attachment urls' do
|
|
217
258
|
text = File.read(Dir["#{location}/*/rich.html"].first)
|
|
218
|
-
mail.parts[0].body.
|
|
219
|
-
text.
|
|
220
|
-
text.
|
|
259
|
+
expect(mail.parts[0].body).to include(url)
|
|
260
|
+
expect(text).to_not include(url)
|
|
261
|
+
expect(text).to include("attachments/#{File.basename(__FILE__)}")
|
|
262
|
+
end
|
|
263
|
+
end
|
|
264
|
+
|
|
265
|
+
context 'attachments with non-word characters in the filename' do
|
|
266
|
+
before do
|
|
267
|
+
Mail.deliver do
|
|
268
|
+
from 'foo@example.com'
|
|
269
|
+
to 'bar@example.com'
|
|
270
|
+
subject 'With attachments'
|
|
271
|
+
text_part do
|
|
272
|
+
body 'This is <plain> text'
|
|
273
|
+
end
|
|
274
|
+
attachments['non word:chars/used,01-02.txt'] = File.read(__FILE__)
|
|
275
|
+
|
|
276
|
+
url = attachments[0].url
|
|
277
|
+
html_part do
|
|
278
|
+
content_type 'text/html; charset=UTF-8'
|
|
279
|
+
body "This is an image: <img src='#{url}'>"
|
|
280
|
+
end
|
|
281
|
+
end
|
|
282
|
+
end
|
|
283
|
+
|
|
284
|
+
it 'creates attachments dir with attachment' do
|
|
285
|
+
attachment = Dir["#{location}/*/attachments/non_word_chars_used_01-02.txt"].first
|
|
286
|
+
expect(File.exist?(attachment)).to be_truthy
|
|
287
|
+
end
|
|
288
|
+
|
|
289
|
+
it 'saves attachment name' do
|
|
290
|
+
plain = File.read(Dir["#{location}/*/plain.html"].first)
|
|
291
|
+
expect(plain).to include('non_word_chars_used_01-02.txt')
|
|
292
|
+
end
|
|
293
|
+
|
|
294
|
+
it 'replaces inline attachment names' do
|
|
295
|
+
text = File.read(Dir["#{location}/*/rich.html"].first)
|
|
296
|
+
expect(text).to_not include('attachments/non word:chars/used,01-02.txt')
|
|
297
|
+
expect(text).to include('attachments/non_word_chars_used_01-02.txt')
|
|
298
|
+
end
|
|
299
|
+
end
|
|
300
|
+
|
|
301
|
+
context 'subjectless mail' do
|
|
302
|
+
before do
|
|
303
|
+
expect(Launchy).to receive(:open)
|
|
304
|
+
|
|
305
|
+
Mail.deliver do
|
|
306
|
+
from 'Foo foo@example.com'
|
|
307
|
+
reply_to 'No Reply no-reply@example.com'
|
|
308
|
+
to 'Bar bar@example.com'
|
|
309
|
+
body 'World! http://example.com'
|
|
310
|
+
end
|
|
311
|
+
end
|
|
312
|
+
|
|
313
|
+
it 'creates plain html document' do
|
|
314
|
+
expect(File.exist?(plain_file)).to be_truthy
|
|
315
|
+
end
|
|
316
|
+
end
|
|
317
|
+
|
|
318
|
+
context 'delivery params' do
|
|
319
|
+
it 'raises an exception if there is no SMTP Envelope To value' do
|
|
320
|
+
expect(Launchy).not_to receive(:open)
|
|
321
|
+
|
|
322
|
+
expect {
|
|
323
|
+
Mail.deliver do
|
|
324
|
+
from 'Foo foo@example.com'
|
|
325
|
+
reply_to 'No Reply no-reply@example.com'
|
|
326
|
+
body 'World! http://example.com'
|
|
327
|
+
end
|
|
328
|
+
}.to raise_exception(ArgumentError)
|
|
329
|
+
end
|
|
330
|
+
|
|
331
|
+
it 'does not raise an exception if there is at least one SMTP Envelope To value' do
|
|
332
|
+
expect(Launchy).to receive(:open)
|
|
333
|
+
|
|
334
|
+
expect {
|
|
335
|
+
Mail.deliver do
|
|
336
|
+
from 'Foo foo@example.com'
|
|
337
|
+
cc 'Bar bar@example.com'
|
|
338
|
+
reply_to 'No Reply no-reply@example.com'
|
|
339
|
+
body 'World! http://example.com'
|
|
340
|
+
end
|
|
341
|
+
}.not_to raise_exception
|
|
342
|
+
end
|
|
343
|
+
end
|
|
344
|
+
|
|
345
|
+
context 'light template' do
|
|
346
|
+
before do
|
|
347
|
+
expect(Launchy).to receive(:open)
|
|
348
|
+
|
|
349
|
+
LetterOpener.configure do |config|
|
|
350
|
+
config.message_template = :light
|
|
351
|
+
end
|
|
352
|
+
|
|
353
|
+
Mail.defaults do
|
|
354
|
+
delivery_method LetterOpener::DeliveryMethod, :location => File.expand_path('../../../tmp/letter_opener', __FILE__)
|
|
355
|
+
end
|
|
356
|
+
|
|
357
|
+
Mail.deliver do
|
|
358
|
+
subject 'Foo subject'
|
|
359
|
+
from 'Foo foo@example.com'
|
|
360
|
+
reply_to 'No Reply no-reply@example.com'
|
|
361
|
+
to 'Bar bar@example.com'
|
|
362
|
+
body 'World! http://example.com'
|
|
363
|
+
end
|
|
364
|
+
end
|
|
365
|
+
|
|
366
|
+
after do
|
|
367
|
+
LetterOpener.configure do |config|
|
|
368
|
+
config.message_template = :default
|
|
369
|
+
end
|
|
370
|
+
end
|
|
371
|
+
|
|
372
|
+
it 'creates plain html document' do
|
|
373
|
+
expect(File.exist?(plain_file)).to be_truthy
|
|
221
374
|
end
|
|
222
375
|
end
|
|
223
376
|
end
|
|
@@ -1,37 +1,222 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
1
2
|
require 'spec_helper'
|
|
2
3
|
|
|
3
4
|
describe LetterOpener::Message do
|
|
4
5
|
let(:location) { File.expand_path('../../../tmp/letter_opener', __FILE__) }
|
|
5
6
|
|
|
7
|
+
def mail(options={}, &blk)
|
|
8
|
+
Mail.new(options, &blk)
|
|
9
|
+
end
|
|
10
|
+
|
|
6
11
|
describe '#reply_to' do
|
|
7
12
|
it 'handles one email as a string' do
|
|
8
|
-
|
|
9
|
-
message.
|
|
13
|
+
mail = mail(:reply_to => 'test@example.com')
|
|
14
|
+
message = described_class.new(mail, location: location)
|
|
15
|
+
expect(message.reply_to).to eq('test@example.com')
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
it 'handles one email with display names' do
|
|
19
|
+
mail = mail(:reply_to => 'test <test@example.com>')
|
|
20
|
+
message = described_class.new(mail, location: location)
|
|
21
|
+
expect(message.reply_to).to eq('test <test@example.com>')
|
|
10
22
|
end
|
|
11
23
|
|
|
12
24
|
it 'handles array of emails' do
|
|
13
|
-
|
|
14
|
-
message.
|
|
25
|
+
mail = mail(:reply_to => ['test1@example.com', 'test2@example.com'])
|
|
26
|
+
message = described_class.new(mail, location: location)
|
|
27
|
+
expect(message.reply_to).to eq('test1@example.com, test2@example.com')
|
|
15
28
|
end
|
|
29
|
+
|
|
30
|
+
it 'handles array of emails with display names' do
|
|
31
|
+
mail = mail(:reply_to => ['test1 <test1@example.com>', 'test2 <test2@example.com>'])
|
|
32
|
+
message = described_class.new(mail, location: location)
|
|
33
|
+
expect(message.reply_to).to eq('test1 <test1@example.com>, test2 <test2@example.com>')
|
|
34
|
+
end
|
|
35
|
+
|
|
16
36
|
end
|
|
17
37
|
|
|
18
38
|
describe '#to' do
|
|
19
39
|
it 'handles one email as a string' do
|
|
20
|
-
|
|
21
|
-
message.
|
|
40
|
+
mail = mail(:to => 'test@example.com')
|
|
41
|
+
message = described_class.new(mail, location: location)
|
|
42
|
+
expect(message.to).to eq('test@example.com')
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
it 'handles one email with display names' do
|
|
46
|
+
mail = mail(:to => 'test <test@example.com>')
|
|
47
|
+
message = described_class.new(mail, location: location)
|
|
48
|
+
expect(message.to).to eq('test <test@example.com>')
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
it 'handles array of emails' do
|
|
52
|
+
mail = mail(:to => ['test1@example.com', 'test2@example.com'])
|
|
53
|
+
message = described_class.new(mail, location: location)
|
|
54
|
+
expect(message.to).to eq('test1@example.com, test2@example.com')
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
it 'handles array of emails with display names' do
|
|
58
|
+
mail = mail(:to => ['test1 <test1@example.com>', 'test2 <test2@example.com>'])
|
|
59
|
+
message = described_class.new(mail, location: location)
|
|
60
|
+
expect(message.to).to eq('test1 <test1@example.com>, test2 <test2@example.com>')
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
describe '#cc' do
|
|
66
|
+
it 'handles one cc email as a string' do
|
|
67
|
+
mail = mail(:cc => 'test@example.com')
|
|
68
|
+
message = described_class.new(mail, location: location)
|
|
69
|
+
expect(message.cc).to eq('test@example.com')
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
it 'handles one cc email with display name' do
|
|
73
|
+
mail = mail(:cc => ['test <test1@example.com>', 'test2 <test2@example.com>'])
|
|
74
|
+
message = described_class.new(mail, location: location)
|
|
75
|
+
expect(message.cc).to eq('test <test1@example.com>, test2 <test2@example.com>')
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
it 'handles array of cc emails' do
|
|
79
|
+
mail = mail(:cc => ['test1@example.com', 'test2@example.com'])
|
|
80
|
+
message = described_class.new(mail, location: location)
|
|
81
|
+
expect(message.cc).to eq('test1@example.com, test2@example.com')
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
it 'handles array of cc emails with display names' do
|
|
85
|
+
mail = mail(:cc => ['test <test1@example.com>', 'test2 <test2@example.com>'])
|
|
86
|
+
message = described_class.new(mail, location: location)
|
|
87
|
+
expect(message.cc).to eq('test <test1@example.com>, test2 <test2@example.com>')
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
describe '#bcc' do
|
|
93
|
+
it 'handles one bcc email as a string' do
|
|
94
|
+
mail = mail(:bcc => 'test@example.com')
|
|
95
|
+
message = described_class.new(mail, location: location)
|
|
96
|
+
expect(message.bcc).to eq('test@example.com')
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
it 'handles one bcc email with display name' do
|
|
100
|
+
mail = mail(:bcc => ['test <test1@example.com>', 'test2 <test2@example.com>'])
|
|
101
|
+
message = described_class.new(mail, location: location)
|
|
102
|
+
expect(message.bcc).to eq('test <test1@example.com>, test2 <test2@example.com>')
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
it 'handles array of bcc emails' do
|
|
106
|
+
mail = mail(:bcc => ['test1@example.com', 'test2@example.com'])
|
|
107
|
+
message = described_class.new(mail, location: location)
|
|
108
|
+
expect(message.bcc).to eq('test1@example.com, test2@example.com')
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
it 'handles array of bcc emails with display names' do
|
|
112
|
+
mail = mail(:bcc => ['test <test1@example.com>', 'test2 <test2@example.com>'])
|
|
113
|
+
message = described_class.new(mail, location: location)
|
|
114
|
+
expect(message.bcc).to eq('test <test1@example.com>, test2 <test2@example.com>')
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
describe '#sender' do
|
|
120
|
+
it 'handles one email as a string' do
|
|
121
|
+
mail = mail(:sender => 'sender@example.com')
|
|
122
|
+
message = described_class.new(mail, location: location)
|
|
123
|
+
expect(message.sender).to eq('sender@example.com')
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
it 'handles one email as a string with display name' do
|
|
127
|
+
mail = mail(:sender => 'test <test@example.com>')
|
|
128
|
+
message = described_class.new(mail, location: location)
|
|
129
|
+
expect(message.sender).to eq('test <test@example.com>')
|
|
22
130
|
end
|
|
23
131
|
|
|
24
132
|
it 'handles array of emails' do
|
|
25
|
-
|
|
26
|
-
message.
|
|
133
|
+
mail = mail(:sender => ['sender1@example.com', 'sender2@example.com'])
|
|
134
|
+
message = described_class.new(mail, location: location)
|
|
135
|
+
expect(message.sender).to eq('sender1@example.com, sender2@example.com')
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
it 'handles array of emails with display names' do
|
|
139
|
+
mail = mail(:sender => ['test <test1@example.com>', 'test2 <test2@example.com>'])
|
|
140
|
+
message = described_class.new(mail, location: location)
|
|
141
|
+
expect(message.sender).to eq('test <test1@example.com>, test2 <test2@example.com>')
|
|
27
142
|
end
|
|
143
|
+
|
|
28
144
|
end
|
|
29
145
|
|
|
30
146
|
describe '#<=>' do
|
|
31
147
|
it 'sorts rich type before plain type' do
|
|
32
|
-
plain = described_class.new(
|
|
33
|
-
rich
|
|
34
|
-
[plain, rich].sort.
|
|
148
|
+
plain = described_class.new(double(content_type: 'text/plain'), location: location)
|
|
149
|
+
rich = described_class.new(double(content_type: 'text/html'), location: location)
|
|
150
|
+
expect([plain, rich].sort).to eq([rich, plain])
|
|
151
|
+
end
|
|
152
|
+
end
|
|
153
|
+
|
|
154
|
+
describe '#auto_link' do
|
|
155
|
+
let(:message){ described_class.new(mail, location: location) }
|
|
156
|
+
|
|
157
|
+
it 'does not modify unlinkable text' do
|
|
158
|
+
text = 'the quick brown fox jumped over the lazy dog'
|
|
159
|
+
expect(message.auto_link(text)).to eq(text)
|
|
160
|
+
end
|
|
161
|
+
|
|
162
|
+
it 'adds links for http' do
|
|
163
|
+
raw = "Link to http://localhost:3000/example/path path"
|
|
164
|
+
linked = "Link to <a href=\"http://localhost:3000/example/path\">http://localhost:3000/example/path</a> path"
|
|
165
|
+
expect(message.auto_link(raw)).to eq(linked)
|
|
166
|
+
end
|
|
167
|
+
end
|
|
168
|
+
|
|
169
|
+
describe '#body' do
|
|
170
|
+
it 'handles UTF-8 charset body correctly, with QP CTE, for a non-multipart message' do
|
|
171
|
+
mail = mail(:sender => 'sender@example.com') do
|
|
172
|
+
content_type "text/html; charset=UTF-8"
|
|
173
|
+
content_transfer_encoding 'quoted-printable'
|
|
174
|
+
body "☃"
|
|
175
|
+
end
|
|
176
|
+
message = message = described_class.new(mail, location: location)
|
|
177
|
+
expect(message.body.encoding.name).to eq('UTF-8')
|
|
178
|
+
end
|
|
179
|
+
|
|
180
|
+
it 'handles UTF-8 charset HTML part body correctly, with QP CTE, for a multipart message' do
|
|
181
|
+
mail = mail(:sender => 'sender@example.com') do
|
|
182
|
+
html_part do
|
|
183
|
+
content_type "text/html; charset=UTF-8"
|
|
184
|
+
content_transfer_encoding 'quoted-printable'
|
|
185
|
+
body "☃"
|
|
186
|
+
end
|
|
187
|
+
end
|
|
188
|
+
message = described_class.new(mail, location: location, part: mail.html_part)
|
|
189
|
+
expect(message.body.encoding.name).to eq('UTF-8')
|
|
190
|
+
end
|
|
191
|
+
|
|
192
|
+
it 'handles UTF-8 charset text part body correctly, with QP CTE, for a multipart message' do
|
|
193
|
+
mail = mail(:sender => 'sender@example.com') do
|
|
194
|
+
text_part do
|
|
195
|
+
content_type "text/plain; charset=UTF-8"
|
|
196
|
+
content_transfer_encoding 'quoted-printable'
|
|
197
|
+
body "☃"
|
|
198
|
+
end
|
|
199
|
+
end
|
|
200
|
+
message = described_class.new(mail, location: location, part: mail.text_part)
|
|
201
|
+
expect(message.body.encoding.name).to eq('UTF-8')
|
|
202
|
+
end
|
|
203
|
+
end
|
|
204
|
+
|
|
205
|
+
describe '.rendered_messages' do
|
|
206
|
+
it 'uses configured default template if options not given' do
|
|
207
|
+
allow(LetterOpener.configuration).to receive(:location) { location }
|
|
208
|
+
messages = described_class.rendered_messages(mail)
|
|
209
|
+
expect(messages.first.template).not_to be_nil
|
|
210
|
+
end
|
|
211
|
+
|
|
212
|
+
it 'fails if necessary defaults are not provided' do
|
|
213
|
+
allow(LetterOpener.configuration).to receive(:location) { nil }
|
|
214
|
+
expect { described_class.rendered_messages(mail) }.to raise_error(ArgumentError)
|
|
215
|
+
end
|
|
216
|
+
|
|
217
|
+
it 'fails if necessary defaults are not provided' do
|
|
218
|
+
allow(LetterOpener.configuration).to receive(:message_template) { nil }
|
|
219
|
+
expect { described_class.rendered_messages(mail) }.to raise_error(ArgumentError)
|
|
35
220
|
end
|
|
36
221
|
end
|
|
37
222
|
end
|