ppl 1.25.0 → 2.0.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.
Files changed (34) hide show
  1. checksums.yaml +4 -4
  2. data/features/email.feature +10 -0
  3. data/features/ls.feature +15 -0
  4. data/features/post.feature +24 -0
  5. data/features/step_definitions/ppl_steps.rb +17 -0
  6. data/lib/ppl/adapter/vcard/greencard.rb +49 -19
  7. data/lib/ppl/application/bootstrap.rb +13 -3
  8. data/lib/ppl/application/shell.rb +2 -0
  9. data/lib/ppl/command/post.rb +60 -16
  10. data/lib/ppl/entity/contact.rb +10 -4
  11. data/lib/ppl/entity/postal_address.rb +6 -0
  12. data/lib/ppl/error/postal_address_not_found.rb +4 -0
  13. data/lib/ppl/format/address_book/postal_addresses.rb +5 -18
  14. data/lib/ppl/format/contact/full.rb +5 -6
  15. data/lib/ppl/format/contact/postal_addresses.rb +26 -0
  16. data/lib/ppl/format/custom/contact.rb +8 -12
  17. data/lib/ppl/format/postal_address/multi_line.rb +16 -0
  18. data/lib/ppl/format/postal_address/one_line.rb +21 -9
  19. data/lib/ppl/service/postal_address.rb +65 -0
  20. data/lib/ppl.rb +5 -1
  21. data/ppl.gemspec +4 -4
  22. data/spec/ppl/adapter/vcard/greencard_spec.rb +151 -98
  23. data/spec/ppl/application/bootstrap_spec.rb +14 -2
  24. data/spec/ppl/application/shell_spec.rb +8 -0
  25. data/spec/ppl/command/post_spec.rb +83 -61
  26. data/spec/ppl/entity/contact_spec.rb +40 -10
  27. data/spec/ppl/entity/postal_address_spec.rb +6 -0
  28. data/spec/ppl/format/address_book/postal_addresses_spec.rb +6 -14
  29. data/spec/ppl/format/contact/full_spec.rb +1 -1
  30. data/spec/ppl/format/contact/postal_addresses_spec.rb +36 -0
  31. data/spec/ppl/format/postal_address/multi_line_spec.rb +57 -0
  32. data/spec/ppl/format/postal_address/one_line_spec.rb +32 -18
  33. data/spec/ppl/service/postal_address_spec.rb +152 -0
  34. metadata +13 -4
@@ -24,6 +24,12 @@ describe Ppl::Entity::Contact do
24
24
  end
25
25
  end
26
26
 
27
+ describe "#postal_addresses" do
28
+ it "should return an array" do
29
+ @contact.postal_addresses.should be_a(Array)
30
+ end
31
+ end
32
+
27
33
  describe "#birthday" do
28
34
  it "should return a value" do
29
35
  @contact.birthday.should eq nil
@@ -36,16 +42,6 @@ describe Ppl::Entity::Contact do
36
42
  end
37
43
  end
38
44
 
39
- describe "#has_email_address?" do
40
- it "should know if the contact has the given email address" do
41
- @contact.email_addresses.push "test@example.org"
42
- @contact.has_email_address?("test@example.org").should eq true
43
- end
44
- it "should know if the contact lacks the given email address" do
45
- @contact.has_email_address?("test@example.org").should eq false
46
- end
47
- end
48
-
49
45
  describe "#urls" do
50
46
  it "should return an array" do
51
47
  @contact.urls.should be_a(Array)
@@ -80,5 +76,39 @@ describe Ppl::Entity::Contact do
80
76
  end
81
77
  end
82
78
 
79
+ describe "#preferred_email_address" do
80
+
81
+ before(:each) do
82
+ @contact.email_addresses << Ppl::Entity::EmailAddress.new
83
+ end
84
+
85
+ it "returns nil if there's no preferred address" do
86
+ @contact.preferred_email_address.should eq nil
87
+ end
88
+
89
+ it "returns the preferred email address" do
90
+ @contact.email_addresses[0].preferred = true
91
+ @contact.preferred_email_address.should be_a(Ppl::Entity::EmailAddress)
92
+ end
93
+
94
+ end
95
+
96
+ describe "#preferred_phone_number" do
97
+
98
+ before(:each) do
99
+ @contact.phone_numbers << Ppl::Entity::PhoneNumber.new
100
+ end
101
+
102
+ it "returns nil if there's no preferred number" do
103
+ @contact.preferred_phone_number.should eq nil
104
+ end
105
+
106
+ it "returns the preferred phone number" do
107
+ @contact.phone_numbers[0].preferred = true
108
+ @contact.preferred_phone_number.should be_a(Ppl::Entity::PhoneNumber)
109
+ end
110
+
111
+ end
112
+
83
113
  end
