ppl 1.23.0 → 1.24.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 +4 -4
- data/Rakefile +6 -0
- data/features/email.feature +38 -1
- data/features/phone.feature +21 -0
- data/features/step_definitions/ppl_steps.rb +31 -1
- data/lib/ppl/adapter/vcard/greencard.rb +8 -2
- data/lib/ppl/application/bootstrap.rb +14 -0
- data/lib/ppl/command/email.rb +58 -4
- data/lib/ppl/command/mutt.rb +2 -2
- data/lib/ppl/command/phone.rb +46 -31
- data/lib/ppl/entity/email_address.rb +13 -0
- data/lib/ppl/entity/phone_number.rb +2 -0
- data/lib/ppl/format/address_book/email_addresses.rb +4 -1
- data/lib/ppl/format/address_book/mutt_query.rb +1 -1
- data/lib/ppl/format/address_book/one_line.rb +10 -1
- data/lib/ppl/format/contact/email_addresses.rb +7 -17
- data/lib/ppl/format/contact/full.rb +27 -8
- data/lib/ppl/format/contact/phone_number.rb +6 -1
- data/lib/ppl/format/table.rb +2 -2
- data/lib/ppl/service/email_address.rb +37 -0
- data/lib/ppl/service/phone_number.rb +40 -0
- data/lib/ppl.rb +8 -1
- data/ppl.gemspec +2 -2
- data/spec/ppl/adapter/vcard/greencard_spec.rb +40 -2
- data/spec/ppl/command/email_spec.rb +58 -0
- data/spec/ppl/command/mutt_spec.rb +10 -10
- data/spec/ppl/command/phone_spec.rb +30 -26
- data/spec/ppl/entity/email_address_spec.rb +28 -0
- data/spec/ppl/entity/phone_number_spec.rb +6 -0
- data/spec/ppl/format/address_book/email_addresses_spec.rb +1 -1
- data/spec/ppl/format/address_book/mutt_query_spec.rb +2 -2
- data/spec/ppl/format/address_book/one_line_spec.rb +11 -1
- data/spec/ppl/format/contact/email_addresses_spec.rb +27 -13
- data/spec/ppl/format/contact/full_spec.rb +25 -13
- data/spec/ppl/format/contact/phone_number_spec.rb +13 -1
- data/spec/ppl/service/email_address_spec.rb +73 -0
- data/spec/ppl/service/phone_number_spec.rb +75 -0
- metadata +8 -2
@@ -0,0 +1,37 @@
|
|
1
|
+
|
2
|
+
class Ppl::Service::EmailAddress
|
3
|
+
|
4
|
+
attr_writer :storage
|
5
|
+
|
6
|
+
def add(contact, address, options)
|
7
|
+
email_address = Ppl::Entity::EmailAddress.new(address)
|
8
|
+
contact.email_addresses << email_address
|
9
|
+
update_email_address(contact, email_address, options)
|
10
|
+
@storage.save_contact(contact)
|
11
|
+
end
|
12
|
+
|
13
|
+
def update(contact, address, options)
|
14
|
+
email_address = contact.email_addresses.find { |e| e.address == address }
|
15
|
+
update_email_address(contact, email_address, options)
|
16
|
+
@storage.save_contact(contact)
|
17
|
+
end
|
18
|
+
|
19
|
+
def remove(contact, address)
|
20
|
+
contact.email_addresses.select! do |email_address|
|
21
|
+
email_address.address != address
|
22
|
+
end
|
23
|
+
@storage.save_contact(contact)
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def update_email_address(contact, email_address, options)
|
29
|
+
if options[:preferred] == true
|
30
|
+
contact.email_addresses.each { |e| e.preferred = (e.address == email_address.address) }
|
31
|
+
elsif options[:preferred] == false
|
32
|
+
email_address.preferred = false
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
|
@@ -0,0 +1,40 @@
|
|
1
|
+
|
2
|
+
class Ppl::Service::PhoneNumber
|
3
|
+
|
4
|
+
attr_writer :storage
|
5
|
+
|
6
|
+
def add(contact, number, options)
|
7
|
+
phone_number = Ppl::Entity::PhoneNumber.new(number)
|
8
|
+
contact.phone_numbers << phone_number
|
9
|
+
update_phone_number(contact, phone_number, options)
|
10
|
+
@storage.save_contact(contact)
|
11
|
+
end
|
12
|
+
|
13
|
+
def update(contact, number, options)
|
14
|
+
matching_numbers = contact.phone_numbers.select { |p| p.number == number }
|
15
|
+
matching_numbers.each { |mn| update_phone_number(contact, mn, options) }
|
16
|
+
@storage.save_contact(contact)
|
17
|
+
end
|
18
|
+
|
19
|
+
def remove(contact, number)
|
20
|
+
contact.phone_numbers.select! do |phone_number|
|
21
|
+
phone_number.number != number
|
22
|
+
end
|
23
|
+
@storage.save_contact(contact)
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def update_phone_number(contact, phone_number, options)
|
29
|
+
if options[:type]
|
30
|
+
phone_number.type = options[:type]
|
31
|
+
end
|
32
|
+
if options[:preferred] == true
|
33
|
+
contact.phone_numbers.each { |p| p.preferred = (p.number == phone_number.number) }
|
34
|
+
elsif options[:preferred] == false
|
35
|
+
phone_number.preferred = false
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
|
data/lib/ppl.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
|
2
2
|
module Ppl
|
3
3
|
|
4
|
-
Version = "1.
|
4
|
+
Version = "1.24.0"
|
5
5
|
|
6
6
|
module Adapter
|
7
7
|
end
|
@@ -21,6 +21,9 @@ module Ppl
|
|
21
21
|
module Format
|
22
22
|
end
|
23
23
|
|
24
|
+
module Service
|
25
|
+
end
|
26
|
+
|
24
27
|
end
|
25
28
|
|
26
29
|
|
@@ -70,6 +73,7 @@ require "ppl/command/scrape"
|
|
70
73
|
|
71
74
|
require "ppl/entity/address_book"
|
72
75
|
require "ppl/entity/contact"
|
76
|
+
require "ppl/entity/email_address"
|
73
77
|
require "ppl/entity/phone_number"
|
74
78
|
require "ppl/entity/postal_address"
|
75
79
|
|
@@ -104,6 +108,9 @@ require "ppl/format/postal_address"
|
|
104
108
|
require "ppl/format/postal_address/one_line"
|
105
109
|
require "ppl/format/table"
|
106
110
|
|
111
|
+
require "ppl/service/email_address"
|
112
|
+
require "ppl/service/phone_number"
|
113
|
+
|
107
114
|
class String
|
108
115
|
alias_method :each, :each_line
|
109
116
|
end
|
data/ppl.gemspec
CHANGED
@@ -19,15 +19,28 @@ describe Ppl::Adapter::Vcard::GreenCard, "#encode" do
|
|
19
19
|
end
|
20
20
|
|
21
21
|
it "should encode the contact's email address" do
|
22
|
-
@contact.email_addresses
|
22
|
+
@contact.email_addresses << Ppl::Entity::EmailAddress.new("john@example.org")
|
23
23
|
@adapter.encode(@contact).should include("EMAIL:john@example.org")
|
24
24
|
end
|
25
25
|
|
26
|
+
it "should encode the contact's preferred email address as such" do
|
27
|
+
email_address = Ppl::Entity::EmailAddress.new("john@example.org")
|
28
|
+
email_address.preferred = true
|
29
|
+
@contact.email_addresses << email_address
|
30
|
+
@adapter.encode(@contact).should include("EMAIL;TYPE=pref:john@example.org")
|
31
|
+
end
|
32
|
+
|
26
33
|
it "should encode the contact's phone number" do
|
27
34
|
@contact.phone_numbers << Ppl::Entity::PhoneNumber.new("01234567890")
|
28
35
|
@adapter.encode(@contact).should include("TEL:01234567890")
|
29
36
|
end
|
30
37
|
|
38
|
+
it "should encode the contact's preferred phone number as such" do
|
39
|
+
@contact.phone_numbers << Ppl::Entity::PhoneNumber.new("01234567890")
|
40
|
+
@contact.phone_numbers[0].preferred = true
|
41
|
+
@adapter.encode(@contact).should include("TEL;TYPE=pref:01234567890")
|
42
|
+
end
|
43
|
+
|
31
44
|
it "should encode the contact's phone number's type" do
|
32
45
|
@contact.phone_numbers << Ppl::Entity::PhoneNumber.new("01234567890", "cell")
|
33
46
|
@adapter.encode(@contact).should include("TEL;TYPE=cell:01234567890")
|
@@ -137,7 +150,19 @@ describe Ppl::Adapter::Vcard::GreenCard, "#decode" do
|
|
137
150
|
"END:VCARD",
|
138
151
|
].join("\n")
|
139
152
|
contact = @adapter.decode(vcard)
|
140
|
-
contact.email_addresses.first.should eq "home@example.org"
|
153
|
+
contact.email_addresses.first.address.should eq "home@example.org"
|
154
|
+
end
|
155
|
+
|
156
|
+
it "should mark preferred email addresses as such" do
|
157
|
+
vcard = [
|
158
|
+
"BEGIN:VCARD",
|
159
|
+
"N:,test",
|
160
|
+
"VERSION:3.0",
|
161
|
+
"EMAIL;PREF:home@example.org",
|
162
|
+
"END:VCARD",
|
163
|
+
].join("\n")
|
164
|
+
contact = @adapter.decode(vcard)
|
165
|
+
contact.email_addresses.first.preferred.should eq true
|
141
166
|
end
|
142
167
|
|
143
168
|
it "should decode the contact's phone number" do
|
@@ -153,6 +178,19 @@ describe Ppl::Adapter::Vcard::GreenCard, "#decode" do
|
|
153
178
|
phone_number.number.should eq "01234567890"
|
154
179
|
end
|
155
180
|
|
181
|
+
it "should mark preferred phone numbers as such" do
|
182
|
+
vcard = [
|
183
|
+
"BEGIN:VCARD",
|
184
|
+
"N:,test",
|
185
|
+
"VERSION:3.0",
|
186
|
+
"TEL;TYPE=pref:01234567890",
|
187
|
+
"END:VCARD",
|
188
|
+
].join("\n")
|
189
|
+
contact = @adapter.decode(vcard)
|
190
|
+
phone_number = contact.phone_numbers.first
|
191
|
+
phone_number.preferred.should eq true
|
192
|
+
end
|
193
|
+
|
156
194
|
it "should decode the contact's phone number's type" do
|
157
195
|
vcard = [
|
158
196
|
"BEGIN:VCARD",
|
@@ -11,5 +11,63 @@ describe Ppl::Command::Email do
|
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
14
|
+
describe "#execute" do
|
15
|
+
|
16
|
+
before(:each) do
|
17
|
+
@contact = Ppl::Entity::Contact.new
|
18
|
+
@service = double(Ppl::Service::EmailAddress)
|
19
|
+
@storage = double(Ppl::Adapter::Storage)
|
20
|
+
@input = Ppl::Application::Input.new
|
21
|
+
@output = double(Ppl::Application::Output)
|
22
|
+
@list_format = double(Ppl::Format::AddressBook)
|
23
|
+
@show_format = double(Ppl::Format::Contact)
|
24
|
+
@storage.stub(:require_contact).and_return(@contact)
|
25
|
+
@storage.stub(:save_contact)
|
26
|
+
@command.storage = @storage
|
27
|
+
@command.email_service = @service
|
28
|
+
@command.list_format = @list_format
|
29
|
+
@command.show_format = @show_format
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should list all email addresses by default" do
|
33
|
+
@storage.should_receive(:load_address_book).and_return(@address_book)
|
34
|
+
@list_format.should_receive(:process).and_return("imagine this is a list")
|
35
|
+
@output.should_receive(:line).with("imagine this is a list")
|
36
|
+
@command.execute(@input, @output)
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should show a single contact's addresses if one is specified" do
|
40
|
+
@input.arguments << "jdoe"
|
41
|
+
@storage.should_receive(:require_contact).and_return(@contact)
|
42
|
+
@show_format.should_receive(:process).and_return("imagine this is a list")
|
43
|
+
@output.should_receive(:line).with("imagine this is a list")
|
44
|
+
@command.execute(@input, @output)
|
45
|
+
end
|
46
|
+
|
47
|
+
it "should delegate to the service layer to add a new email address" do
|
48
|
+
@input.arguments = ["jdoe", "jdoe@example.org"]
|
49
|
+
@storage.should_receive(:require_contact).and_return(@contact)
|
50
|
+
@service.should_receive(:add).with(@contact, "jdoe@example.org", @input.options)
|
51
|
+
@command.execute(@input, @output)
|
52
|
+
end
|
53
|
+
|
54
|
+
it "should delegate to the service layer to update an existing address" do
|
55
|
+
@contact.email_addresses << Ppl::Entity::EmailAddress.new("jdoe@example.org")
|
56
|
+
@input.arguments = ["jdoe", "jdoe@example.org"]
|
57
|
+
@storage.should_receive(:require_contact).and_return(@contact)
|
58
|
+
@service.should_receive(:update).with(@contact, "jdoe@example.org", {})
|
59
|
+
@command.execute(@input, @output)
|
60
|
+
end
|
61
|
+
|
62
|
+
it "should delegate to the service layer to remove an email address" do
|
63
|
+
@input.arguments = ["jdoe", "jdoe@example.org"]
|
64
|
+
@input.options[:delete] = true
|
65
|
+
@storage.should_receive(:require_contact).and_return(@contact)
|
66
|
+
@service.should_receive(:remove).with(@contact, "jdoe@example.org")
|
67
|
+
@command.execute(@input, @output)
|
68
|
+
end
|
69
|
+
|
70
|
+
end
|
71
|
+
|
14
72
|
end
|
15
73
|
|
@@ -37,7 +37,7 @@ describe Ppl::Command::Mutt do
|
|
37
37
|
it "should return email address matches" do
|
38
38
|
|
39
39
|
@contact.name = "Test User"
|
40
|
-
@contact.email_addresses.
|
40
|
+
@contact.email_addresses << Ppl::Entity::EmailAddress.new("test@example.org")
|
41
41
|
@address_book.contacts.push(@contact)
|
42
42
|
|
43
43
|
@input.arguments.push "example"
|
@@ -55,13 +55,13 @@ describe Ppl::Command::Mutt do
|
|
55
55
|
@input.arguments.push "prova"
|
56
56
|
@contact.name = "Test User"
|
57
57
|
|
58
|
-
@contact.email_addresses.
|
59
|
-
@contact.email_addresses.
|
58
|
+
@contact.email_addresses << Ppl::Entity::EmailAddress.new("test@test.org")
|
59
|
+
@contact.email_addresses << Ppl::Entity::EmailAddress.new("prova@prova.org")
|
60
60
|
@address_book.contacts.push(@contact)
|
61
61
|
@storage.stub(:load_address_book).and_return(@address_book)
|
62
62
|
@format.should_receive(:process) do |address_book|
|
63
63
|
address_book.contacts[0].email_addresses.length.should eq 1
|
64
|
-
address_book.contacts[0].email_addresses[0].should eq "prova@prova.org"
|
64
|
+
address_book.contacts[0].email_addresses[0].address.should eq "prova@prova.org"
|
65
65
|
end
|
66
66
|
@output.stub(:line)
|
67
67
|
@command.execute(@input, @output)
|
@@ -70,7 +70,7 @@ describe Ppl::Command::Mutt do
|
|
70
70
|
it "should return name matches" do
|
71
71
|
|
72
72
|
@contact.name = "Test User"
|
73
|
-
@contact.email_addresses.
|
73
|
+
@contact.email_addresses << Ppl::Entity::EmailAddress.new("test@example.org")
|
74
74
|
@address_book.contacts.push(@contact)
|
75
75
|
|
76
76
|
@input.arguments.push "User"
|
@@ -89,8 +89,8 @@ describe Ppl::Command::Mutt do
|
|
89
89
|
@input.arguments.push "org"
|
90
90
|
|
91
91
|
@contact.name = "Test User"
|
92
|
-
@contact.email_addresses.
|
93
|
-
@contact.email_addresses.
|
92
|
+
@contact.email_addresses << Ppl::Entity::EmailAddress.new("test@test.org")
|
93
|
+
@contact.email_addresses << Ppl::Entity::EmailAddress.new("prova@prova.org")
|
94
94
|
@address_book.contacts << @contact
|
95
95
|
|
96
96
|
@storage.stub(:load_address_book).and_return(@address_book)
|
@@ -109,8 +109,8 @@ describe Ppl::Command::Mutt do
|
|
109
109
|
before(:each) do
|
110
110
|
@input.options[:ignore_case] = true
|
111
111
|
@contact.name = "Joe Schmoe"
|
112
|
-
@contact.email_addresses.
|
113
|
-
@contact.email_addresses.
|
112
|
+
@contact.email_addresses << Ppl::Entity::EmailAddress.new("joe@somewhere.com")
|
113
|
+
@contact.email_addresses << Ppl::Entity::EmailAddress.new("LOUD@SHOUTING.COM")
|
114
114
|
@address_book.contacts << @contact
|
115
115
|
@storage.stub(:load_address_book).and_return(@address_book)
|
116
116
|
@output.stub(:line)
|
@@ -128,7 +128,7 @@ describe Ppl::Command::Mutt do
|
|
128
128
|
@input.arguments.push "loud"
|
129
129
|
@format.should_receive(:process) do |address_book|
|
130
130
|
address_book.contacts[0].email_addresses.length.should eq 1
|
131
|
-
address_book.contacts[0].email_addresses[0].should eq "LOUD@SHOUTING.COM"
|
131
|
+
address_book.contacts[0].email_addresses[0].address.should eq "LOUD@SHOUTING.COM"
|
132
132
|
end
|
133
133
|
@command.execute(@input, @output)
|
134
134
|
end
|
@@ -15,51 +15,55 @@ describe Ppl::Command::Phone do
|
|
15
15
|
|
16
16
|
before(:each) do
|
17
17
|
@contact = Ppl::Entity::Contact.new
|
18
|
+
@service = double(Ppl::Service::PhoneNumber)
|
18
19
|
@storage = double(Ppl::Adapter::Storage)
|
20
|
+
@list_format = double(Ppl::Format::AddressBook)
|
21
|
+
@show_format = double(Ppl::Format::Contact)
|
19
22
|
@input = Ppl::Application::Input.new
|
20
|
-
@
|
23
|
+
@output = double(Ppl::Application::Output)
|
21
24
|
@storage.stub(:require_contact).and_return(@contact)
|
22
25
|
@storage.stub(:save_contact)
|
26
|
+
@command.phone_service = @service
|
23
27
|
@command.storage = @storage
|
28
|
+
@command.list_format = @list_format
|
29
|
+
@command.show_format = @show_format
|
24
30
|
end
|
25
31
|
|
26
|
-
it "should
|
27
|
-
@storage.should_receive(:
|
28
|
-
|
29
|
-
|
32
|
+
it "should list all phone numbers by default" do
|
33
|
+
@storage.should_receive(:load_address_book).and_return(@address_book)
|
34
|
+
@list_format.should_receive(:process)
|
35
|
+
@output.should_receive(:line)
|
30
36
|
@command.execute(@input, @output)
|
31
37
|
end
|
32
38
|
|
33
|
-
it "should
|
34
|
-
@
|
35
|
-
|
36
|
-
|
39
|
+
it "should show a single contact's numbers if one is specified" do
|
40
|
+
@input.arguments << "jdoe"
|
41
|
+
@storage.should_receive(:require_contact).and_return(@contact)
|
42
|
+
@show_format.should_receive(:process)
|
43
|
+
@output.should_receive(:line)
|
37
44
|
@command.execute(@input, @output)
|
38
45
|
end
|
39
46
|
|
40
|
-
it "should
|
41
|
-
@input.
|
42
|
-
@
|
43
|
-
|
44
|
-
|
47
|
+
it "should delegate to the service layer to remove a phone number" do
|
48
|
+
@input.arguments = ["jdoe", "01234567890"]
|
49
|
+
@input.options[:delete] = true
|
50
|
+
@storage.should_receive(:require_contact).and_return(@contact)
|
51
|
+
@service.should_receive(:remove).with(@contact, "01234567890")
|
45
52
|
@command.execute(@input, @output)
|
46
53
|
end
|
47
54
|
|
48
|
-
it "
|
49
|
-
@
|
50
|
-
@storage.should_receive(:
|
51
|
-
|
52
|
-
end
|
55
|
+
it "should delegate to the service layer to add a new phone number" do
|
56
|
+
@input.arguments = ["jdoe", "98776332"]
|
57
|
+
@storage.should_receive(:require_contact).and_return(@contact)
|
58
|
+
@service.should_receive(:add).with(@contact, "98776332", @input.options)
|
53
59
|
@command.execute(@input, @output)
|
54
60
|
end
|
55
61
|
|
56
|
-
it "should
|
57
|
-
@
|
58
|
-
@input.
|
59
|
-
@
|
60
|
-
@
|
61
|
-
c.phone_numbers.length.should eq 0
|
62
|
-
end
|
62
|
+
it "should delegate to the service layer to update an existing number" do
|
63
|
+
@contact.phone_numbers << Ppl::Entity::PhoneNumber.new("012345678")
|
64
|
+
@input.arguments = ["jdoe", "012345678"]
|
65
|
+
@storage.should_receive(:require_contact).and_return(@contact)
|
66
|
+
@service.should_receive(:update).with(@contact, "012345678", {})
|
63
67
|
@command.execute(@input, @output)
|
64
68
|
end
|
65
69
|
|
@@ -0,0 +1,28 @@
|
|
1
|
+
|
2
|
+
describe Ppl::Entity::EmailAddress do
|
3
|
+
|
4
|
+
before(:each) do
|
5
|
+
@email_address = Ppl::Entity::EmailAddress.new
|
6
|
+
end
|
7
|
+
|
8
|
+
describe "#address" do
|
9
|
+
it "should return a value" do
|
10
|
+
@email_address.address.should eq nil
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
describe "#preferred" do
|
15
|
+
it "should be false by default" do
|
16
|
+
@email_address.preferred.should eq false
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe "#initialize" do
|
21
|
+
it "should accept an address" do
|
22
|
+
email = Ppl::Entity::EmailAddress.new("bob@example.org")
|
23
|
+
email.address.should eq "bob@example.org"
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
|
@@ -11,6 +11,12 @@ describe Ppl::Entity::PhoneNumber do
|
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
14
|
+
describe "#preferred" do
|
15
|
+
it "should be false by default" do
|
16
|
+
@phone_number.preferred.should eq false
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
14
20
|
describe "#type" do
|
15
21
|
it "should return a value" do
|
16
22
|
@phone_number.type.should eq nil
|
@@ -34,7 +34,7 @@ describe Ppl::Format::AddressBook::EmailAddresses do
|
|
34
34
|
end
|
35
35
|
|
36
36
|
it "should show an email address if it's available" do
|
37
|
-
@contact.email_addresses.
|
37
|
+
@contact.email_addresses << Ppl::Entity::EmailAddress.new("jdoe@example.org")
|
38
38
|
@table.should_receive(:add_row).with({
|
39
39
|
:id => "test:",
|
40
40
|
:email_addresses => "jdoe@example.org",
|
@@ -7,7 +7,7 @@ describe Ppl::Format::AddressBook::MuttQuery do
|
|
7
7
|
@contact = Ppl::Entity::Contact.new
|
8
8
|
@table = double(Ppl::Format::Table)
|
9
9
|
|
10
|
-
@contact.email_addresses.
|
10
|
+
@contact.email_addresses << Ppl::Entity::EmailAddress.new("test@example.org")
|
11
11
|
@contact.name = "Test Contact"
|
12
12
|
|
13
13
|
@format.table = @table
|
@@ -25,7 +25,7 @@ describe Ppl::Format::AddressBook::MuttQuery do
|
|
25
25
|
end
|
26
26
|
|
27
27
|
it "should list all of each contact's email addresses" do
|
28
|
-
@contact.email_addresses.
|
28
|
+
@contact.email_addresses << Ppl::Entity::EmailAddress.new("test2@example.com")
|
29
29
|
@table.should_receive(:add_row).with({
|
30
30
|
:email => "test@example.org",
|
31
31
|
:name => "Test Contact",
|
@@ -36,7 +36,7 @@ describe Ppl::Format::AddressBook::OneLine do
|
|
36
36
|
|
37
37
|
it "should show all the info if it's available" do
|
38
38
|
@contact.name = "John Doe"
|
39
|
-
@contact.email_addresses.
|
39
|
+
@contact.email_addresses << Ppl::Entity::EmailAddress.new("jdoe@example.org")
|
40
40
|
@table.should_receive(:add_row).with({
|
41
41
|
:id => "test:",
|
42
42
|
:name => "John Doe",
|
@@ -45,6 +45,16 @@ describe Ppl::Format::AddressBook::OneLine do
|
|
45
45
|
@format.process(@address_book)
|
46
46
|
end
|
47
47
|
|
48
|
+
it "should show all the info if it's available" do
|
49
|
+
@contact.email_addresses << Ppl::Entity::EmailAddress.new("jdoe@example.org")
|
50
|
+
@contact.email_addresses << Ppl::Entity::EmailAddress.new("fred@testtest.es")
|
51
|
+
@contact.email_addresses[1].preferred = true
|
52
|
+
@table.should_receive(:add_row) do |row|
|
53
|
+
row[:email].should eq "<fred@testtest.es>"
|
54
|
+
end
|
55
|
+
@format.process(@address_book)
|
56
|
+
end
|
57
|
+
|
48
58
|
end
|
49
59
|
|
50
60
|
end
|
@@ -1,28 +1,42 @@
|
|
1
1
|
|
2
|
+
describe Ppl::Format::Contact::EmailAddresses do
|
3
|
+
describe "#initialize" do
|
4
|
+
it "should pass the colors through to the table" do
|
5
|
+
colors = {"id" => "blue"}
|
6
|
+
Ppl::Format::Table.should_receive(:new).with([:star, :email_addresses], colors)
|
7
|
+
format = Ppl::Format::Contact::EmailAddresses.new(colors)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
2
12
|
describe Ppl::Format::Contact::EmailAddresses do
|
3
13
|
|
4
14
|
before(:each) do
|
5
15
|
@format = Ppl::Format::Contact::EmailAddresses.new
|
6
16
|
@contact = Ppl::Entity::Contact.new
|
7
|
-
@
|
8
|
-
@
|
17
|
+
@email = Ppl::Entity::EmailAddress.new("test@example.org")
|
18
|
+
@table = double(Ppl::Format::Table)
|
19
|
+
@format.table = @table
|
20
|
+
@contact.email_addresses << @email
|
9
21
|
end
|
10
22
|
|
11
23
|
describe "#process" do
|
12
24
|
|
13
|
-
it "should
|
14
|
-
@
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
@
|
19
|
-
@format.process(@contact).should eq "jdoe@example.org"
|
25
|
+
it "should pass each email address to the table" do
|
26
|
+
@table.should_receive(:add_row).with({
|
27
|
+
:star => " ",
|
28
|
+
:email_addresses => "test@example.org",
|
29
|
+
})
|
30
|
+
@format.process(@contact)
|
20
31
|
end
|
21
32
|
|
22
|
-
it "should
|
23
|
-
@
|
24
|
-
@
|
25
|
-
|
33
|
+
it "should mark the preferred email with a star" do
|
34
|
+
@email.preferred = true
|
35
|
+
@table.should_receive(:add_row).with({
|
36
|
+
:star => "*",
|
37
|
+
:email_addresses => "test@example.org",
|
38
|
+
})
|
39
|
+
@format.process(@contact)
|
26
40
|
end
|
27
41
|
|
28
42
|
end
|
@@ -6,8 +6,14 @@ describe Ppl::Format::Contact::Full do
|
|
6
6
|
@contact = Ppl::Entity::Contact.new
|
7
7
|
@address = Ppl::Entity::PostalAddress.new
|
8
8
|
|
9
|
+
@email_address_format = double(Ppl::Format::Contact)
|
10
|
+
@phone_number_format = double(Ppl::Format::Contact)
|
9
11
|
@postal_address_format = double(Ppl::Format::Contact)
|
12
|
+
@format.email_address_format = @email_address_format
|
13
|
+
@format.phone_number_format = @phone_number_format
|
10
14
|
@format.postal_address_format = @postal_address_format
|
15
|
+
|
16
|
+
@email_address_format.stub(:process)
|
11
17
|
end
|
12
18
|
|
13
19
|
describe "#process" do
|
@@ -23,27 +29,33 @@ describe Ppl::Format::Contact::Full do
|
|
23
29
|
|
24
30
|
it "should include their email address in brackets" do
|
25
31
|
@contact.name = "John Doe"
|
26
|
-
@contact.email_addresses.
|
32
|
+
@contact.email_addresses << Ppl::Entity::EmailAddress.new("john@example.org")
|
27
33
|
@format.process(@contact).should include "John Doe <john@example.org>"
|
28
34
|
end
|
29
35
|
|
30
|
-
it "should
|
31
|
-
@contact.
|
32
|
-
@contact.email_addresses.
|
33
|
-
@contact.email_addresses.
|
34
|
-
@
|
35
|
-
@format.process(@contact).should include "
|
36
|
-
@format.process(@contact).should include "john@example.net"
|
36
|
+
it "should include their preferred email address in brackets" do
|
37
|
+
@contact.name = "John Doe"
|
38
|
+
@contact.email_addresses << Ppl::Entity::EmailAddress.new("john@example.org")
|
39
|
+
@contact.email_addresses << Ppl::Entity::EmailAddress.new("fred@testtest.es")
|
40
|
+
@contact.email_addresses[1].preferred = true
|
41
|
+
@format.process(@contact).should include "John Doe <fred@testtest.es>"
|
37
42
|
end
|
38
43
|
|
39
|
-
it "should
|
40
|
-
@contact.
|
41
|
-
@
|
44
|
+
it "should invoke the email address formatter if there are any addresses" do
|
45
|
+
@contact.email_addresses << Ppl::Entity::EmailAddress.new("john@example.net")
|
46
|
+
@email_address_format.should_receive(:process).with(@contact)
|
47
|
+
@format.process(@contact)
|
42
48
|
end
|
43
49
|
|
44
|
-
it "should
|
50
|
+
it "should invoke the phone number formatter if there are any numbers" do
|
45
51
|
@contact.phone_numbers << Ppl::Entity::PhoneNumber.new("01234567890")
|
46
|
-
@
|
52
|
+
@phone_number_format.should_receive(:process).with(@contact)
|
53
|
+
@format.process(@contact)
|
54
|
+
end
|
55
|
+
|
56
|
+
it "should show their birthday if available" do
|
57
|
+
@contact.birthday = Date.parse("1980-01-01")
|
58
|
+
@format.process(@contact).should include "1980-01-01"
|
47
59
|
end
|
48
60
|
|
49
61
|
it "should show all their organizations" do
|