motion-addressbook 1.4.0 → 1.5.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 (31) hide show
  1. data/.travis.yml +0 -1
  2. data/README.md +2 -3
  3. data/Rakefile +16 -4
  4. data/lib/motion-addressbook/version.rb +1 -1
  5. data/lib/motion-addressbook.rb +22 -10
  6. data/motion/address_book/{addr_book.rb → ios/addr_book.rb} +0 -0
  7. data/motion/address_book/{group.rb → ios/group.rb} +0 -0
  8. data/motion/address_book/{multi_value.rb → ios/multi_value.rb} +0 -0
  9. data/motion/address_book/{multi_valued.rb → ios/multi_valued.rb} +0 -0
  10. data/motion/address_book/{person.rb → ios/person.rb} +8 -0
  11. data/motion/address_book/{picker.rb → ios/picker.rb} +0 -0
  12. data/motion/address_book/{source.rb → ios/source.rb} +0 -0
  13. data/motion/address_book/osx/addr_book.rb +67 -0
  14. data/motion/address_book/osx/group.rb +122 -0
  15. data/motion/address_book/osx/multi_valued.rb +166 -0
  16. data/motion/address_book/osx/person.rb +350 -0
  17. data/motion/address_book.rb +13 -5
  18. data/motion-addressbook.gemspec +2 -2
  19. data/spec/{address_book → ios/address_book}/group_spec.rb +0 -0
  20. data/spec/{address_book → ios/address_book}/multi_valued_spec.rb +0 -0
  21. data/spec/{address_book → ios/address_book}/person_spec.rb +33 -154
  22. data/spec/{address_book → ios/address_book}/picker_spec.rb +0 -0
  23. data/spec/{helpers → ios/helpers}/bacon_matchers.rb +0 -0
  24. data/spec/{helpers → ios/helpers}/hacks.rb +0 -0
  25. data/spec/{helpers → ios/helpers}/person_helpers.rb +0 -0
  26. data/spec/osx/address_book/person_spec.rb +174 -0
  27. data/spec/osx/helpers/bacon_matchers.rb +11 -0
  28. data/spec/osx/helpers/hacks.rb +6 -0
  29. data/spec/osx/helpers/person_helpers.rb +12 -0
  30. metadata +39 -29
  31. data/spec/address_book/multi_value_spec.rb +0 -125
@@ -1,27 +1,18 @@
1
1
  describe AddressBook::Person do
2
- before do
3
- @ab = AddressBook::AddrBook.new
4
- end
5
2
  describe 'ways of creating and finding people' do
6
3
  describe 'new' do
7
4
  before do
8
5
  @data = new_alex
9
- @alex = @ab.new_person(@data)
6
+ @alex = AddressBook::Person.new(@data)
10
7
  end
11
8
  it 'should create but not save in the address book' do
12
9
  @alex.should.be.new_record
13
- end
14
- it 'should have no mod date' do
15
- @alex.modification_date.should.be.nil
10
+ @alex.should.not.exists?
16
11
  end
17
12
  it 'should have initial values' do
18
13
  @alex.first_name.should == 'Alex'
19
14
  @alex.last_name.should == 'Testy'
20
15
  @alex.email_values.should == [@data[:emails][0][:value]]
21
- @alex.email.should == @data[:emails][0][:value]
22
- end
23
- it "should round-trip attributes without loss" do
24
- @alex.attributes.should.equal @data
25
16
  end
26
17
  it 'should have a composite name' do
27
18
  @alex.composite_name.should == 'Alex Testy'
@@ -31,23 +22,19 @@ describe AddressBook::Person do
31
22
  describe 'existing' do
32
23
  before do
33
24
  @email = unique_email
34
- @origdata = new_alex(@email)
35
- @alex = @ab.create_person(@origdata)
25
+ @alex = AddressBook::Person.create(new_alex(@email))
36
26
  end
37
27
  after do
38
28
  @alex.delete!
39
29
  end
40
- it 'should have a mod date' do
41
- @alex.modification_date.should.not.be.nil
42
- end
43
30
  describe '.find_by_uid' do