84
114
 
@@ -5,6 +5,12 @@ describe Ppl::Entity::PostalAddress do
5
5
  @address = Ppl::Entity::PostalAddress.new
6
6
  end
7
7
 
8
+ describe "#preferred" do
9
+ it "should be false by default" do
10
+ @address.preferred.should eq false
11
+ end
12
+ end
13
+
8
14
  describe "#street" do
9
15
  it "should return a value" do
10
16
  @address.street.should be nil
@@ -3,7 +3,7 @@ describe Ppl::Format::AddressBook::PostalAddresses do
3
3
  describe "#initialize" do
4
4
  it "should pass the colors through to the table" do
5
5
  colors = {"id" => "blue"}
6
- Ppl::Format::Table.should_receive(:new).with([:id, :postal_address], colors)
6
+ Ppl::Format::Table.should_receive(:new).with([:id, :address_ids], colors)
7
7
  format = Ppl::Format::AddressBook::PostalAddresses.new(colors)
8
8
  end
9
9
  end
@@ -18,8 +18,9 @@ describe Ppl::Format::AddressBook::PostalAddresses do
18
18
  @address = Ppl::Entity::PostalAddress.new
19
19
  @table = double(Ppl::Format::Table)
20
20
 
21
+ @address.id = "home"
21
22
  @contact.id = "test"
22
- @contact.postal_address = @address
23
+ @contact.postal_addresses << @address
23
24
  @format.table = @table
24
25
 
25
26
  @address_book.contacts.push(@contact)
@@ -27,19 +28,10 @@ describe Ppl::Format::AddressBook::PostalAddresses do
27
28
 
28
29
  describe "#process" do
29
30
 
30
- it "should at least show the contact's id" do
31
+ it "shows the contact's and address' IDs" do
31
32
  @table.should_receive(:add_row).with({
32
- :id => "test:",
33
- :postal_address => "",
34
- })
35
- @format.process(@address_book)
36
- end
37
-
38
- it "should show the postal address if it's available" do
39
- @address.street = "1 Test Road"
40
- @table.should_receive(:add_row).with({
41
- :id => "test:",
42
- :postal_address => "1 Test Road",
33
+ :id => "test:",
34
+ :address_ids => "home",
43
35
  })
44
36
  @format.process(@address_book)
45
37
  end
@@ -64,7 +64,7 @@ describe Ppl::Format::Contact::Full do
64
64
  end
65
65
 
66
66
  it "should show their postal address if available" do
67
- @contact.postal_address = @address
67
+ @contact.postal_addresses << @address
68
68
  @postal_address_format.should_receive(:process).and_return("")
69
69
  @format.process(@contact)
70
70
  end
