go_import 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (90) hide show
  1. data/bin/go-import +96 -0
  2. data/lib/go_import/csv_helper.rb +47 -0
  3. data/lib/go_import/email_helper.rb +10 -0
  4. data/lib/go_import/errors.rb +22 -0
  5. data/lib/go_import/excel_helper.rb +10 -0
  6. data/lib/go_import/global_phone.json +6571 -0
  7. data/lib/go_import/model/address.rb +61 -0
  8. data/lib/go_import/model/class_settings.rb +50 -0
  9. data/lib/go_import/model/coworker.rb +76 -0
  10. data/lib/go_import/model/coworker_reference.rb +33 -0
  11. data/lib/go_import/model/customfield.rb +87 -0
  12. data/lib/go_import/model/deal.rb +172 -0
  13. data/lib/go_import/model/deal_class_settings.rb +73 -0
  14. data/lib/go_import/model/deal_state.rb +15 -0
  15. data/lib/go_import/model/deal_status.rb +23 -0
  16. data/lib/go_import/model/deal_status_reference.rb +47 -0
  17. data/lib/go_import/model/deal_status_setting.rb +49 -0
  18. data/lib/go_import/model/documents.rb +51 -0
  19. data/lib/go_import/model/link.rb +70 -0
  20. data/lib/go_import/model/note.rb +97 -0
  21. data/lib/go_import/model/note_classification.rb +25 -0
  22. data/lib/go_import/model/organization.rb +219 -0
  23. data/lib/go_import/model/person.rb +151 -0
  24. data/lib/go_import/model/referencetosource.rb +46 -0
  25. data/lib/go_import/model/relation.rb +23 -0
  26. data/lib/go_import/model/rootmodel.rb +359 -0
  27. data/lib/go_import/model/settings.rb +61 -0
  28. data/lib/go_import/model/tag.rb +35 -0
  29. data/lib/go_import/model_helpers.rb +54 -0
  30. data/lib/go_import/phone_helper.rb +74 -0
  31. data/lib/go_import/roo_helper.rb +80 -0
  32. data/lib/go_import/serialize_helper.rb +186 -0
  33. data/lib/go_import/source.rb +87 -0
  34. data/lib/go_import/templating.rb +52 -0
  35. data/lib/go_import.rb +19 -0
  36. data/sources/csv/.gitignore +14 -0
  37. data/sources/csv/.go_import/runner.rb +62 -0
  38. data/sources/csv/Gemfile +5 -0
  39. data/sources/csv/Rakefile.rb +7 -0
  40. data/sources/csv/converter.rb +179 -0
  41. data/sources/csv/data/coworkers.csv +2 -0
  42. data/sources/csv/data/deals.csv +2 -0
  43. data/sources/csv/data/organizations.csv +2 -0
  44. data/sources/csv/data/persons.csv +2 -0
  45. data/sources/csv/spec/exporter_spec.rb +17 -0
  46. data/sources/csv/spec/sample_data/coworkers.csv +2 -0
  47. data/sources/csv/spec/sample_data/deals.csv +2 -0
  48. data/sources/csv/spec/sample_data/organizations.csv +2 -0
  49. data/sources/csv/spec/sample_data/persons.csv +2 -0
  50. data/sources/csv/spec/spec_helper.rb +30 -0
  51. data/sources/easy/.gitignore +14 -0
  52. data/sources/easy/.go_import/runner.rb +115 -0
  53. data/sources/easy/Export/readme.txt +6 -0
  54. data/sources/easy/Gemfile +5 -0
  55. data/sources/easy/Rakefile.rb +7 -0
  56. data/sources/easy/converter.rb +435 -0
  57. data/sources/easy/spec/exporter_spec.rb +10 -0
  58. data/sources/easy/spec/sample_data/Company.txt +649 -0
  59. data/sources/easy/spec/spec_helper.rb +30 -0
  60. data/sources/excel/.gitignore +14 -0
  61. data/sources/excel/.go_import/runner.rb +116 -0
  62. data/sources/excel/Gemfile +6 -0
  63. data/sources/excel/Rakefile.rb +7 -0
  64. data/sources/excel/converter.rb +130 -0
  65. data/sources/excel/spec/sample_data/sample.xlsx +0 -0
  66. data/sources/excel/spec/spec_helper.rb +26 -0
  67. data/sources/excel/spec/tomodel_spec.rb +18 -0
  68. data/sources/excel/template.xlsx +0 -0
  69. data/spec/address_spec.rb +49 -0
  70. data/spec/class_settings_spec.rb +37 -0
  71. data/spec/coworker_spec.rb +94 -0
  72. data/spec/custom_field_spec.rb +22 -0
  73. data/spec/deal_class_settings_spec.rb +104 -0
  74. data/spec/deal_spec.rb +182 -0
  75. data/spec/deal_status_reference_spec.rb +17 -0
  76. data/spec/documents_spec.rb +37 -0
  77. data/spec/helpers/csv_helper_spec.rb +29 -0
  78. data/spec/helpers/email_helper_spec.rb +32 -0
  79. data/spec/helpers/phone_helper_spec.rb +97 -0
  80. data/spec/helpers/roo_helper_spec.rb +10 -0
  81. data/spec/helpers/serialize_helper_spec.rb +249 -0
  82. data/spec/helpers/xsd_validate_spec.rb +55 -0
  83. data/spec/link_spec.rb +106 -0
  84. data/spec/note_spec.rb +110 -0
  85. data/spec/organization_spec.rb +151 -0
  86. data/spec/person_spec.rb +132 -0
  87. data/spec/rootmodel_spec.rb +371 -0
  88. data/spec/spec_helper.rb +30 -0
  89. data/spec/templating_spec.rb +12 -0
  90. metadata +306 -0