44
31
  it 'should find match' do
45
- alex = @ab.person(@alex.uid)
32
+ @alex.uid.should.not.be.nil
33
+ alex = AddressBook::Person.find_by_uid @alex.uid
46
34
  alex.uid.should == @alex.uid
47
35
  alex.email_values.should.include? @email
48
36
  alex.first_name.should == 'Alex'
49
37
  alex.last_name.should == 'Testy'
50
- alex.attributes.should.equal @alex.attributes
51
38
  end
52
39
  end
53
40
  describe '.find_all_by_email' do
@@ -55,6 +42,7 @@ describe AddressBook::Person do
55
42
  alexes = AddressBook::Person.find_all_by_email @email
56
43
  alexes.should.not.be.empty
57
44
  alexes.each do |alex|
45
+ alex.uid.should != nil
58
46
  alex.email_values.should.include? @email
59
47
  alex.first_name.should == 'Alex'
60
48
  alex.last_name.should == 'Testy'
@@ -68,6 +56,7 @@ describe AddressBook::Person do
68
56
  describe '.find_by_email' do
69
57
  it 'should find match' do
70
58
  alex = AddressBook::Person.find_by_email @email
59
+ alex.uid.should.not.be.nil
71
60
  alex.email_values.should.include? @email
72
61
  alex.first_name.should == 'Alex'
73
62
  alex.last_name.should == 'Testy'
@@ -82,6 +71,7 @@ describe AddressBook::Person do
82
71
  alexes = AddressBook::Person.where(:email => @email)
83
72
  alexes.should.not.be.empty
84
73
  alexes.each do |alex|
74
+ alex.uid.should != nil
85
75
  alex.email_values.should.include? @email
86
76
  alex.first_name.should == 'Alex'
87
77
  alex.last_name.should == 'Testy'
@@ -95,43 +85,25 @@ describe AddressBook::Person do
95
85
 
96
86
  describe '.all' do
97
87
  it 'should have the person we created' do
98
- all_names = @ab.people.map do |person|
88
+ all_names = AddressBook::Person.all.map do |person|
99
89
  [person.first_name, person.last_name]
100
90
  end
101
91
  all_names.should.include? [@alex.first_name, @alex.last_name]
102
92
  end
103
93
 
104
94
  it 'should get bigger when we create another' do
105
- initial_people_count = @ab.people.size
106
- @person = @ab.create_person({:first_name => 'Alex2', :last_name=>'Rothenberg2'})
107
- @ab.people.size.should == (initial_people_count + 1)
95
+ initial_people_count = AddressBook::Person.all.size
96
+ @person = AddressBook::Person.create({:first_name => 'Alex2', :last_name=>'Rothenberg2'})
97
+ AddressBook::Person.all.size.should == (initial_people_count + 1)
108
98
  @person.delete!
109
99
  end
110
100
  end
111
-
112
- describe ".replace" do
113
- before do
114
- warn "DOING REPLACE"
115
- @newdata = {
116
- :first_name => 'Alexander',
117
- :last_name => "Testy",
118
- :organization => "Acme, Inc.",
119
- :emails => [{:label => 'work', :value => @origdata[:emails].first[:value]}]
120
- }
121
- @alex.replace(@newdata)
122
- @alex.save
123
- end
124
-
125
- it "should have the new contents" do
126
- @alex.attributes.should == @newdata
127
- end
128
- end
129
101
  end
130
102
 
131
103
  describe '.find_or_new_by_XXX - new or existing' do
132
104
  before do
133
105
  @email = unique_email
134
- @alex = @ab.create_person(new_alex(@email))
106
+ @alex = AddressBook::Person.create(new_alex(@email))
135
107
  end
136
108
  after do
137
109
  @alex.delete!
@@ -140,6 +112,7 @@ describe AddressBook::Person do
140
112
  it 'should find an existing person' do
141
113
  alex = AddressBook::Person.find_or_new_by_email(@email)
142
114
  alex.should.not.be.new_record
115
+ alex.uid.should != nil
143
116
  alex.first_name.should == 'Alex'
144
117
  alex.last_name.should == 'Testy'