@@ -0,0 +1,36 @@
1
+
2
+ describe Ppl::Format::Contact::PostalAddresses do
3
+ describe "#initialize" do
4
+ it "should pass the colors through to the table" do
5
+ colors = {"address_id" => "blue"}
6
+ Ppl::Format::Table.should_receive(:new).with([:star, :address_id, :address_text], colors)
7
+ format = Ppl::Format::Contact::PostalAddresses.new(colors)
8
+ end
9
+ end
10
+ end
11
+
12
+ describe Ppl::Format::Contact::PostalAddresses do
13
+
14
+ before(:each) do
15
+ @format = Ppl::Format::Contact::PostalAddresses.new
16
+ @contact = Ppl::Entity::Contact.new
17
+ @address = Ppl::Entity::PostalAddress.new
18
+ @table = double(Ppl::Format::Table)
19
+ @pa_fmt = double(Ppl::Format::PostalAddress)
20
+ @format.table = @table
21
+ @format.postal_address_format = @pa_fmt
22
+ end
23
+
24
+ describe "#process" do
25
+
26
+ it "passes each postal address to the postal address formatter" do
27
+ @contact.postal_addresses << @address
28
+ @pa_fmt.should_receive(:process).with(@address, @table)
29
+ @table.should_receive(:to_s)
30
+ @format.process(@contact)
31
+ end
32
+
33
+ end
34
+
35
+ end
36
+
@@ -0,0 +1,57 @@
1
+
2
+ describe Ppl::Format::PostalAddress::MultiLine do
3
+
4
+ before(:each) do
5
+ @format = Ppl::Format::PostalAddress::MultiLine.new
6
+ @address = Ppl::Entity::PostalAddress.new
7
+ end
8
+
9
+ describe "#process" do
10
+
11
+ context "all address attributes contain a value" do
12
+
13
+ before(:each) do
14
+ @address.id = "home"
15
+ @address.street = "123 Happy Lane"
16
+ @address.country = "United Kingdom"
17
+ @address.locality = "Bristol"
18
+ @address.po_box = "12345"
19
+ @address.postal_code = "BS1 1SB"
20
+ @address.region = "A very nice region indeed"
21
+ end
22
+
23
+ it "outputs each address attribute on its own line" do
24
+ @lines = @format.process(@address).split "\n"
25
+ @lines[0].should eq "123 Happy Lane"
26
+ @lines[1].should eq "Bristol"
27
+ @lines[2].should eq "A very nice region indeed"
28
+ @lines[3].should eq "United Kingdom"
29
+ @lines[4].should eq "12345"
30
+ @lines[5].should eq "BS1 1SB"
31
+ end
32
+
33
+ end
34
+
35
+ context "some empty address attributes" do
36
+
37
+ before(:each) do
38
+ @address.id = "home"
39
+ @address.street = "123 Happy Lane"
40
+ @address.country = "United Kingdom"
41
+ @address.locality = "Bristol"
42
+ end
43
+
44
+ it "doesn't output superfluous blank lines" do
45
+ @lines = @format.process(@address).split "\n"
46
+ @lines.length.should eq 3
47
+ @lines[0].should eq "123 Happy Lane"
48
+ @lines[1].should eq "Bristol"
49
+ @lines[2].should eq "United Kingdom"
50
+ end
51
+
52
+ end
53
+
54
+ end
55
+
56
+ end
57
+
@@ -3,39 +3,53 @@ describe Ppl::Format::PostalAddress::OneLine do
3
3
 
4
4
  before(:each) do
5
5
  @format = Ppl::Format::PostalAddress::OneLine.new
6
+ @table = double(Ppl::Format::Table)
6
7
  @address = Ppl::Entity::PostalAddress.new
7
8
  end
8
9
 
9
10
  describe "#process" do
10
11
 
11
- it "should include the country if available" do
12
- @address.country = "UK"
13
- @format.process(@address).should include "UK"
12
+ before(:each) do
13
+ @address.id = "home"
14
+ @address.street = "123 Happy Lane"
15
+ @address.country = "United Kingdom"
14
16
  end
15
17
 
16
- it "should include the locality if available" do
17
- @address.locality = "Liverpool"
18
- @format.process(@address).should include "Liverpool"
18
+ after(:each) do
19
+ @format.process(@address, @table)
19
20
  end
20
21
 
21
- it "should include the street if available" do
22
- @address.street = "1 Test Road"
23
- @format.process(@address).should include "1 Test Road"
22
+ it "inserts a blank 'star' column" do
23
+ @table.should_receive(:add_row) { |r| r[:star].should eq " " }
24
24
  end
25
25
 
26
- it "should include the po box if available" do
27
- @address.po_box = "123456"
28
- @format.process(@address).should include "123456"
26
+ it "marks preferred addresses with a star" do
27
+ @address.preferred = true
28
+ @table.should_receive(:add_row) { |r| r[:star].should eq "*" }
29
29
  end
30
30
 
31
- it "should include the postal code if available" do
32
- @address.postal_code = "L1 9AA"
33
- @format.process(@address).should include "L1 9AA"
31
+ it "puts the ID in its own column" do
32
+ @table.should_receive(:add_row) { |r| r[:address_id].should eq "home" }
34
33
  end
35
34
 
36
- it "should include the region if available" do
37
- @address.region = "Merseyside"
38
- @format.process(@address).should include "Merseyside"
35
+ it "concatenates the rest of the address in its own column" do
36
+ @address.country = nil
37
+ @table.should_receive(:add_row) do |row|
38
+ row[:address_text].should eq "123 Happy Lane"
39
+ end
40
+ end
41
+
42
+ it "separates address elements with commas" do
43
+ @table.should_receive(:add_row) do |row|
44
+ row[:address_text].should eq "123 Happy Lane, United Kingdom"
45
+ end
46
+ end
47
+
48
+ it "prunes elements that are empty" do
49
+ @address.country = ""
50
+ @table.should_receive(:add_row) do |row|
51
+ row[:address_text].should eq "123 Happy Lane"
52
+ end
39
53
  end
40
54
 
41
55
  end