data/spec/deal_spec.rb ADDED
@@ -0,0 +1,182 @@
1
+ require "spec_helper"
2
+ require 'go_import'
3
+
4
+ describe "Deal" do
5
+ let(:deal){
6
+ GoImport::Deal.new
7
+ }
8
+
9
+ it "will auto convert org to org.ref during assignment" do
10
+ # given
11
+ org = GoImport::Organization.new({:integration_id => "123", :name => "Lundalogik"})
12
+
13
+ # when
14
+ deal.customer = org
15
+
16
+ # then
17
+ deal.customer.is_a?(GoImport::OrganizationReference).should eq true
18
+ end
19
+
20
+ it "will auto convert coworker to coworker.ref during assignment" do
21
+ # given
22
+ coworker = GoImport::Coworker.new({:integration_id => "456", :first_name => "Billy", :last_name => "Bob"})
23
+
24
+ # when
25
+ deal.responsible_coworker = coworker
26
+
27
+ # then
28
+ deal.responsible_coworker.is_a?(GoImport::CoworkerReference).should eq true
29
+ end
30
+
31
+ it "will auto convert person to person.ref during assignment" do
32
+ # given
33
+ person = GoImport::Person.new({:integration_id => "123"})
34
+
35
+ # when
36
+ deal.customer_contact = person
37
+
38
+ # then
39
+ deal.customer_contact.is_a?(GoImport::PersonReference).should eq true
40
+ end
41
+
42
+ it "will fail on validation if name is empty" do
43
+ # given
44
+ deal.name = ""
45
+ deal.status = "required status"
46
+
47
+ # when, then
48
+ deal.validate.length.should be > 0
49
+ end
50
+
51
+ it "will fail on validation if name is nil" do
52
+ # given
53
+ deal.name = nil
54
+ deal.status = "required status"
55
+
56
+ # when, then
57
+ deal.validate.length.should be > 0
58
+ end
59
+
60
+ it "will fail on validation if status dont have a status reference" do
61
+ # given
62
+ deal.name = "Deal must have a name"
63
+ # this will create a status with a status_reference
64
+ deal.status = "Driv"
65
+
66
+ # when
67
+ # and this will set the reference to nil (this will probably
68
+ # never happen in the real world).
69
+ deal.status.status_reference = nil
70
+
71
+ # then
72
+ deal.validate.length.should be > 0
73
+ end
74
+
75
+ it "will fail on validation if status has an invalid status reference" do
76
+ # given
77
+ deal.name = "Deal must have a name"
78
+ deal.status = ""
79
+
80
+ # when, then
81
+ deal.validate.length.should be > 0
82
+ end
83
+
84
+ it "should convert value strings that looks like number to number" do
85
+ # given
86
+ deal.name = "The deal with a strange value"
87
+
88
+ # when
89
+ deal.value = "357 000"
90
+
91
+ # then
92
+ deal.value.should eq "357000"
93
+ end
94
+
95
+ it "should raise invalidvalueerror if value is not a number" do
96
+ # given
97
+ deal.name = "The deal with an invalid value"
98
+
99
+ # when, then
100
+ expect {
101
+ deal.value = "Im not a number"
102
+ }.to raise_error(GoImport::InvalidValueError)
103
+ end
104
+
105
+ it "should set value if value is an integer" do
106
+ # given
107
+ deal.name = "The new deal"
108
+
109
+ # when
110
+ deal.value = "100"
111
+
112
+ # then
113
+ deal.value.should eq "100"
114
+ end
115
+
116
+ it "should set value if value is a float" do
117
+ # given
118
+ deal.name = "The new deal"
119
+
120
+ # when
121
+ deal.value = "100.10"
122
+
123
+ # then
124
+ deal.value.should eq "100.10"
125
+ end
126
+
127
+ it "should set value to 0 if value is nil" do
128
+ # given
129
+ deal.name = "The new deal"
130
+
131
+ # when
132
+ deal.value = nil
133
+
134
+ # then
135
+ deal.value.should eq 0
136
+ end
137
+
138
+ it "should set status_reference from status_setting" do
139
+ # This case should be used when the status is defined in the rootmodel
140
+
141
+ # given
142
+ deal.name = "Deal with status from deal_status_setting"
143
+ deal_status_setting = GoImport::DealStatusSetting.new({:integration_id => "123", :label => "Driv"})
144
+
145
+ # when
146
+ deal.status = deal_status_setting
147
+
148
+ # then
149
+ deal.status.is_a?(GoImport::DealStatus).should eq true
150
+ deal.status.status_reference.is_a?(GoImport::DealStatusReference).should eq true
151
+ deal.status.status_reference.label.should eq "Driv"
152
+ deal.status.status_reference.integration_id.should eq "123"
153
+ end
154
+
155
+ it "should set status_reference from label and integrationid if status is a string" do
156
+ # This case should be used when the status is already defined
157
+ # in the appliation and is referenced by label
158
+
159
+ # given
160
+ deal.name = "Deal with status from label"
161
+
162
+ # when
163
+ deal.status = "Driv"
164
+
165
+ # then
166
+ deal.status.is_a?(GoImport::DealStatus).should eq true
167
+ deal.status.status_reference.is_a?(GoImport::DealStatusReference).should eq true
168
+ deal.status.status_reference.label.should eq "Driv"
169
+ deal.status.status_reference.integration_id.should eq "Driv"
170
+ end
171
+
172
+ it "should raise error if status reference cant be created" do
173
+ # given
174
+ deal.name = "Deal with failed status"
175
+
176
+ # when, then
177
+ expect {
178
+ deal.status = GoImport::DealStatus.new({:id => 123})
179
+ }.to raise_error(GoImport::InvalidDealStatusError)
180
+ end
181
+
182
+ end
@@ -0,0 +1,17 @@
1
+ require "spec_helper"
2
+ require 'go_import'
3
+
4
+ describe "DealStatusReference" do
5
+ let(:deal_status_reference){
6
+ GoImport::DealStatusReference.new
7
+ }
8
+
9
+ it "should fail on validation if name, id and integration_id is nil" do
10
+ # given
11
+ #deal_status_reference
12
+
13
+ # when, then
14
+ deal_status_reference.validate.length.should be > 0
15
+ end
16
+ end
17
+
@@ -0,0 +1,37 @@
1
+ require "spec_helper"
2
+ require 'go_import'
3
+
4
+ describe "Documents" do
5
+ let(:documents) {
6
+ GoImport::Documents.new
7
+ }
8
+
9
+ it "can add a new link" do
10
+ # given
11
+ link = GoImport::Link.new
12
+ link.integration_id = "123key"
13
+ link.url = "http://dropbox.com/files/readme.txt"
14
+
15
+ # when
16
+ documents.add_link link
17
+
18
+ # then
19
+ documents.find_link_by_integration_id("123key").url.should eq "http://dropbox.com/files/readme.txt"
20
+ documents.links.length.should eq 1
21
+ end
22
+
23
+ it "will not add a new link when a link with the same integration_id already exists" do
24
+ # given
25
+ documents.add_link({ :integration_id => "123", :url => "http://dropbox.com" })
26
+ documents.links.length.should eq 1
27
+
28
+ # when, then
29
+ expect {
30
+ documents.add_link({ :integration_id => "123", :url => "http://drive.google.com" })
31
+ }.to raise_error(GoImport::AlreadyAddedError)
32
+ documents.links.length.should eq 1
33
+ documents.find_link_by_integration_id("123").url.should eq "http://dropbox.com"
34
+ end
35
+
36
+ end
37
+
@@ -0,0 +1,29 @@
1
+ require 'spec_helper'
2
+ require 'go_import'
3
+
4
+ describe GoImport::CsvHelper do
5
+ it "should" do
6
+ v = GoImport::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 = GoImport::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 = GoImport::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 = GoImport::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
@@ -0,0 +1,32 @@
1
+ require 'spec_helper'
2
+ require 'go_import'
3
+
4
+ describe GoImport::EmailHelper do
5
+ it "should validate a common email address" do
6
+ # given
7
+ import_email = "apl@lundalogik.se"
8
+
9
+ # when, then
10
+ GoImport::EmailHelper.is_valid?(import_email).should eq true
11
+ end
12
+
13
+ it "should validate an address with firstname.lastname" do
14
+ GoImport::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
+ GoImport::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
+ GoImport::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
+ GoImport::EmailHelper.is_valid?("firstname@example").should eq true
27
+ end
28
+
29
+ it "should not validate an invalid address" do
30
+ GoImport::EmailHelper.is_valid?("hubbabubba").should eq false
31
+ end
32
+ end
@@ -0,0 +1,97 @@
1
+ require 'spec_helper'
2
+ require 'go_import'
3
+
4
+ describe GoImport::PhoneHelper do
5
+ before(:each) do
6
+ GoImport::PhoneHelper.set_country_code(:se)
7
+ end
8
+
9
+ it "should parse phonenumbers" do
10
+ # given, when
11
+ nice_number = GoImport::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 = GoImport::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 = GoImport::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 = GoImport::PhoneHelper.parse_numbers(source1, ['/', ',', "\\\\"])
49
+ home2, mobile2 = GoImport::PhoneHelper.parse_numbers(source2, ['/', ',', "\\\\"])
50
+ home3, mobile3, direct3 = GoImport::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 = GoImport::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 = GoImport::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
+ GoImport::PhoneHelper.set_country_code(:no)
92
+ number = GoImport::PhoneHelper.parse_numbers(source)
93
+
94
+ # then
95
+ number.should eq "+4722130030"
96
+ end
97
+ end
@@ -0,0 +1,10 @@
1
+ require 'spec_helper'
2
+ require 'go_import'
3
+ require 'roo'
4
+ describe GoImport::RooHelper do
5
+ it "should handle sv chars" do
6
+ samplefile = File.join(File.dirname(__FILE__), '..', 'sample_data', 'excel.xlsx')
7
+ rows = GoImport::RooHelper.new(Roo::Excelx.new(samplefile)).rows
8
+ rows.should include({"Alpha"=>"L\u00E5s","Beta"=>"m\u00E4sk","\u00D6rjan"=>"l\u00E4sk","\u00C4skil"=>""})
9
+ end
10
+ end
@@ -0,0 +1,249 @@
1
+ require 'spec_helper'
2
+ require 'go_import'
3
+
4
+ describe GoImport::SerializeHelper do
5
+
6
+ describe "Serialize note" do
7
+ let(:serialized) {
8
+ n = GoImport::Note.new
9
+ n.text = "text"
10
+ GoImport::SerializeHelper::serialize(n,-1)
11
+ }
12
+ it "should contain text" do
13
+ serialized.should match(/<Text>[\n ]*text[\n ]*<\/Text>/)
14
+ end
15
+ it "should contain start tag" do
16
+ serialized.should match(/<Note>/)
17
+ end
18
+ it "should be utf-8" do
19
+ serialized.encoding.should equal Encoding::UTF_8
20
+ end
21
+ end
22
+
23
+ describe "Serialize note with xml inside" do
24
+ let(:serialized) {
25
+ n = GoImport::Note.new
26
+ n.text = "<text>"
27
+ GoImport::SerializeHelper::serialize(n,-1)
28
+ }
29
+ it "should contain encoded text" do
30
+ serialized.should match(/<Text>[\n ]*&lt;text&gt;[\n ]*<\/Text>/)
31
+ end
32
+ end
33
+
34
+ describe "Serialize custom value with xml inside" do
35
+ let(:serialized) {
36
+ v = GoImport::CustomValue.new
37
+ v.value = "<text>"
38
+ v.field = GoImport::CustomFieldReference.new()
39
+ v.field.integration_id = "1"
40
+ GoImport::SerializeHelper::serialize(v,-1)
41
+ }
42
+ it "should contain encoded text" do
43
+ serialized.should match(/<Value>[\n ]*&lt;text&gt;[\n ]*<\/Value>/)
44
+ end
45
+
46
+ end
47
+
48
+ describe "Serialize without data" do
49
+ let(:serialized) {
50
+ p = GoImport::Person.new
51
+ GoImport::SerializeHelper::serialize(p,-1)
52
+ }
53
+ it "should not contain fields that are not set" do
54
+ serialized.should_not match(/<Email>/)
55
+ serialized.should_not match(/<Position>/)
56
+ serialized.should_not match(/<AlternativeEmail>/)
57
+ serialized.should_not match(/<Tags>/)
58
+ serialized.should_not match(/<CustomValues>/)
59
+ end
60
+ it "should be utf-8" do
61
+ serialized.encoding.should equal Encoding::UTF_8
62
+ end
63
+ end
64
+
65
+ describe "Serialize person" do
66
+ let(:serialized) {
67
+ p = GoImport::Person.new
68
+ p.id = "1"
69
+ p.first_name = "Kalle"
70
+ p.last_name = "Anka"
71
+ p.with_source do |source|
72
+ source.par_se('122345')
73
+ end
74
+ #p.source_ref = {:name=>'Go',:id=>"PASE122345"}
75
+ p.with_postal_address do |addr|
76
+ addr.city = "Ankeborg"
77
+ end
78
+ p.currently_employed=true
79
+ p.set_tag("tag:anka")
80
+ p.set_tag("tag:Bj\u{00F6}rk")
81
+ p.set_tag("tag:<Bj\u{00F6}rk>")
82
+ p.set_custom_field({:integration_id=>"2", :value=>"cf value"})
83
+ p.set_custom_field({:integration_id=>"3", :value=>"cf Bj\u{00F6}rk"})
84
+ p.set_custom_field({:integration_id=>"4", :value=>"cf <Bj\u{00F6}rk>"})
85
+ GoImport::SerializeHelper::serialize(p,-1)
86
+ }
87
+ it "should contain first and last name" do
88
+ serialized.should match(/<FirstName>[\n ]*Kalle[\n ]*<\/FirstName>/)
89
+ serialized.should match(/Anka/)
90
+ end
91
+ it "should contain currently_employed" do
92
+ serialized.should match(/<CurrentlyEmployed>[\n ]*true[\n ]*<\/CurrentlyEmployed>/)
93
+ end
94
+ it "should tag name" do
95
+ serialized.should match(/tag:anka/)
96
+ end
97
+ it "should contain address" do
98
+ serialized.should match(/Ankeborg/)
99
+ end
100
+ it "should contain custom field" do
101
+ serialized.should match(/cf value/)
102
+ end
103
+ it "should contain reference to source" do
104
+ serialized.should match(/122345/)
105
+ end
106
+ it "should handle sv chars in tags" do
107
+ serialized.should match(/tag:Bj\u{00F6}rk/)
108
+ end
109
+ it "should handle sv chars in custom value" do
110
+ serialized.should match(/cf Bj\u{00F6}rk/)
111
+ end
112
+ it "should handle xml in tag" do
113
+ serialized.should match(/tag:&lt;Bj\u{00F6}rk&gt;/)
114
+ end
115
+ it "should handle xml in custom value" do
116
+ serialized.should match(/cf &lt;Bj\u{00F6}rk&gt;/)
117
+ end
118
+ it "should be utf-8" do
119
+ serialized.encoding.should equal Encoding::UTF_8
120
+ end
121
+ end
122
+ describe "Serialize organization" do
123
+ let(:serialized) {
124
+ o = GoImport::Organization.new
125
+ o.name = "Ankeborgs bibliotek"
126
+ o.with_source do |source|
127
+ source.par_se('122345')
128
+ end
129
+ #o.source_ref = {:name=>'Go',:id=>"PASE122345"}
130
+ o.set_tag("tag:bibliotek")
131
+ o.set_tag("tag:Bj\u{00F6}rk")
132
+ o.set_custom_field({:integration_id=>"2", :value=>"cf value"})
133
+ o.set_custom_field({:integration_id=>"3", :value=>"cf Bj\u{00F6}rk"})
134
+ o.with_postal_address do |addr|
135
+ addr.city = "Ankeborg"
136
+ end
137
+ o.with_visit_address do |addr|
138
+ addr.city = "Gaaseborg"
139
+ end
140
+ o.add_employee({
141
+ :integration_id => "1",
142
+ :first_name => "Kalle",
143
+ :last_name => "Anka"
144
+ })
145
+ GoImport::SerializeHelper::serialize(o,-1)
146
+ }
147
+ it "should contain name" do
148
+ serialized.should match(/Ankeborgs bibliotek/)
149
+ end
150
+ it "should contain employee" do
151
+ serialized.should match(/Kalle/)
152
+ serialized.should match(/Anka/)
153
+ end
154
+ it "should contain address" do
155
+ serialized.should match(/Ankeborg/)
156
+ serialized.should match(/Gaaseborg/)
157
+ end
158
+ it "should tag name" do
159
+ serialized.should match(/<Tag>[\n ]*tag:bibliotek[\n ]*<\/Tag>/)
160
+ end
161
+ it "should contain custom field" do
162
+ serialized.should match(/cf value/)
163
+ #puts serialized
164
+ end
165
+ it "should contain reference to source" do
166
+ serialized.should match(/122345/)
167
+ end
168
+ it "should handle sv chars in tags" do
169
+ serialized.should match(/tag:Bj\u{00F6}rk/)
170
+ end
171
+ it "should handle sv chars in custom value" do
172
+ serialized.should match(/cf Bj\u{00F6}rk/)
173
+ end
174
+ it "should be utf-8" do
175
+ serialized.encoding.should equal Encoding::UTF_8
176
+ end
177
+ end
178
+
179
+ describe "Serialize goimport" do
180
+ let(:serialized) {
181
+ i = GoImport::RootModel.new
182
+ o = GoImport::Organization.new
183
+ o.name = "Ankeborgs bibliotek"
184
+ i.organizations.push(o)
185
+ GoImport::SerializeHelper::serialize(i,-1)
186
+ }
187
+ it "should contain name" do
188
+ serialized.should match(/Ankeborgs bibliotek/)
189
+ end
190
+ it "should have version" do
191
+ serialized.should match(/<GoImport Version='v2_0'/)
192
+ end
193
+ it "should be utf-8" do
194
+ serialized.encoding.should equal Encoding::UTF_8
195
+ end
196
+ end
197
+ describe "Get import rows" do
198
+ describe "for person" do
199
+ let(:import_rows) { GoImport::Person.new.get_import_rows }
200
+ it "should contain integration id" do
201
+ import_rows.should include({:id=>'integration_id', :name=>'Integration id', :type=>:string})
202
+ import_rows.should include({:id=>'id', :name=>'Go id', :type=>:string})
203
+ end
204
+ it "should contain address" do
205
+ expected = {:id=>'postal_address', :name=>'Postal address', :type=>:address,
206
+ :model=>[
207
+ {:id=>'street',:name=>'Street', :type=>:string},
208
+ {:id=>'zip_code',:name=>'Zip code', :type=>:string},
209
+ {:id=>'city',:name=>'City', :type=>:string},
210
+ {:id=>'country_code',:name=>'Country code', :type=>:string},
211
+ {:id=>'location',:name=>'Location', :type=>:string},
212
+ {:id=>'country_name',:name=>'Country name', :type=>:string},
213
+ ]}
214
+ import_rows.should include(expected)
215
+ end
216
+ it "should contain organization" do
217
+ import_rows.should include({
218
+ :id=>'organization',
219
+ :name=>'Organization',
220
+ :type=>:organization_reference,
221
+ :model=>[
222
+ {:id=>'id', :name=>'Go id', :type=>:string},
223
+ {:id=>'integration_id', :name=>'Integration id', :type=>:string},
224
+ {:id=>'heading', :name=>'Heading', :type=>:string}
225
+ ]
226
+ })
227
+ end
228
+ end
229
+ describe "for organization" do
230
+ let(:import_rows) { GoImport::Organization.new.get_import_rows }
231
+ it "should contain integration id" do
232
+ import_rows.should include({:id=>'integration_id', :name=>'Integration id', :type=>:string})
233
+ import_rows.should include({:id=>'id', :name=>'Go id', :type=>:string})
234
+ end
235
+ it "should contain address" do
236
+ expected = {:id=>'postal_address', :name=>'Postal address', :type=>:address,
237
+ :model=>[
238
+ {:id=>'street',:name=>'Street', :type=>:string},
239
+ {:id=>'zip_code',:name=>'Zip code', :type=>:string},
240
+ {:id=>'city',:name=>'City', :type=>:string},
241
+ {:id=>'country_code',:name=>'Country code', :type=>:string},
242
+ {:id=>'location',:name=>'Location', :type=>:string},
243
+ {:id=>'country_name',:name=>'Country name', :type=>:string},
244
+ ]}
245
+ import_rows.should include(expected)
246
+ end
247
+ end
248
+ end
249
+ end