145
118
  alex.emails.attributes.map{|r| r[:value]}.should == [@email]
@@ -148,6 +121,7 @@ describe AddressBook::Person do
148
121
  never_before_used_email = unique_email
149
122
  new_person = AddressBook::Person.find_or_new_by_email(never_before_used_email)
150
123
  new_person.should.be.new_record
124
+ new_person.should.not.exists
151
125
  new_person.email_values.should == [never_before_used_email]
152
126
  new_person.first_name.should == nil
153
127
  end
@@ -157,6 +131,7 @@ describe AddressBook::Person do
157
131
  describe 'save' do
158
132
  before do
159
133
  @attributes = {
134
+ :prefix => 'Mr.',
160
135
  :first_name=>'Alex',
161
136
  :middle_name=>'Q.',
162
137
  :last_name=>'Testy',
@@ -166,7 +141,6 @@ describe AddressBook::Person do
166
141
  :department => 'Development',
167
142
  :organization => 'The Company',
168
143
  :note => 'some important guy',
169
- :birthday => NSDate.dateWithNaturalLanguageString('July 1, 1982'),
170
144
  # :mobile_phone => '123 456 7890', :office_phone => '987 654 3210',
171
145
  :phones => [
172
146
  {:label => 'mobile', :value => '123 456 7899'},
@@ -183,29 +157,25 @@ describe AddressBook::Person do
183
157
  { :label => 'home page', :value => "http://www.mysite.com/" },
184
158
  { :label => 'work', :value => 'http://dept.bigco.com/' },
185
159
  { :label => 'school', :value => 'http://state.edu/college' }
186
- ],
187
- :dates => [
188
- { :label => 'anniversary', :date => NSDate.dateWithNaturalLanguageString('October 9, 2009') },
189
- { :label => 'apotheosis', :date => NSDate.dateWithNaturalLanguageString('April 1, 2013') }
190
160
  ]
191
161
  }
192
162
  end
193
163
 
194
164
  describe 'a new person' do
195
165
  before do
196
- @ab_person = @ab.new_person(@attributes)
166
+ @ab_person = AddressBook::Person.new(@attributes)
197
167
  end
198
168
 
199
169
  it 'should not be existing' do
200
170
  @ab_person.should.be.new_record
201
171
  @ab_person.should.not.be.exists
202
- @ab_person.modification_date.should.be.nil
203
172
  end
204
173
 
205
174
  it 'should be able to get each of the single value fields' do
206
175
  @ab_person.first_name.should.equal @attributes[:first_name ]
207
176
  @ab_person.last_name.should.equal @attributes[:last_name ]
208
177
  @ab_person.middle_name.should.equal @attributes[:middle_name ]
178
+ @ab_person.prefix.should.equal @attributes[:prefix ]
209
179
  @ab_person.suffix.should.equal @attributes[:suffix ]
210
180
  @ab_person.nickname.should.equal @attributes[:nickname ]
211
181
  @ab_person.job_title.should.equal @attributes[:job_title ]
@@ -244,26 +214,11 @@ describe AddressBook::Person do
244
214
  @ab_person.organization.should.equal 'new organization'
245
215
  end
246
216
 
247
- def empty_image(width, height)
248
- UIGraphicsBeginImageContext(CGSizeMake(width, height) )
249
- CGContextSetFillColorWithColor(UIGraphicsGetCurrentContext(), '#ffffff'.to_color)
250
- image = UIGraphicsGetImageFromCurrentImageContext()
251
- UIGraphicsEndImageContext()
252
- image
253
- end
254
-
255
217
  it 'should be able to set the photo' do
256
- data = UIImagePNGRepresentation empty_image(1,1)
218
+ image = CIImage.emptyImage
219
+ data = UIImagePNGRepresentation(UIImage.imageWithCIImage image)
257
220
  @ab_person.photo = data
258
- @ab_person.photo.should.not == nil
259
- @ab_person.photo.should.equal data
260
- end
261
-
262
- it 'should be able to get the photo as an image' do
263
- data = UIImagePNGRepresentation empty_image(1,1)
264
- @ab_person.photo = data
265
- @ab_person.photo_image.size
266
- @ab_person.photo_image.size.should.equal CGSizeMake(1,1)
221
+ UIImagePNGRepresentation(@ab_person.photo).should.equal data
267
222
  end
