forked from mikel/mail
/
common_address_spec.rb
113 lines (89 loc) · 4.67 KB
/
common_address_spec.rb
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# encoding: utf-8
require File.join(File.dirname(File.expand_path(__FILE__)), '..', '..', '..', 'spec_helper')
describe Mail::CommonAddress do
describe "address handling" do
it "should give the addresses it is going to" do
field = Mail::ToField.new("To", "test1@lindsaar.net")
field.addresses.first.should == "test1@lindsaar.net"
end
it "should split up the address list into individual addresses" do
field = Mail::ToField.new("To", "test1@lindsaar.net, test2@lindsaar.net")
field.addresses.should == ["test1@lindsaar.net", "test2@lindsaar.net"]
end
it "should give the formatted addresses" do
field = Mail::ToField.new("To", "Mikel <test1@lindsaar.net>, Bob <test2@lindsaar.net>")
field.formatted.should == ["Mikel <test1@lindsaar.net>", "Bob <test2@lindsaar.net>"]
end
it "should give the display names" do
field = Mail::ToField.new("To", "Mikel <test1@lindsaar.net>, Bob <test2@lindsaar.net>")
field.display_names.should == ["Mikel", "Bob"]
end
it "should give the actual address objects" do
field = Mail::ToField.new("To", "Mikel <test1@lindsaar.net>, Bob <test2@lindsaar.net>")
field.addrs.each do |addr|
addr.class.should == Mail::Address
end
end
it "should handle groups as well" do
field = Mail::ToField.new("To", "test1@lindsaar.net, group: test2@lindsaar.net, me@lindsaar.net;")
field.addresses.should == ["test1@lindsaar.net", "test2@lindsaar.net", "me@lindsaar.net"]
end
it "should provide a list of groups" do
field = Mail::ToField.new("To", "test1@lindsaar.net, My Group: test2@lindsaar.net, me@lindsaar.net;")
field.group_names.should == ["My Group"]
end
it "should provide a list of addresses per group" do
field = Mail::ToField.new("To", "test1@lindsaar.net, My Group: test2@lindsaar.net, me@lindsaar.net;")
field.groups["My Group"].length.should == 2
field.groups["My Group"].first.to_s.should == 'test2@lindsaar.net'
field.groups["My Group"].last.to_s.should == 'me@lindsaar.net'
end
it "should provide a list of addresses that are just in the groups" do
field = Mail::ToField.new("To", "test1@lindsaar.net, My Group: test2@lindsaar.net, me@lindsaar.net;")
field.group_addresses.should == ['test2@lindsaar.net', 'me@lindsaar.net']
end
it "should handle initializing as an empty string" do
field = Mail::ToField.new("To", "")
field.addresses.should == []
field.value = 'mikel@test.lindsaar.net'
field.addresses.should == ['mikel@test.lindsaar.net']
end
it "should encode to an empty string if it has no addresses or groups" do
field = Mail::ToField.new("To", "")
field.encoded.should == ''
field.value = 'mikel@test.lindsaar.net'
field.encoded.should == "To: mikel@test.lindsaar.net\r\n"
end
it "should allow you to append an address" do
field = Mail::ToField.new("To", "")
field << 'mikel@test.lindsaar.net'
field.addresses.should == ["mikel@test.lindsaar.net"]
end
end
describe "encoding and decoding fields" do
it "should allow us to encode an address field" do
field = Mail::ToField.new("test1@lindsaar.net, My Group: test2@lindsaar.net, me@lindsaar.net;")
field.encoded.should == "To: test1@lindsaar.net, \r\n\tMy Group: test2@lindsaar.net, \r\n\tme@lindsaar.net;\r\n"
end
it "should allow us to encode a simple address field" do
field = Mail::ToField.new("test1@lindsaar.net")
field.encoded.should == "To: test1@lindsaar.net\r\n"
end
it "should allow us to encode an address field" do
field = Mail::CcField.new("test1@lindsaar.net, My Group: test2@lindsaar.net, me@lindsaar.net;")
field.encoded.should == "Cc: test1@lindsaar.net, \r\n\tMy Group: test2@lindsaar.net, \r\n\tme@lindsaar.net;\r\n"
end
it "should allow us to decode an address field" do
field = Mail::ToField.new("test1@lindsaar.net, My Group: test2@lindsaar.net, me@lindsaar.net;")
field.decoded.should == "test1@lindsaar.net, My Group: test2@lindsaar.net, me@lindsaar.net;"
end
it "should allow us to decode a non ascii address field" do
field = Mail::ToField.new("=?UTF-8?B?44G/44GR44KL?= <raasdnil@text.lindsaar.net>")
field.decoded.should == '"みける" <raasdnil@text.lindsaar.net>'
end
it "should allow us to decode a non ascii address field" do
field = Mail::ToField.new("=?UTF-8?B?44G/44GR44KL?= <raasdnil@text.lindsaar.net>, =?UTF-8?B?44G/44GR44KL?= <mikel@text.lindsaar.net>")
field.decoded.should == '"みける" <raasdnil@text.lindsaar.net>, "みける" <mikel@text.lindsaar.net>'
end
end
end