@@ -0,0 +1,152 @@
1
+
2
+ describe Ppl::Service::PostalAddress do
3
+
4
+ before(:each) do
5
+ @service = Ppl::Service::PostalAddress.new
6
+ @contact = Ppl::Entity::Contact.new
7
+ @address = Ppl::Entity::PostalAddress.new
8
+ end
9
+
10
+ describe "#add" do
11
+
12
+ before(:each) do
13
+ @service.add(@contact, "home", {
14
+ :country => "United Kingdom",
15
+ :locality => "Bristol",
16
+ :street => "1 Broad Mead",
17
+ :po_box => "550011",
18
+ :postal_code => "BS1 1SB",
19
+ :region => "South West",
20
+ })
21
+ @address = @contact.postal_addresses.first
22
+ end
23
+
24
+ it "adds one postal address to the contact" do
25
+ @contact.postal_addresses.length.should eq 1
26
+ end
27
+
28
+ it "sets the country of the new address" do
29
+ @address.country.should eq "United Kingdom"
30
+ end
31
+ it "sets the locality of the new address" do
32
+ @address.locality.should eq "Bristol"
33
+ end
34
+ it "sets the street of the new address" do
35
+ @address.street.should eq "1 Broad Mead"
36
+ end
37
+ it "sets the PO box of the new address" do
38
+ @address.po_box.should eq "550011"
39
+ end
40
+ it "sets the postal code of the new address" do
41
+ @address.postal_code.should eq "BS1 1SB"
42
+ end
43
+ it "sets the region of the new address" do
44
+ @address.region.should eq "South West"
45
+ end
46
+ end
47
+
48
+
49
+ describe "#update" do
50
+
51
+ before(:each) do
52
+ @address.id = "home"
53
+ @contact.postal_addresses << @address
54
+ @service.update(@contact, "home", {
55
+ :country => "United Kingdom",
56
+ :locality => "Bristol",
57
+ :street => "1 Broad Mead",
58
+ :po_box => "550011",
59
+ :postal_code => "BS1 1SB",
60
+ :region => "South West",
61
+ })
62
+ end
63
+
64
+ it "doesn't change the number of addresses owned by the contact" do
65
+ @contact.postal_addresses.length.should eq 1
66
+ end
67
+ it "sets the country of the new address" do
68
+ @address.country.should eq "United Kingdom"
69
+ end
70
+ it "sets the locality of the new address" do
71
+ @address.locality.should eq "Bristol"
72
+ end
73
+ it "sets the street of the new address" do
74
+ @address.street.should eq "1 Broad Mead"
75
+ end
76
+ it "sets the PO box of the new address" do
77
+ @address.po_box.should eq "550011"
78
+ end
79
+ it "sets the postal code of the new address" do
80
+ @address.postal_code.should eq "BS1 1SB"
81
+ end
82
+ it "sets the region of the new address" do
83
+ @address.region.should eq "South West"
84
+ end
85
+ end
86
+
87
+
88
+ describe "#update" do
89
+
90
+ before(:each) do
91
+ @address.id = "home"
92
+ @contact.postal_addresses << @address
93
+ end
94
+
95
+ it "allows addresses to be moved" do
96
+ @service.should_receive(:move)
97
+ @service.update(@contact, "home", {:new_id => "work"})
98
+ end
99
+
100
+ it "sets addresses as preferred" do
101
+ second_address = Ppl::Entity::PostalAddress.new
102
+ second_address.id = "other"
103
+ second_address.preferred = true
104
+ @contact.postal_addresses << second_address
105
+ @service.update(@contact, "home", {:preferred => true})
106
+ @address.preferred.should eq true
107
+ second_address.preferred.should eq false
108
+ end
109
+
110
+ it "sets addresses as not preferred" do
111
+ @address.preferred = true
112
+ @service.update(@contact, "home", {:preferred => false})
113
+ @address.preferred.should eq false
114
+ end
115
+
116
+ end
117
+
118
+ describe "#move" do
119
+ before(:each) do
120
+ @address.id = "home"
121
+ @contact.postal_addresses << @address
122
+ other_address = Ppl::Entity::PostalAddress.new
123
+ other_address.id = "other"
124
+ @contact.postal_addresses << other_address
125
+ end
126
+ it "raises an error if the new ID is already in use" do
127
+ expect{@service.move(@contact, "home", "other")}.to raise_error
128
+ end
129
+ it "moves the address to the new ID" do
130
+ @service.move(@contact, "home", "available")
131
+ @address.id.should eq "available"
132
+ end
133
+ end
134
+
135
+ describe "#remove" do
136
+ before(:each) do
137
+ @address.id = "home"
138
+ @contact.postal_addresses << @address
139
+ @service.remove(@contact, "home")
140
+ end
141
+
142
+ it "removes the specified address" do
143
+ @contact.postal_addresses.length.should eq 0
144
+ end
145
+
146
+ it "raises an error if there is no such address" do
147
+ expect{@service.remove(@contact, "home")}.to raise_error(Ppl::Error::PostalAddressNotFound)
148
+ end
149
+ end
150
+
151
+ end
152
+
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ppl
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.25.0
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Henry Smith
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-04-24 00:00:00.000000000 Z
11
+ date: 2013-05-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: colored
@@ -150,7 +150,8 @@ dependencies:
150
150
  - - '>='