268
223
  end
269
224
 
@@ -289,7 +244,6 @@ describe AddressBook::Person do
289
244
 
290
245
  describe 'once saved' do
291
246
  before do
292
- @before = Time.now
293
247
  @before_count = AddressBook.count
294
248
  @ab_person.save
295
249
  end
@@ -302,27 +256,18 @@ describe AddressBook::Person do
302
256
  @ab_person.should.be.exists
303
257
  end
304
258
 
305
- # it 'should populate timestamps' do
306
- # @ab_person.modification_date.should.not.be.nil
307
- # should.satisfy {@ab_person.modification_date > @before}
308
- # end
309
-
310
259
  it "should increment the count" do
311
260
  AddressBook.count.should.equal @before_count+1
312
261
  end
313
262
 
314
- it 'should round-trip all attributes without loss' do
315
- @ab_person.attributes.should.equal @attributes
316
- end
317
-
318
263
  it 'should have scalar properties' do
319
- [:first_name, :middle_name, :last_name, :job_title, :department, :organization, :note, :birthday].each do |attr|
320
- @ab_person.send(attr).should.equal @attributes[attr]
264
+ [:first_name, :middle_name, :last_name, :job_title, :department, :organization, :note].each do |attr|
265
+ @ab_person.attributes[attr].should.equal @attributes[attr]
321
266
  end
322
267
  end
323
268
 
324
269
  it 'should have a composite name' do
325
- @ab_person.composite_name.should == 'Alex Q. Testy III'
270
+ @ab_person.composite_name.should == 'Mr. Alex Q. Testy III'
326
271
  end
327
272
 
328
273
  it 'should be able to count the emails' do
@@ -338,21 +283,22 @@ describe AddressBook::Person do
338
283
  end
339
284
  end
340
285
 
341
- describe 'once deleted' do
286
+ describe 'can be deleted' do
342
287
  before do
343
288
  @ab_person.save
344
289
  @ab_person.delete!
345
290
  end
346
- it 'should no longer exist' do
291
+ it 'after deletion it should no longer exist' do
347
292
  @ab_person.should.not.be.exists
348
- # @ab_person.should.be.new_record
293
+ @ab_person.should.be.new_record
349
294
  end
350
295
  end
351
296
  end
352
297
 
353
298
  describe 'an existing person' do
354
299
  before do
355
- @orig_ab_person = @ab.create_person(@attributes)
300
+ @orig_ab_person = AddressBook::Person.new(@attributes)
301
+ @orig_ab_person.save
356
302
  @ab_person = AddressBook::Person.find_or_new_by_email(@attributes[:emails][0][:value])
357
303
  end
358
304
  after do
@@ -393,7 +339,7 @@ describe AddressBook::Person do
393
339
  { :label => 'work' },
394
340
  { :label => 'work', :url => 'http://state.edu/college' }
395
341
  ]
396
- @ab_person = @ab.create_person(@attributes)
342
+ @ab_person = AddressBook::Person.create(@attributes)
397
343
  end
398
344
  after do
399
345
  @ab_person.delete!
@@ -418,13 +364,12 @@ describe AddressBook::Person do
418
364
 
419
365
  describe "organization record" do
420
366
  before do
