fruit_to_lime 2.5.3 → 2.5.5
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.
- data/lib/fruit_to_lime.rb +17 -17
- data/lib/fruit_to_lime/csv_helper.rb +47 -47
- data/lib/fruit_to_lime/email_helper.rb +10 -10
- data/lib/fruit_to_lime/errors.rb +16 -16
- data/lib/fruit_to_lime/excel_helper.rb +10 -10
- data/lib/fruit_to_lime/global_phone.json +6571 -6571
- data/lib/fruit_to_lime/model/address.rb +60 -60
- data/lib/fruit_to_lime/model/class_settings.rb +50 -50
- data/lib/fruit_to_lime/model/coworker.rb +76 -76
- data/lib/fruit_to_lime/model/coworker_reference.rb +33 -33
- data/lib/fruit_to_lime/model/customfield.rb +87 -87
- data/lib/fruit_to_lime/model/deal.rb +141 -145
- data/lib/fruit_to_lime/model/deal_status.rb +12 -12
- data/lib/fruit_to_lime/model/note.rb +79 -79
- data/lib/fruit_to_lime/model/organization.rb +203 -197
- data/lib/fruit_to_lime/model/person.rb +151 -151
- data/lib/fruit_to_lime/model/referencetosource.rb +45 -45
- data/lib/fruit_to_lime/model/relation.rb +23 -23
- data/lib/fruit_to_lime/model/rootmodel.rb +338 -330
- data/lib/fruit_to_lime/model/settings.rb +60 -60
- data/lib/fruit_to_lime/model/tag.rb +35 -35
- data/lib/fruit_to_lime/model_helpers.rb +54 -54
- data/lib/fruit_to_lime/phone_helper.rb +74 -74
- data/lib/fruit_to_lime/roo_helper.rb +72 -72
- data/lib/fruit_to_lime/serialize_helper.rb +186 -186
- data/lib/fruit_to_lime/templating.rb +52 -52
- data/spec/address_spec.rb +48 -48
- data/spec/class_settings_spec.rb +37 -37
- data/spec/coworker_spec.rb +94 -94
- data/spec/custom_field_spec.rb +22 -22
- data/spec/deal_spec.rb +101 -102
- data/spec/helpers/csv_helper_spec.rb +29 -29
- data/spec/helpers/email_helper_spec.rb +32 -32
- data/spec/helpers/phone_helper_spec.rb +97 -97
- data/spec/helpers/serialize_helper_spec.rb +249 -249
- data/spec/helpers/xsd_validate_spec.rb +58 -58
- data/spec/note_spec.rb +98 -67
- data/spec/organization_spec.rb +103 -89
- data/spec/person_spec.rb +134 -134
- data/spec/rootmodel_spec.rb +277 -230
- data/spec/templating_spec.rb +11 -11
- data/templates/csv/lib/tomodel.rb +230 -230
- data/templates/csv/spec/exporter_spec.rb +17 -17
- data/templates/csv/spec/sample_data/coworkers.csv +2 -2
- data/templates/csv/spec/sample_data/deals.csv +2 -2
- data/templates/csv/spec/sample_data/organizations.csv +2 -2
- data/templates/csv/spec/sample_data/persons.csv +2 -2
- data/templates/easy/Gemfile +5 -0
- data/templates/easy/Rakefile.rb +7 -0
- data/templates/easy/convert.rb +3 -0
- data/templates/easy/lib/tomodel.rb +330 -0
- data/templates/easy/spec/exporter_spec.rb +10 -0
- data/templates/easy/spec/sample_data/Company.txt +649 -0
- data/templates/easy/spec/spec_helper.rb +24 -0
- data/templates/excel/lib/tomodel.rb +207 -207
- data/templates/sqlserver/lib/tomodel.rb +79 -79
- metadata +10 -3
data/spec/custom_field_spec.rb
CHANGED
@@ -1,22 +1,22 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
require 'fruit_to_lime'
|
3
|
-
|
4
|
-
describe "CustomField" do
|
5
|
-
before (:all) do
|
6
|
-
@custom_field = FruitToLime::CustomField.new({:id => 'the id',
|
7
|
-
:integration_id=>'the key',
|
8
|
-
:value=> 'the value'})
|
9
|
-
end
|
10
|
-
|
11
|
-
it "is the same as a custom field with the same integration_id" do
|
12
|
-
@custom_field.same_as?(FruitToLime::CustomField.new({:integration_id=>'the key',
|
13
|
-
:value=> 'the value 2'})).should eq true
|
14
|
-
end
|
15
|
-
|
16
|
-
it "is the same as a custom field with the same id" do
|
17
|
-
@custom_field.same_as?(FruitToLime::CustomField.new({:id=>'the id',
|
18
|
-
:value=> 'the value 2'})).should eq true
|
19
|
-
end
|
20
|
-
|
21
|
-
end
|
22
|
-
|
1
|
+
require "spec_helper"
|
2
|
+
require 'fruit_to_lime'
|
3
|
+
|
4
|
+
describe "CustomField" do
|
5
|
+
before (:all) do
|
6
|
+
@custom_field = FruitToLime::CustomField.new({:id => 'the id',
|
7
|
+
:integration_id=>'the key',
|
8
|
+
:value=> 'the value'})
|
9
|
+
end
|
10
|
+
|
11
|
+
it "is the same as a custom field with the same integration_id" do
|
12
|
+
@custom_field.same_as?(FruitToLime::CustomField.new({:integration_id=>'the key',
|
13
|
+
:value=> 'the value 2'})).should eq true
|
14
|
+
end
|
15
|
+
|
16
|
+
it "is the same as a custom field with the same id" do
|
17
|
+
@custom_field.same_as?(FruitToLime::CustomField.new({:id=>'the id',
|
18
|
+
:value=> 'the value 2'})).should eq true
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
|
data/spec/deal_spec.rb
CHANGED
@@ -1,102 +1,101 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
require 'fruit_to_lime'
|
3
|
-
|
4
|
-
describe "Deal" do
|
5
|
-
let(:deal){
|
6
|
-
FruitToLime::Deal.new
|
7
|
-
}
|
8
|
-
|
9
|
-
it "can attach a current status" do
|
10
|
-
deal.with_status do |status|
|
11
|
-
status.label = 'xyz'
|
12
|
-
status.id = '123'
|
13
|
-
status.date = DateTime.now
|
14
|
-
status.note = 'ho ho'
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
it "will auto convert org to org.ref during assignment" do
|
19
|
-
# given
|
20
|
-
org = FruitToLime::Organization.new({:integration_id => "123", :name => "Lundalogik"})
|
21
|
-
|
22
|
-
# when
|
23
|
-
deal.customer = org
|
24
|
-
|
25
|
-
# then
|
26
|
-
deal.customer.is_a?(FruitToLime::OrganizationReference).should eq true
|
27
|
-
end
|
28
|
-
|
29
|
-
it "will auto convert coworker to coworker.ref during assignment" do
|
30
|
-
# given
|
31
|
-
coworker = FruitToLime::Coworker.new({:integration_id => "456", :first_name => "Billy", :last_name => "Bob"})
|
32
|
-
|
33
|
-
# when
|
34
|
-
deal.responsible_coworker = coworker
|
35
|
-
|
36
|
-
# then
|
37
|
-
deal.responsible_coworker.is_a?(FruitToLime::CoworkerReference).should eq true
|
38
|
-
end
|
39
|
-
|
40
|
-
it "will auto convert person to person.ref during assignment" do
|
41
|
-
# given
|
42
|
-
person = FruitToLime::Person.new({:integration_id => "123"})
|
43
|
-
|
44
|
-
# when
|
45
|
-
deal.customer_contact = person
|
46
|
-
|
47
|
-
# then
|
48
|
-
deal.customer_contact.is_a?(FruitToLime::PersonReference).should eq true
|
49
|
-
end
|
50
|
-
|
51
|
-
it "will fail on validation if name
|
52
|
-
# given
|
53
|
-
deal.name = "The big deal"
|
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
|
-
end
|
1
|
+
require "spec_helper"
|
2
|
+
require 'fruit_to_lime'
|
3
|
+
|
4
|
+
describe "Deal" do
|
5
|
+
let(:deal){
|
6
|
+
FruitToLime::Deal.new
|
7
|
+
}
|
8
|
+
|
9
|
+
it "can attach a current status" do
|
10
|
+
deal.with_status do |status|
|
11
|
+
status.label = 'xyz'
|
12
|
+
status.id = '123'
|
13
|
+
status.date = DateTime.now
|
14
|
+
status.note = 'ho ho'
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
it "will auto convert org to org.ref during assignment" do
|
19
|
+
# given
|
20
|
+
org = FruitToLime::Organization.new({:integration_id => "123", :name => "Lundalogik"})
|
21
|
+
|
22
|
+
# when
|
23
|
+
deal.customer = org
|
24
|
+
|
25
|
+
# then
|
26
|
+
deal.customer.is_a?(FruitToLime::OrganizationReference).should eq true
|
27
|
+
end
|
28
|
+
|
29
|
+
it "will auto convert coworker to coworker.ref during assignment" do
|
30
|
+
# given
|
31
|
+
coworker = FruitToLime::Coworker.new({:integration_id => "456", :first_name => "Billy", :last_name => "Bob"})
|
32
|
+
|
33
|
+
# when
|
34
|
+
deal.responsible_coworker = coworker
|
35
|
+
|
36
|
+
# then
|
37
|
+
deal.responsible_coworker.is_a?(FruitToLime::CoworkerReference).should eq true
|
38
|
+
end
|
39
|
+
|
40
|
+
it "will auto convert person to person.ref during assignment" do
|
41
|
+
# given
|
42
|
+
person = FruitToLime::Person.new({:integration_id => "123"})
|
43
|
+
|
44
|
+
# when
|
45
|
+
deal.customer_contact = person
|
46
|
+
|
47
|
+
# then
|
48
|
+
deal.customer_contact.is_a?(FruitToLime::PersonReference).should eq true
|
49
|
+
end
|
50
|
+
|
51
|
+
it "will fail on validation if name is empty" do
|
52
|
+
# given
|
53
|
+
deal.name = "The big deal"
|
54
|
+
|
55
|
+
# when, then
|
56
|
+
deal.validate.should eq ""
|
57
|
+
end
|
58
|
+
|
59
|
+
it "should convert value strings that looks like number to number" do
|
60
|
+
# given
|
61
|
+
deal.name = "The deal with a strange value"
|
62
|
+
|
63
|
+
# when
|
64
|
+
deal.value = "357 000"
|
65
|
+
|
66
|
+
# then
|
67
|
+
deal.value.should eq "357000"
|
68
|
+
end
|
69
|
+
|
70
|
+
it "should raise invalidvalueerror if value is not a number" do
|
71
|
+
# given
|
72
|
+
deal.name = "The deal with an invalid value"
|
73
|
+
|
74
|
+
# when, then
|
75
|
+
expect {
|
76
|
+
deal.value = "Im not a number"
|
77
|
+
}.to raise_error(FruitToLime::InvalidValueError)
|
78
|
+
end
|
79
|
+
|
80
|
+
it "should set value if value is an integer" do
|
81
|
+
# given
|
82
|
+
deal.name = "The new deal"
|
83
|
+
|
84
|
+
# when
|
85
|
+
deal.value = "100"
|
86
|
+
|
87
|
+
# then
|
88
|
+
deal.value.should eq "100"
|
89
|
+
end
|
90
|
+
|
91
|
+
it "should set value if value is a float" do
|
92
|
+
# given
|
93
|
+
deal.name = "The new deal"
|
94
|
+
|
95
|
+
# when
|
96
|
+
deal.value = "100.10"
|
97
|
+
|
98
|
+
# then
|
99
|
+
deal.value.should eq "100.10"
|
100
|
+
end
|
101
|
+
end
|
@@ -1,29 +1,29 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'fruit_to_lime'
|
3
|
-
|
4
|
-
describe FruitToLime::CsvHelper do
|
5
|
-
it "should" do
|
6
|
-
v = FruitToLime::CsvHelper.text_to_hashes("id;navn
|
7
|
-
1;Noerrebro")
|
8
|
-
v.should include({"id"=>"1","navn"=>"Noerrebro"})
|
9
|
-
end
|
10
|
-
it "should handle sv chars" do
|
11
|
-
v = FruitToLime::CsvHelper.text_to_hashes("id;navn
|
12
|
-
1;Bj\u{00F6}rk")
|
13
|
-
v.should include({"id"=>"1","navn"=>"Bj\u{00F6}rk"})
|
14
|
-
end
|
15
|
-
it "should handle escaped newlines" do
|
16
|
-
v = FruitToLime::CsvHelper.text_to_hashes("id;navn
|
17
|
-
1;\"Bj\u{00F6}rk
|
18
|
-
And a new line\"")
|
19
|
-
v.should include({"id"=>"1","navn"=>"Bj\u{00F6}rk
|
20
|
-
And a new line"})
|
21
|
-
end
|
22
|
-
it "should handle escaped newlines with ',' as delim" do
|
23
|
-
v = FruitToLime::CsvHelper.text_to_hashes("id,navn
|
24
|
-
1,\"Bj\u{00F6}rk
|
25
|
-
And a new line\"")
|
26
|
-
v.should include({"id"=>"1","navn"=>"Bj\u{00F6}rk
|
27
|
-
And a new line"})
|
28
|
-
end
|
29
|
-
end
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'fruit_to_lime'
|
3
|
+
|
4
|
+
describe FruitToLime::CsvHelper do
|
5
|
+
it "should" do
|
6
|
+
v = FruitToLime::CsvHelper.text_to_hashes("id;navn
|
7
|
+
1;Noerrebro")
|
8
|
+
v.should include({"id"=>"1","navn"=>"Noerrebro"})
|
9
|
+
end
|
10
|
+
it "should handle sv chars" do
|
11
|
+
v = FruitToLime::CsvHelper.text_to_hashes("id;navn
|
12
|
+
1;Bj\u{00F6}rk")
|
13
|
+
v.should include({"id"=>"1","navn"=>"Bj\u{00F6}rk"})
|
14
|
+
end
|
15
|
+
it "should handle escaped newlines" do
|
16
|
+
v = FruitToLime::CsvHelper.text_to_hashes("id;navn
|
17
|
+
1;\"Bj\u{00F6}rk
|
18
|
+
And a new line\"")
|
19
|
+
v.should include({"id"=>"1","navn"=>"Bj\u{00F6}rk
|
20
|
+
And a new line"})
|
21
|
+
end
|
22
|
+
it "should handle escaped newlines with ',' as delim" do
|
23
|
+
v = FruitToLime::CsvHelper.text_to_hashes("id,navn
|
24
|
+
1,\"Bj\u{00F6}rk
|
25
|
+
And a new line\"")
|
26
|
+
v.should include({"id"=>"1","navn"=>"Bj\u{00F6}rk
|
27
|
+
And a new line"})
|
28
|
+
end
|
29
|
+
end
|
@@ -1,32 +1,32 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'fruit_to_lime'
|
3
|
-
|
4
|
-
describe FruitToLime::EmailHelper do
|
5
|
-
it "should validate a common email address" do
|
6
|
-
# given
|
7
|
-
import_email = "apl@lundalogik.se"
|
8
|
-
|
9
|
-
# when, then
|
10
|
-
FruitToLime::EmailHelper.is_valid?(import_email).should eq true
|
11
|
-
end
|
12
|
-
|
13
|
-
it "should validate an address with firstname.lastname" do
|
14
|
-
FruitToLime::EmailHelper.is_valid?("firstname.lastname@example.com").should eq true
|
15
|
-
end
|
16
|
-
|
17
|
-
it "should validate an address with lots of subdomains" do
|
18
|
-
FruitToLime::EmailHelper.is_valid?("firstname.lastname@sub1.sub2.example.com").should eq true
|
19
|
-
end
|
20
|
-
|
21
|
-
it "should validate an address with some special chars" do
|
22
|
-
FruitToLime::EmailHelper.is_valid?("firstname-lastname+=@sub1.sub2.example.com").should eq true
|
23
|
-
end
|
24
|
-
|
25
|
-
it "should validate an address with no top level domain" do
|
26
|
-
FruitToLime::EmailHelper.is_valid?("firstname@example").should eq true
|
27
|
-
end
|
28
|
-
|
29
|
-
it "should not validate an invalid address" do
|
30
|
-
FruitToLime::EmailHelper.is_valid?("hubbabubba").should eq false
|
31
|
-
end
|
32
|
-
end
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'fruit_to_lime'
|
3
|
+
|
4
|
+
describe FruitToLime::EmailHelper do
|
5
|
+
it "should validate a common email address" do
|
6
|
+
# given
|
7
|
+
import_email = "apl@lundalogik.se"
|
8
|
+
|
9
|
+
# when, then
|
10
|
+
FruitToLime::EmailHelper.is_valid?(import_email).should eq true
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should validate an address with firstname.lastname" do
|
14
|
+
FruitToLime::EmailHelper.is_valid?("firstname.lastname@example.com").should eq true
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should validate an address with lots of subdomains" do
|
18
|
+
FruitToLime::EmailHelper.is_valid?("firstname.lastname@sub1.sub2.example.com").should eq true
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should validate an address with some special chars" do
|
22
|
+
FruitToLime::EmailHelper.is_valid?("firstname-lastname+=@sub1.sub2.example.com").should eq true
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should validate an address with no top level domain" do
|
26
|
+
FruitToLime::EmailHelper.is_valid?("firstname@example").should eq true
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should not validate an invalid address" do
|
30
|
+
FruitToLime::EmailHelper.is_valid?("hubbabubba").should eq false
|
31
|
+
end
|
32
|
+
end
|
@@ -1,97 +1,97 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'fruit_to_lime'
|
3
|
-
|
4
|
-
describe FruitToLime::PhoneHelper do
|
5
|
-
before(:each) do
|
6
|
-
FruitToLime::PhoneHelper.set_country_code(:se)
|
7
|
-
end
|
8
|
-
|
9
|
-
it "should parse phonenumbers" do
|
10
|
-
# given, when
|
11
|
-
nice_number = FruitToLime::PhoneHelper.parse_numbers("0709-685226")
|
12
|
-
|
13
|
-
# then
|
14
|
-
nice_number.should eq "+46709685226"
|
15
|
-
end
|
16
|
-
|
17
|
-
it "should parse multiple numbers with default delimiter" do
|
18
|
-
# given
|
19
|
-
source = "046 - 270 48 00, 0709-685226"
|
20
|
-
|
21
|
-
# when
|
22
|
-
home, mobile = FruitToLime::PhoneHelper.parse_numbers(source)
|
23
|
-
|
24
|
-
# then
|
25
|
-
home.should eq "+46462704800"
|
26
|
-
mobile.should eq "+46709685226"
|
27
|
-
end
|
28
|
-
|
29
|
-
it "should parse multiple numbers with custom delimiter" do
|
30
|
-
# given
|
31
|
-
source = "046 - 270 48 00/ 0709-685226"
|
32
|
-
|
33
|
-
# when
|
34
|
-
home, mobile = FruitToLime::PhoneHelper.parse_numbers(source, '/')
|
35
|
-
|
36
|
-
# then
|
37
|
-
home.should eq "+46462704800"
|
38
|
-
mobile.should eq "+46709685226"
|
39
|
-
end
|
40
|
-
|
41
|
-
it "should parse numbers with different delimiters" do
|
42
|
-
# given
|
43
|
-
source1 = "046 - 270 48 00/ 0709-685226"
|
44
|
-
source2 = "08-562 776 00, 070-73 85 180"
|
45
|
-
source3 = "031-712 44 00\\\\ 0707 38 52 72/, 031 71 244 04"
|
46
|
-
|
47
|
-
# when
|
48
|
-
home1, mobile1 = FruitToLime::PhoneHelper.parse_numbers(source1, ['/', ',', "\\\\"])
|
49
|
-
home2, mobile2 = FruitToLime::PhoneHelper.parse_numbers(source2, ['/', ',', "\\\\"])
|
50
|
-
home3, mobile3, direct3 = FruitToLime::PhoneHelper.parse_numbers(source3, ['/', ',', "\\\\"])
|
51
|
-
|
52
|
-
# then
|
53
|
-
home1.should eq "+46462704800"
|
54
|
-
mobile1.should eq "+46709685226"
|
55
|
-
|
56
|
-
home2.should eq "+46856277600"
|
57
|
-
mobile2.should eq "+46707385180"
|
58
|
-
|
59
|
-
home3.should eq "+46317124400"
|
60
|
-
mobile3.should eq "+46707385272"
|
61
|
-
direct3.should eq "+46317124404"
|
62
|
-
end
|
63
|
-
|
64
|
-
it "should not mess with invalid numbers by default" do
|
65
|
-
# given
|
66
|
-
source = "im not a number"
|
67
|
-
|
68
|
-
# when
|
69
|
-
number = FruitToLime::PhoneHelper.parse_numbers(source)
|
70
|
-
|
71
|
-
# then
|
72
|
-
number.should eq "im not a number"
|
73
|
-
end
|
74
|
-
|
75
|
-
it "should not mess with invalid numbers unless strict mode" do
|
76
|
-
# given
|
77
|
-
source = "im not a number"
|
78
|
-
|
79
|
-
# when
|
80
|
-
number = FruitToLime::PhoneHelper.parse_numbers_strict(source)
|
81
|
-
|
82
|
-
# then
|
83
|
-
number.should eq ""
|
84
|
-
end
|
85
|
-
|
86
|
-
it "should parse foreign numbers" do
|
87
|
-
# given
|
88
|
-
source = "22 13 00 30"
|
89
|
-
|
90
|
-
# when
|
91
|
-
FruitToLime::PhoneHelper.set_country_code(:no)
|
92
|
-
number = FruitToLime::PhoneHelper.parse_numbers(source)
|
93
|
-
|
94
|
-
# then
|
95
|
-
number.should eq "+4722130030"
|
96
|
-
end
|
97
|
-
end
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'fruit_to_lime'
|
3
|
+
|
4
|
+
describe FruitToLime::PhoneHelper do
|
5
|
+
before(:each) do
|
6
|
+
FruitToLime::PhoneHelper.set_country_code(:se)
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should parse phonenumbers" do
|
10
|
+
# given, when
|
11
|
+
nice_number = FruitToLime::PhoneHelper.parse_numbers("0709-685226")
|
12
|
+
|
13
|
+
# then
|
14
|
+
nice_number.should eq "+46709685226"
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should parse multiple numbers with default delimiter" do
|
18
|
+
# given
|
19
|
+
source = "046 - 270 48 00, 0709-685226"
|
20
|
+
|
21
|
+
# when
|
22
|
+
home, mobile = FruitToLime::PhoneHelper.parse_numbers(source)
|
23
|
+
|
24
|
+
# then
|
25
|
+
home.should eq "+46462704800"
|
26
|
+
mobile.should eq "+46709685226"
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should parse multiple numbers with custom delimiter" do
|
30
|
+
# given
|
31
|
+
source = "046 - 270 48 00/ 0709-685226"
|
32
|
+
|
33
|
+
# when
|
34
|
+
home, mobile = FruitToLime::PhoneHelper.parse_numbers(source, '/')
|
35
|
+
|
36
|
+
# then
|
37
|
+
home.should eq "+46462704800"
|
38
|
+
mobile.should eq "+46709685226"
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should parse numbers with different delimiters" do
|
42
|
+
# given
|
43
|
+
source1 = "046 - 270 48 00/ 0709-685226"
|
44
|
+
source2 = "08-562 776 00, 070-73 85 180"
|
45
|
+
source3 = "031-712 44 00\\\\ 0707 38 52 72/, 031 71 244 04"
|
46
|
+
|
47
|
+
# when
|
48
|
+
home1, mobile1 = FruitToLime::PhoneHelper.parse_numbers(source1, ['/', ',', "\\\\"])
|
49
|
+
home2, mobile2 = FruitToLime::PhoneHelper.parse_numbers(source2, ['/', ',', "\\\\"])
|
50
|
+
home3, mobile3, direct3 = FruitToLime::PhoneHelper.parse_numbers(source3, ['/', ',', "\\\\"])
|
51
|
+
|
52
|
+
# then
|
53
|
+
home1.should eq "+46462704800"
|
54
|
+
mobile1.should eq "+46709685226"
|
55
|
+
|
56
|
+
home2.should eq "+46856277600"
|
57
|
+
mobile2.should eq "+46707385180"
|
58
|
+
|
59
|
+
home3.should eq "+46317124400"
|
60
|
+
mobile3.should eq "+46707385272"
|
61
|
+
direct3.should eq "+46317124404"
|
62
|
+
end
|
63
|
+
|
64
|
+
it "should not mess with invalid numbers by default" do
|
65
|
+
# given
|
66
|
+
source = "im not a number"
|
67
|
+
|
68
|
+
# when
|
69
|
+
number = FruitToLime::PhoneHelper.parse_numbers(source)
|
70
|
+
|
71
|
+
# then
|
72
|
+
number.should eq "im not a number"
|
73
|
+
end
|
74
|
+
|
75
|
+
it "should not mess with invalid numbers unless strict mode" do
|
76
|
+
# given
|
77
|
+
source = "im not a number"
|
78
|
+
|
79
|
+
# when
|
80
|
+
number = FruitToLime::PhoneHelper.parse_numbers_strict(source)
|
81
|
+
|
82
|
+
# then
|
83
|
+
number.should eq ""
|
84
|
+
end
|
85
|
+
|
86
|
+
it "should parse foreign numbers" do
|
87
|
+
# given
|
88
|
+
source = "22 13 00 30"
|
89
|
+
|
90
|
+
# when
|
91
|
+
FruitToLime::PhoneHelper.set_country_code(:no)
|
92
|
+
number = FruitToLime::PhoneHelper.parse_numbers(source)
|
93
|
+
|
94
|
+
# then
|
95
|
+
number.should eq "+4722130030"
|
96
|
+
end
|
97
|
+
end
|