151
151
  - !ruby/object:Gem::Version
152
152
  version: '0'
153
- description: CLI Address Book
153
+ description: ppl is a command-line address book using vCard & git for storage and
154
+ synchronisation
154
155
  email: henry@henrysmith.org
155
156
  executables:
156
157
  - ppl
@@ -177,6 +178,7 @@ files:
177
178
  - features/nick.feature
178
179
  - features/org.feature
179
180
  - features/phone.feature
181
+ - features/post.feature
180
182
  - features/rm.feature
181
183
  - features/step_definitions/address_book_steps.rb
182
184
  - features/step_definitions/cwd_steps.rb
@@ -232,6 +234,7 @@ files:
232
234
  - lib/ppl/error/completion_not_found.rb
233
235
  - lib/ppl/error/contact_not_found.rb
234
236
  - lib/ppl/error/incorrect_usage.rb
237
+ - lib/ppl/error/postal_address_not_found.rb
235
238
  - lib/ppl/format/address_book.rb
236
239
  - lib/ppl/format/address_book/ages.rb
237
240
  - lib/ppl/format/address_book/birthdays.rb
@@ -254,16 +257,19 @@ files:
254
257
  - lib/ppl/format/contact/organization.rb
255
258
  - lib/ppl/format/contact/phone_number.rb
256
259
  - lib/ppl/format/contact/postal_address.rb
260
+ - lib/ppl/format/contact/postal_addresses.rb
257
261
  - lib/ppl/format/contact/urls.rb
258
262
  - lib/ppl/format/custom.rb
259
263
  - lib/ppl/format/custom/contact.rb
260
264
  - lib/ppl/format/custom/email_address.rb
261
265
  - lib/ppl/format/custom/phone_number.rb
262
266
  - lib/ppl/format/postal_address.rb
267
+ - lib/ppl/format/postal_address/multi_line.rb
263
268
  - lib/ppl/format/postal_address/one_line.rb
264
269
  - lib/ppl/format/table.rb
265
270
  - lib/ppl/service/email_address.rb
266
271
  - lib/ppl/service/phone_number.rb
272
+ - lib/ppl/service/postal_address.rb
267
273
  - ppl.gemspec
268
274
  - spec/ppl/adapter/color/colored_spec.rb
269
275
  - spec/ppl/adapter/color_spec.rb
@@ -332,17 +338,20 @@ files:
332
338
  - spec/ppl/format/contact/organization_spec.rb
333
339
  - spec/ppl/format/contact/phone_number_spec.rb
334
340
  - spec/ppl/format/contact/postal_address_spec.rb
341
+ - spec/ppl/format/contact/postal_addresses_spec.rb
335
342
  - spec/ppl/format/contact/urls_spec.rb
336
343
  - spec/ppl/format/contact_spec.rb
337
344
  - spec/ppl/format/custom/contact_spec.rb
338
345
  - spec/ppl/format/custom/email_address_spec.rb
339
346
  - spec/ppl/format/custom/phone_number_spec.rb
340
347
  - spec/ppl/format/custom_spec.rb
348
+ - spec/ppl/format/postal_address/multi_line_spec.rb
341
349
  - spec/ppl/format/postal_address/one_line_spec.rb
342
350
  - spec/ppl/format/postal_address_spec.rb
343
351
  - spec/ppl/format/table_spec.rb
344
352
  - spec/ppl/service/email_address_spec.rb
345
353
  - spec/ppl/service/phone_number_spec.rb
354
+ - spec/ppl/service/postal_address_spec.rb
346
355
  - spec/spec_helper.rb
347
356
  homepage: http://ppladdressbook.org
348
357
  licenses:
@@ -367,5 +376,5 @@ rubyforge_project:
367
376
  rubygems_version: 2.0.3
368
377
  signing_key:
369
378
  specification_version: 4
370
- summary: CLI Address Book
379
+ summary: The command line address book
371
380
  test_files: []