421
- @person = @ab.new_person(
367
+ @person = AddressBook::Person.new(
422
368
  :first_name => 'John',
423
369
  :last_name => 'Whorfin',
424
370
  :organization => 'Acme Inc.',
425
371
  :is_org => true,
426
- :note => 'big important company',
427
- :birthday => NSDate.dateWithNaturalLanguageString('August 17, 1947')
372
+ :note => 'big important company'
428
373
  )
429
374
  end
430
375
 
@@ -435,7 +380,7 @@ describe AddressBook::Person do
435
380
 
436
381
  describe 'method missing magic' do
437
382
  before do
438
- @person = @ab.new_person({})
383
+ @person = AddressBook::Person.new
439
384
  end
440
385
  describe 'getters' do
441
386
  it 'should have a getter for each attribute' do
@@ -444,7 +389,6 @@ describe AddressBook::Person do
444
389
  @person.getter?('job_title' ).should.be truthy
445
390
  @person.getter?('department' ).should.be truthy
446
391
  @person.getter?('organization').should.be truthy
447
- @person.getter?('birthday').should.be truthy
448
392
  end
449
393
  it 'should know what is not a getter' do
450
394
  @person.getter?('nonesense' ).should.be falsey
@@ -502,69 +446,4 @@ describe AddressBook::Person do
502
446
  end
503
447
  end
504
448
  end
505
-
506
- describe "multiple emails/phone #'s handling" do
507
- it "should accept multiple emails/phone #'s as array of strings for new records" do
508
- person = @ab.new_person(
509
- :first_name => 'Ashish',
510
- :last_name => 'Upadhyay',
511
- :email => ['a@mail.com','a@mail.com','a@mail.com'],
512
- :phones => ['1212999222','1212999333','1212999444'],
513
- )
514
- person.should.be.new_record
515
- end
516
- it "should accept multiple emails/phone #'s as array of hashes for new records" do
517
- person = @ab.new_person(
518
- :first_name => 'Ashish',
519
- :last_name => 'Upadhyay',
520
- :email => [{ :value => 'a@mail.com' } , { :value => 'a@mail.com' } , { :value => 'a@mail.com' } ] ,
521
- :phones => [{ :value => '1212999222' } , { :value => '1212999333' } , { :value => '1212999444' } ] ,
522
- )
523
- person.should.be.new_record
524
- end
525
- it "should accept multiple emails/phone #'s as array of combination of strings or hashes for new records" do
526
- person = @ab.new_person(
527
- :first_name => 'Ashish',
528
- :last_name => 'Upadhyay',
529
- :email => [ { :value => 'a@mail.com' } , 'a@mail.com' , { :value => 'a@mail.com', :label => 'Office'}] ,
530
- :phones => [ '1212999222' , { :value => '1212999333', :label => 'Personal' } , { :value => '1212999444' } ] ,
531
- )
532
- person.should.be.new_record
533
- end
534
- end
535
-
536
- describe 'vcard' do
537
- before do
538
- @alex = @ab.create_person(new_alex(unique_email))
539
- @jason = @ab.create_person(new_alex('jason@example.com'))
540
- end
541
- after do
542
- @jason.delete!
543
- @alex.delete!
544
- end
545
-
546
- describe '.vcard_for' do
547
- it 'creates a vcard for a single person' do
548
- alex_vcard = AddressBook::Person.vcard_for(@alex).to_s
549
- alex_vcard.should.include? 'BEGIN:VCARD'
550
- alex_vcard.should.include? "EMAIL;type=INTERNET;type=HOME;type=pref:#{@alex.email}"
551
- alex_vcard.should.include? 'END:VCARD'
552
- end
553
- it 'creates a vcard for an array of people' do
554
- alex_and_jason_vcard = AddressBook::Person.vcard_for([@alex, @jason]).to_s
555
- alex_and_jason_vcard.should.include? 'BEGIN:VCARD'
556
- alex_and_jason_vcard.should.include? "EMAIL;type=INTERNET;type=HOME;type=pref:#{@alex.email}"
557
- alex_and_jason_vcard.should.include? "EMAIL;type=INTERNET;type=HOME;type=pref:#{@jason.email}"
558
- alex_and_jason_vcard.should.include? 'END:VCARD'
559
- end
560
- end
561
- describe '#to_vcard' do
562
- it 'knows how to create vcard for itself' do
563
- alex_vcard = @alex.to_vcard.to_s
564
- alex_vcard.should.include? 'BEGIN:VCARD'
565
- alex_vcard.should.include? "EMAIL;type=INTERNET;type=HOME;type=pref:#{@alex.email}"
566
- alex_vcard.should.include? 'END:VCARD'
567
- end
568
- end
569
- end
570
449
  end
File without changes
File without changes
File without changes
@@ -0,0 +1,174 @@
1
+ describe AddressBook::Person do
2
+ before do
3
+ @alex_data = {
4
+ :prefix => 'Mr.',
5
+ :first_name=>'Alex',
6
+ :middle_name=>'Q.',
7
+ :last_name=>'Testy',
8
+ :suffix => 'III',
9
+ :nickname => 'Geekster',
10
+ :job_title => 'Developer',
11
+ :department => 'Development',
12
+ :organization => 'The Company',
13
+ :note => 'some important guy',
14
+ :phones => [
15
+ {:label => 'mobile', :value => '123 456 7899'},
16
+ {:label => 'office', :value => '987 654 3210'}
17
+ ],
18
+ :emails => [
19
+ {:label => 'work', :value => unique_email}
20
+ ],
21
+ :addresses => [
22
+ {:label => 'home', :city => 'Dogpatch', :state => 'KY'}
23
+ ],
24
+ :urls => [
25
+ { :label => 'home page', :value => "http://www.mysite.com/" },
26
+ { :label => 'work', :value => 'http://dept.bigco.com/' },
27
+ { :label => 'school', :value => 'http://state.edu/college' }
28
+ ]
29
+ }
30
+ end
31
+
32
+ describe 'a new person' do
33
+ before do
34
+ @ab = AddressBook::AddrBook.new
35
+ @the_person = @ab.new_person(@alex_data)
36
+ end
37
+
38
+ it 'should not exist' do
39
+ @the_person.should.be.new
40
+ @the_person.should.not.be.exists
41
+ end
42
+
43
+ it 'should be able to get each of the single value fields' do
44
+ @the_person.first_name.should.equal @alex_data[:first_name ]
45
+ @the_person.last_name.should.equal @alex_data[:last_name ]
46
+ @the_person.middle_name.should.equal @alex_data[:middle_name ]
47
+ @the_person.suffix.should.equal @alex_data[:prefix ]
48
+ @the_person.suffix.should.equal @alex_data[:suffix ]
49
+ @the_person.nickname.should.equal @alex_data[:nickname ]
50
+ @the_person.job_title.should.equal @alex_data[:job_title ]
51
+ @the_person.department.should.equal @alex_data[:department ]
52
+ @the_person.organization.should.equal @alex_data[:organization]
53
+ @the_person.note.should.equal @alex_data[:note]
54
+ @the_person.should.be.person?
55
+ end
56
+
57
+ it 'should get a value back for singular requests against multi-value attributes' do
58
+ @the_person.email.should.equal @alex_data[:emails].first[:value]
59
+ @the_person.phone.should.equal @alex_data[:phones].first[:value]
60
+ @the_person.url.should.equal @alex_data[:urls].first[:value]
61
+ @the_person.address.should.equal @alex_data[:addresses].first
62
+ end
63
+
64
+ # describe 'setting each field' do
65
+ # it 'should be able to set the first name' do
66
+ # @the_person.first_name = 'new first name'
67
+ # @the_person.first_name.should.equal 'new first name'
68
+ # end
69
+ # it 'should be able to set the last name' do
70
+ # @the_person.last_name = 'new last name'
71
+ # @the_person.last_name.should.equal 'new last name'
72
+ # end
73
+ # it 'should be able to set the job title' do
74
+ # @the_person.job_title = 'new job title'
75
+ # @the_person.job_title.should.equal 'new job title'
76
+ # end
77
+ # it 'should be able to set the department' do
78
+ # @the_person.department = 'new department'
79
+ # @the_person.department.should.equal 'new department'
80
+ # end
81
+ # it 'should be able to set the organization' do
82
+ # @the_person.organization = 'new organization'
83
+ # @the_person.organization.should.equal 'new organization'
84
+ # end
85
+
86
+ # it 'should be able to set the photo' do
87
+ # image = CIImage.emptyImage
88
+ # data = UIImagePNGRepresentation(UIImage.imageWithCIImage image)
89
+ # @the_person.photo = data
90
+ # UIImagePNGRepresentation(@the_person.photo).should.equal data
91
+ # end
92
+ # end
93
+
94
+ it 'should be able to count & get the phone numbers' do
95
+ @the_person.phones.size.should.equal 2
96
+ @the_person.phones.attributes.should.equal @alex_data[:phones]
97
+ end
98
+
99
+ it 'should be able to count & get the emails' do
100
+ @the_person.emails.size.should.equal 1
101
+ @the_person.emails.attributes.should.equal @alex_data[:emails]
102
+ end
103
+
104
+ it 'should be able to count & inspect the addresses' do
105
+ @the_person.addresses.count.should.equal 1
106
+ @the_person.addresses.attributes.should.equal @alex_data[:addresses]
107
+ end
108
+
109
+ it 'should be able to count & inspect the URLs' do
110
+ @the_person.urls.count.should.equal 3
111
+ @the_person.urls.attributes.should.equal @alex_data[:urls]
112
+ end
113
+
114
+ describe 'once saved' do
115
+ before do
116
+ @before_count = @ab.count
117
+ @the_person.save
118
+ end
119
+ after do
120
+ @the_person.delete!
121
+ end
122
+
123
+ it 'should no longer be new' do
124
+ @the_person.should.not.be.new
125
+ @the_person.should.be.exists
126
+ end
127
+
128
+ it "should increment the count" do
129
+ @ab.count.should.equal @before_count+1
130
+ end
131
+
132
+ it 'should have scalar properties' do
133
+ [:first_name, :middle_name, :last_name, :job_title, :department, :organization, :note].each do |attr|
134
+ @the_person.attributes[attr].should.equal @alex_data[attr]
135
+ end
136
+ end
137
+
138
+ it 'should be able to count the emails' do
139
+ @the_person.emails.size.should.equal 1
140
+ end
141
+
142
+ it 'should be able to count the addresses' do
143
+ @the_person.addresses.count.should.equal 1
144
+ end
145
+
146
+ it 'should be able to retrieve the addresses' do
147
+ @the_person.addresses.attributes.should.equal @alex_data[:addresses]
148
+ end
149
+
150
+ describe '...and updated' do
151
+ before do
152
+ @id_before = @the_person.uid
153
+ @the_person.first_name = 'New First Name'
154
+ @the_person.save
155
+ end
156
+
157
+ it 'should not change ID' do
158
+ @the_person.uid.should.equal @id_before
159
+ end
160
+ end
161
+ end
162
+
163
+ describe 'after save & delete' do
164
+ before do
165
+ @the_person.save
166
+ @the_person.delete!
167
+ end
168
+ it 'should no longer exist' do
169
+ @the_person.should.not.be.exists
170
+ @the_person.should.be.new
171
+ end
172
+ end
173
+ end
174
+ end
@@ -0,0 +1,11 @@
1
+ # 1.should.be truthy
2
+ # false.should.not.be truthy
3
+ def truthy()
4
+ lambda { |obj| !!obj }
5
+ end
6
+
7
+ # 1.should.not.be falsey
8
+ # false.should..be falsey
9
+ def falsey()
10
+ lambda { |obj| !obj }
11
+ end
@@ -0,0 +1,6 @@
1
+ # The value of these constants is undefined until one of the following functions has been called:
2
+ # ABAddressBookCreate, ABPersonCreate, ABGroupCreate.
3
+ # see https://developer.apple.com/library/ios/#documentation/AddressBook/Reference/ABPersonRef_iPhoneOS/Reference/reference.html
4
+ # and search for "Discussion"
5
+ # WTF: Why would an API define a constant this way?!?!
6
+ AddressBook.address_book
@@ -0,0 +1,12 @@
1
+ def unique_email(email='alex_testy@example.com')
2
+ name, domain = email.split('@')
3
+ "#{name}_#{Time.now.to_i}_#{rand(1000)}@#{domain}"
4
+ end
5
+
6
+ def new_alex(emailaddr = unique_email)
7
+ {
8
+ :first_name => 'Alex',
9
+ :last_name => 'Testy',
10
+ :emails => [{:label => 'home', :value => emailaddr}]
11
+ }
12
+ end