has_vcards 0.20.3 → 1.0.0.rc0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (105) hide show
  1. data/MIT-LICENSE +4 -1
  2. data/README.md +18 -0
  3. data/Rakefile +28 -0
  4. data/app/assets/javascripts/has_vcards/application.js +13 -0
  5. data/app/assets/stylesheets/has_vcards/application.css +15 -0
  6. data/app/controllers/has_vcards/directory_lookup_controller.rb +21 -0
  7. data/app/controllers/has_vcards/phone_numbers_controller.rb +16 -0
  8. data/app/controllers/has_vcards/vcards_controller.rb +22 -0
  9. data/app/helpers/has_vcards/application_helper.rb +18 -0
  10. data/app/input/has_vcards/zip_locality_input.rb +16 -0
  11. data/app/models/has_vcards/address.rb +42 -0
  12. data/app/models/has_vcards/concerns/has_vcards.rb +42 -0
  13. data/app/models/has_vcards/phone_number.rb +61 -0
  14. data/app/models/has_vcards/vcard.rb +123 -0
  15. data/app/models/has_vcards/vcard/directory_address.rb +25 -0
  16. data/app/models/has_vcards/vcard/directory_lookup.rb +123 -0
  17. data/app/views/has_vcards/layouts/has_vcards/application.html.erb +14 -0
  18. data/app/views/{people → has_vcards/people}/_address_form.html.haml +1 -1
  19. data/app/views/{phone_numbers → has_vcards/phone_numbers}/_form.html.haml +0 -0
  20. data/app/views/{phone_numbers → has_vcards/phone_numbers}/_list.html.haml +0 -0
  21. data/app/views/{phone_numbers → has_vcards/phone_numbers}/_nested_form.html.haml +0 -0
  22. data/app/views/{phone_numbers → has_vcards/phone_numbers}/_phone_number.html.haml +0 -0
  23. data/app/views/{vcards → has_vcards/vcards}/_address.html.haml +0 -0
  24. data/app/views/{vcards → has_vcards/vcards}/_directory_lookup.html.haml +0 -0
  25. data/app/views/{vcards → has_vcards/vcards}/_directory_matches.html.haml +0 -0
  26. data/app/views/{vcards → has_vcards/vcards}/_form.html.haml +1 -1
  27. data/app/views/{vcards → has_vcards/vcards}/_show.html.haml +1 -1
  28. data/app/views/{vcards → has_vcards/vcards}/directory_lookup.js.erb +0 -0
  29. data/config/locales/de.yml +11 -18
  30. data/config/locales/en.yml +21 -6
  31. data/config/locales/fr.yml +6 -18
  32. data/config/routes.rb +1 -1
  33. data/db/migrate/20121113120000_create_honorific_prefixes_table.rb +1 -1
  34. data/db/migrate/20140617113710_rename_tables_for_namespacing.rb +8 -0
  35. data/db/migrate/20140619101337_remove_object_from_phone_number.rb +6 -0
  36. data/db/migrate/20140619102041_rename_vcard_object_to_reference.rb +6 -0
  37. data/db/migrate/20140619121756_refactor_honorific_prefix.rb +5 -0
  38. data/lib/has_vcards.rb +5 -18
  39. data/lib/has_vcards/engine.rb +29 -0
  40. data/lib/has_vcards/version.rb +4 -1
  41. data/spec/controllers/has_vcards/phone_numbers_controller_spec.rb +42 -0
  42. data/spec/controllers/has_vcards/vcards_controller_spec.rb +42 -0
  43. data/spec/dummy/README.rdoc +28 -0
  44. data/spec/dummy/Rakefile +6 -0
  45. data/spec/dummy/app/assets/javascripts/application.js +13 -0
  46. data/spec/dummy/app/assets/stylesheets/application.css +15 -0
  47. data/spec/dummy/app/controllers/application_controller.rb +5 -0
  48. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  49. data/spec/dummy/app/views/layouts/application.html.erb +14 -0
  50. data/spec/dummy/bin/bundle +3 -0
  51. data/spec/dummy/bin/rails +4 -0
  52. data/spec/dummy/bin/rake +4 -0
  53. data/spec/dummy/config.ru +4 -0
  54. data/spec/dummy/config/application.rb +29 -0
  55. data/spec/dummy/config/boot.rb +5 -0
  56. data/spec/dummy/config/database.yml +37 -0
  57. data/spec/dummy/config/environment.rb +5 -0
  58. data/spec/dummy/config/environments/development.rb +37 -0
  59. data/spec/dummy/config/environments/production.rb +83 -0
  60. data/spec/dummy/config/environments/test.rb +39 -0
  61. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  62. data/spec/dummy/config/initializers/cookies_serializer.rb +3 -0
  63. data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  64. data/spec/dummy/config/initializers/inflections.rb +16 -0
  65. data/spec/dummy/config/initializers/mime_types.rb +4 -0
  66. data/spec/dummy/config/initializers/session_store.rb +3 -0
  67. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  68. data/spec/dummy/config/locales/en.yml +23 -0
  69. data/spec/dummy/config/routes.rb +4 -0
  70. data/spec/dummy/config/secrets.yml +22 -0
  71. data/spec/dummy/db/development.sqlite3 +0 -0
  72. data/spec/dummy/db/migrate/20140620151641_create_somethings.rb +7 -0
  73. data/spec/dummy/db/schema.rb +66 -0
  74. data/spec/dummy/db/test.sqlite3 +0 -0
  75. data/spec/dummy/log/development.log +2513 -0
  76. data/spec/dummy/log/test.log +11671 -0
  77. data/spec/dummy/public/404.html +67 -0
  78. data/spec/dummy/public/422.html +67 -0
  79. data/spec/dummy/public/500.html +66 -0
  80. data/spec/dummy/public/favicon.ico +0 -0
  81. data/spec/factories/addresses.rb +7 -0
  82. data/spec/factories/phone_numbers.rb +7 -0
  83. data/spec/factories/vcards.rb +5 -0
  84. data/spec/models/has_vcards/address_spec.rb +58 -0
  85. data/spec/models/has_vcards/concerns/has_vcards_spec.rb +50 -0
  86. data/spec/models/has_vcards/phone_number_spec.rb +82 -0
  87. data/spec/models/has_vcards/vcard_spec.rb +172 -0
  88. data/spec/rails_helper.rb +18 -0
  89. data/spec/spec_helper.rb +74 -0
  90. metadata +262 -47
  91. data/README.markdown +0 -14
  92. data/app/controllers/directory_lookup_controller.rb +0 -17
  93. data/app/controllers/phone_numbers_controller.rb +0 -14
  94. data/app/controllers/vcards_controller.rb +0 -20
  95. data/app/helpers/has_vcards_helper.rb +0 -13
  96. data/app/input/zip_locality_input.rb +0 -14
  97. data/app/models/address.rb +0 -40
  98. data/app/models/honorific_prefix.rb +0 -6
  99. data/app/models/phone_number.rb +0 -43
  100. data/app/models/vcard.rb +0 -112
  101. data/app/models/vcard/directory_address.rb +0 -21
  102. data/app/models/vcard/directory_lookup.rb +0 -122
  103. data/config/application.rb +0 -19
  104. data/config/boot.rb +0 -6
  105. data/lib/has_vcards/railtie.rb +0 -19
@@ -0,0 +1,67 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>The page you were looking for doesn't exist (404)</title>
5
+ <meta name="viewport" content="width=device-width,initial-scale=1">
6
+ <style>
7
+ body {
8
+ background-color: #EFEFEF;
9
+ color: #2E2F30;
10
+ text-align: center;
11
+ font-family: arial, sans-serif;
12
+ margin: 0;
13
+ }
14
+
15
+ div.dialog {
16
+ width: 95%;
17
+ max-width: 33em;
18
+ margin: 4em auto 0;
19
+ }
20
+
21
+ div.dialog > div {
22
+ border: 1px solid #CCC;
23
+ border-right-color: #999;
24
+ border-left-color: #999;
25
+ border-bottom-color: #BBB;
26
+ border-top: #B00100 solid 4px;
27
+ border-top-left-radius: 9px;
28
+ border-top-right-radius: 9px;
29
+ background-color: white;
30
+ padding: 7px 12% 0;
31
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
32
+ }
33
+
34
+ h1 {
35
+ font-size: 100%;
36
+ color: #730E15;
37
+ line-height: 1.5em;
38
+ }
39
+
40
+ div.dialog > p {
41
+ margin: 0 0 1em;
42
+ padding: 1em;
43
+ background-color: #F7F7F7;
44
+ border: 1px solid #CCC;
45
+ border-right-color: #999;
46
+ border-left-color: #999;
47
+ border-bottom-color: #999;
48
+ border-bottom-left-radius: 4px;
49
+ border-bottom-right-radius: 4px;
50
+ border-top-color: #DADADA;
51
+ color: #666;
52
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
53
+ }
54
+ </style>
55
+ </head>
56
+
57
+ <body>
58
+ <!-- This file lives in public/404.html -->
59
+ <div class="dialog">
60
+ <div>
61
+ <h1>The page you were looking for doesn't exist.</h1>
62
+ <p>You may have mistyped the address or the page may have moved.</p>
63
+ </div>
64
+ <p>If you are the application owner check the logs for more information.</p>
65
+ </div>
66
+ </body>
67
+ </html>
@@ -0,0 +1,67 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>The change you wanted was rejected (422)</title>
5
+ <meta name="viewport" content="width=device-width,initial-scale=1">
6
+ <style>
7
+ body {
8
+ background-color: #EFEFEF;
9
+ color: #2E2F30;
10
+ text-align: center;
11
+ font-family: arial, sans-serif;
12
+ margin: 0;
13
+ }
14
+
15
+ div.dialog {
16
+ width: 95%;
17
+ max-width: 33em;
18
+ margin: 4em auto 0;
19
+ }
20
+
21
+ div.dialog > div {
22
+ border: 1px solid #CCC;
23
+ border-right-color: #999;
24
+ border-left-color: #999;
25
+ border-bottom-color: #BBB;
26
+ border-top: #B00100 solid 4px;
27
+ border-top-left-radius: 9px;
28
+ border-top-right-radius: 9px;
29
+ background-color: white;
30
+ padding: 7px 12% 0;
31
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
32
+ }
33
+
34
+ h1 {
35
+ font-size: 100%;
36
+ color: #730E15;
37
+ line-height: 1.5em;
38
+ }
39
+
40
+ div.dialog > p {
41
+ margin: 0 0 1em;
42
+ padding: 1em;
43
+ background-color: #F7F7F7;
44
+ border: 1px solid #CCC;
45
+ border-right-color: #999;
46
+ border-left-color: #999;
47
+ border-bottom-color: #999;
48
+ border-bottom-left-radius: 4px;
49
+ border-bottom-right-radius: 4px;
50
+ border-top-color: #DADADA;
51
+ color: #666;
52
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
53
+ }
54
+ </style>
55
+ </head>
56
+
57
+ <body>
58
+ <!-- This file lives in public/422.html -->
59
+ <div class="dialog">
60
+ <div>
61
+ <h1>The change you wanted was rejected.</h1>
62
+ <p>Maybe you tried to change something you didn't have access to.</p>
63
+ </div>
64
+ <p>If you are the application owner check the logs for more information.</p>
65
+ </div>
66
+ </body>
67
+ </html>
@@ -0,0 +1,66 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>We're sorry, but something went wrong (500)</title>
5
+ <meta name="viewport" content="width=device-width,initial-scale=1">
6
+ <style>
7
+ body {
8
+ background-color: #EFEFEF;
9
+ color: #2E2F30;
10
+ text-align: center;
11
+ font-family: arial, sans-serif;
12
+ margin: 0;
13
+ }
14
+
15
+ div.dialog {
16
+ width: 95%;
17
+ max-width: 33em;
18
+ margin: 4em auto 0;
19
+ }
20
+
21
+ div.dialog > div {
22
+ border: 1px solid #CCC;
23
+ border-right-color: #999;
24
+ border-left-color: #999;
25
+ border-bottom-color: #BBB;
26
+ border-top: #B00100 solid 4px;
27
+ border-top-left-radius: 9px;
28
+ border-top-right-radius: 9px;
29
+ background-color: white;
30
+ padding: 7px 12% 0;
31
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
32
+ }
33
+
34
+ h1 {
35
+ font-size: 100%;
36
+ color: #730E15;
37
+ line-height: 1.5em;
38
+ }
39
+
40
+ div.dialog > p {
41
+ margin: 0 0 1em;
42
+ padding: 1em;
43
+ background-color: #F7F7F7;
44
+ border: 1px solid #CCC;
45
+ border-right-color: #999;
46
+ border-left-color: #999;
47
+ border-bottom-color: #999;
48
+ border-bottom-left-radius: 4px;
49
+ border-bottom-right-radius: 4px;
50
+ border-top-color: #DADADA;
51
+ color: #666;
52
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
53
+ }
54
+ </style>
55
+ </head>
56
+
57
+ <body>
58
+ <!-- This file lives in public/500.html -->
59
+ <div class="dialog">
60
+ <div>
61
+ <h1>We're sorry, but something went wrong.</h1>
62
+ </div>
63
+ <p>If you are the application owner check the logs for more information.</p>
64
+ </div>
65
+ </body>
66
+ </html>
File without changes
@@ -0,0 +1,7 @@
1
+ FactoryGirl.define do
2
+ factory :address, class: HasVcards::Address do
3
+ sequence(:postal_code) { |n| "8200#{ n }" }
4
+ locality 'Test Town'
5
+ street_address '312 Test Street'
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ FactoryGirl.define do
2
+ factory :phone_number, class: HasVcards::PhoneNumber do
3
+ sequence(:number) { |n| "+41 000-111-#{ n }" }
4
+ vcard
5
+ phone_number_type 'phone'
6
+ end
7
+ end
@@ -0,0 +1,5 @@
1
+ FactoryGirl.define do
2
+ factory :vcard, class: HasVcards::Vcard do
3
+ full_name 'Ben Hur'
4
+ end
5
+ end
@@ -0,0 +1,58 @@
1
+ require 'rails_helper'
2
+
3
+ RSpec.describe HasVcards::Address do
4
+ before { @address = FactoryGirl.create :address }
5
+
6
+ it 'has a valid factory' do
7
+ expect(@address).to be_valid
8
+ end
9
+
10
+ describe 'address validation' do
11
+
12
+ it 'accepts a valid address' do
13
+ @address.validate_address
14
+
15
+ expect(@address.errors).to be_empty
16
+ end
17
+
18
+ it 'accepts with an extended address instead of a street address' do
19
+ @address.street_address = nil
20
+ @address.extended_address = 'Alternative Address'
21
+ @address.validate_address
22
+
23
+ expect(@address.errors).to be_empty
24
+ end
25
+
26
+ it 'accepts with a postal office box instead of a street address' do
27
+ @address.street_address = nil
28
+ @address.post_office_box = '982312'
29
+ @address.validate_address
30
+
31
+ expect(@address.errors).to be_empty
32
+ end
33
+
34
+ it 'rejects without a postal code' do
35
+ @address.postal_code = nil
36
+ @address.validate_address
37
+
38
+ expect(@address.errors.size).to eq 1
39
+ expect(@address.errors.first.first).to eq :postal_code
40
+ end
41
+
42
+ it 'rejects without a locality' do
43
+ @address.locality = nil
44
+ @address.validate_address
45
+
46
+ expect(@address.errors.size).to eq 1
47
+ expect(@address.errors.first.first).to eq :locality
48
+ end
49
+
50
+ it 'rejects without at least an address, an extended address or a post office box' do
51
+ @address.street_address = nil
52
+ @address.validate_address
53
+
54
+ expect(@address.errors.size).to eq 3
55
+ expect(@address.errors.first.first).to eq :street_address
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,50 @@
1
+ require 'rails_helper'
2
+
3
+ # Dummy class to test class methods
4
+ class Something < ActiveRecord::Base
5
+ include HasVcards::Concerns::HasVcards
6
+ end
7
+
8
+ describe HasVcards::Concerns::HasVcards do
9
+ context 'a new instance of Something' do
10
+ let(:something) { Something.new }
11
+
12
+ it 'has a vcards association' do
13
+ expect(something.vcards.build).to be_a HasVcards::Vcard
14
+ end
15
+
16
+ it 'has a vcard association' do
17
+ expect(something.build_vcard).to be_a HasVcards::Vcard
18
+ end
19
+
20
+ it 'has a vcard autobuilt' do
21
+ expect(something.vcard).to be_a HasVcards::Vcard
22
+ end
23
+
24
+ it 'delegates attribute accessors to the main vcard' do
25
+ attributes = [ :full_name, :nickname, :family_name, :given_name, :additional_name, :honorific_prefix, :honorific_suffix ]
26
+
27
+ attributes.each do |attr|
28
+ expect(something.vcard).to receive(attr)
29
+ something.vcard.send(attr)
30
+
31
+ expect(something.vcard).to receive("#{attr}=")
32
+ something.vcard.send("#{attr}=", 'foo')
33
+ end
34
+ end
35
+ end
36
+
37
+ it 'accepts nested attributes for vcard' do
38
+ vcard_attributes = { full_name: 'Full' }
39
+
40
+ something = Something.create(vcard_attributes: vcard_attributes)
41
+ expect(something.vcard.full_name).to eq 'Full'
42
+ end
43
+
44
+ it 'accepts nested attributes for vcards' do
45
+ vcards_attributes = { '' => { full_name: 'Full' } }
46
+
47
+ something = Something.create(vcards_attributes: vcards_attributes)
48
+ expect(something.vcards[0].full_name).to eq 'Full'
49
+ end
50
+ end
@@ -0,0 +1,82 @@
1
+ require 'rails_helper'
2
+
3
+ RSpec.describe HasVcards::PhoneNumber do
4
+ before { @phone_number = FactoryGirl.create :phone_number }
5
+
6
+ it 'has a valid factory' do
7
+ expect(@phone_number).to be_valid
8
+ expect(@phone_number.vcard).to be_valid
9
+ end
10
+
11
+ describe '#label' do
12
+ let(:phone) { FactoryGirl.build :phone_number }
13
+
14
+ it 'uses locales when known' do
15
+ phone.phone_number_type = 'email'
16
+ expect(phone.label).to eq 'Mail'
17
+ end
18
+
19
+ it 'titelizes the type when no locale available' do
20
+ phone.phone_number_type = 'new_phone'
21
+ expect(phone.label).to eq 'New Phone'
22
+ end
23
+ end
24
+
25
+ describe '#to_s' do
26
+ let(:phone) { FactoryGirl.build :phone_number, number: '077/777 88 99' }
27
+
28
+ it 'returns the sole number by default' do
29
+ expect(phone.to_s).to eq '077/777 88 99'
30
+ end
31
+
32
+ it 'returns the sole number for :default format' do
33
+ expect(phone.to_s(:default)).to eq '077/777 88 99'
34
+ end
35
+
36
+ it 'returns the label and number for the :label format' do
37
+ expect(phone).to receive(:label).and_return('Ph')
38
+ string = phone.to_s(:label)
39
+ expect(string).to match(/077\/777 88 99/)
40
+ expect(string).to match(/Ph/)
41
+ end
42
+
43
+ it 'uses the passed in separator for the :label format' do
44
+ expect(phone).to receive(:label).and_return('Ph')
45
+ expect(phone.to_s(:label, '|')).to eq 'Ph|077/777 88 99'
46
+ end
47
+
48
+ it 'uses locales to the passed in separator for the :label format' do
49
+ expect(phone).to receive(:label).and_return('Ph')
50
+ expect(phone.to_s(:label, '|')).to eq 'Ph|077/777 88 99'
51
+ end
52
+ end
53
+
54
+ describe '#to_url' do
55
+ let(:phone) { FactoryGirl.build :phone_number, number: '123' }
56
+
57
+ it 'returns a tel: URL for phone numbers' do
58
+ phone.phone_number_type = 'phone'
59
+ expect(phone.to_url).to eq 'tel:123'
60
+ end
61
+
62
+ it 'returns a tel: URL for mobile numbers' do
63
+ phone.phone_number_type = 'mobile'
64
+ expect(phone.to_url).to eq 'tel:123'
65
+ end
66
+
67
+ it 'returns a fax: URL for fax numbers' do
68
+ phone.phone_number_type = 'fax'
69
+ expect(phone.to_url).to eq 'fax:123'
70
+ end
71
+
72
+ it 'returns a mailto: URL for email addresses' do
73
+ phone.phone_number_type = 'email'
74
+ expect(phone.to_url).to eq 'mailto:123'
75
+ end
76
+
77
+ it 'returns nil for unknown types' do
78
+ phone.phone_number_type = 'unicorn'
79
+ expect(phone.to_url).to be_nil
80
+ end
81
+ end
82
+ end
@@ -0,0 +1,172 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rails_helper'
4
+
5
+ describe HasVcards::Vcard do
6
+ before { @vcard = FactoryGirl.build :vcard }
7
+
8
+ it 'has a valid factory' do
9
+ expect(@vcard).to be_valid
10
+ end
11
+
12
+ context 'a new instance' do
13
+ let(:vcard) { HasVcards::Vcard.new }
14
+
15
+ it 'has an address autobuilt' do
16
+ expect(vcard.address).to be_a HasVcards::Address
17
+ end
18
+ end
19
+
20
+ describe 'name validation' do
21
+
22
+ it 'accepts vcards with a full name' do
23
+ @vcard.validate_name
24
+
25
+ expect(@vcard.errors).to be_empty
26
+ end
27
+
28
+ it 'accepts vcards with a given name' do
29
+ @vcard.full_name = nil
30
+ @vcard.given_name = 'Ben'
31
+ @vcard.validate_name
32
+
33
+ expect(@vcard.errors).to be_empty
34
+ end
35
+
36
+ it 'accepts vcards with a family name' do
37
+ @vcard.full_name = nil
38
+ @vcard.family_name = 'Hur'
39
+ @vcard.validate_name
40
+
41
+ expect(@vcard.errors).to be_empty
42
+ end
43
+
44
+ it 'rejects vcards without a full name' do
45
+ @vcard.full_name = nil
46
+ @vcard.validate_name
47
+
48
+ expect(@vcard.errors.size).to be 3
49
+ end
50
+ end
51
+
52
+ describe '#full_name' do
53
+
54
+ context 'with an existing full name' do
55
+
56
+ it 'returns the same name' do
57
+ expect(@vcard.full_name).to eq 'Ben Hur'
58
+ end
59
+ end
60
+
61
+ context 'without an existing full name' do
62
+ before { @vcard.full_name = nil }
63
+
64
+ it 'constructs a full name from family- and given name' do
65
+ @vcard.family_name = 'Clark'
66
+ @vcard.given_name = 'Louis'
67
+
68
+ expect(@vcard.full_name).to eq 'Clark Louis'
69
+ end
70
+ end
71
+ end
72
+
73
+ describe '#abbreviated_name' do
74
+
75
+ context 'with an existing full name' do
76
+
77
+ it 'returns the same name' do
78
+ expect(@vcard.abbreviated_name).to eq 'Ben Hur'
79
+ end
80
+ end
81
+
82
+ context 'without an existing full name' do
83
+ before { @vcard.full_name = nil }
84
+
85
+ it 'constructs a full name from family- and given name' do
86
+ @vcard.family_name = 'Clark'
87
+ @vcard.given_name = 'Louis Anderson'
88
+
89
+ expect(@vcard.abbreviated_name).to eq 'L. Clark'
90
+ end
91
+ end
92
+ end
93
+
94
+ it 'delegates attribute accessors to the main address' do
95
+ attributes = [ :post_office_box, :extended_address, :street_address, :locality, :region, :postal_code, :country_name, :zip_locality]
96
+ attributes.each do |attr|
97
+ expect(@vcard.address).to receive(attr)
98
+ @vcard.address.send(attr)
99
+
100
+ expect(@vcard.address).to receive("#{attr}=")
101
+ @vcard.address.send("#{attr}=", 'foo')
102
+ end
103
+ end
104
+
105
+ describe '#address_lines' do
106
+
107
+ it 'only returns non empty lines' do
108
+ @vcard.street_address = '1234 Foobar Street'
109
+ @vcard.post_office_box = '09823'
110
+ @vcard.extended_address = ' '
111
+
112
+ expect(@vcard.address_lines.size).to be 2
113
+ end
114
+
115
+ it 'strips lines' do
116
+ @vcard.street_address = ' 1234 Foobar Street '
117
+ expect(@vcard.address_lines).to include('1234 Foobar Street')
118
+ end
119
+ end
120
+
121
+ describe '#full_address_lines' do
122
+
123
+ it 'also returns the full address and name' do
124
+ @vcard.full_name = 'Fullname'
125
+ @vcard.honorific_prefix = 'Prefix'
126
+ @vcard.street_address = '1234 Foobar Street'
127
+ @vcard.post_office_box = '09823'
128
+
129
+ expect(@vcard.full_address_lines.size).to be 4
130
+ end
131
+
132
+ it 'strips lines' do
133
+ @vcard.street_address = ' 1234 Foobar Street '
134
+ expect(@vcard.address_lines).to include('1234 Foobar Street')
135
+ end
136
+ end
137
+
138
+ describe '#contact_lines' do
139
+ it 'returns contact lines' do
140
+ 3.times { FactoryGirl.create :phone_number, vcard: @vcard }
141
+ expect(@vcard.contacts.size).to eq 3
142
+ expect(@vcard.contact_lines.size).to eq 3
143
+ end
144
+
145
+ it 'strips lines' do
146
+ @vcard.contacts.build(number: ' 123 44 55 ')
147
+ expect(@vcard.contact_lines).to include('123 44 55')
148
+ end
149
+ end
150
+
151
+ describe 'contacts relation' do
152
+ describe '#build_defaults' do
153
+ it 'builds default contacts' do
154
+ @vcard.contacts = []
155
+ @vcard.contacts.build_defaults
156
+ expect(@vcard.contacts.map(&:phone_number_type)).to eql ['Tel. geschäft', 'Tel. privat', 'Handy', 'E-Mail']
157
+ end
158
+
159
+ it 'can be run twice without duplicating default contacts' do
160
+ @vcard.contacts = []
161
+ @vcard.contacts.build_defaults
162
+ expect { @vcard.contacts.build_defaults }.to_not change { @vcard.contacts.size }
163
+ end
164
+
165
+ it 'does not add contacts for existing type' do
166
+ email = @vcard.contacts.build phone_number_type: 'E-Mail'
167
+ @vcard.contacts.build_defaults
168
+ expect(@vcard.contacts.select { |contact| contact.phone_number_type == 'E-Mail' }).to contain_exactly(email)
169
+ end
170
+ end
171
+ end
172
+ end