fruit_to_lime 0.9.1 → 0.9.2
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/fruit_to_lime +24 -24
- data/lib/fruit_to_lime/address_helper.rb +17 -17
- data/lib/fruit_to_lime/csv_helper.rb +32 -32
- data/lib/fruit_to_lime/model/address.rb +37 -37
- data/lib/fruit_to_lime/model/coworker.rb +44 -44
- data/lib/fruit_to_lime/model/coworker_reference.rb +17 -17
- data/lib/fruit_to_lime/model/customfield.rb +30 -30
- data/lib/fruit_to_lime/model/note.rb +38 -38
- data/lib/fruit_to_lime/model/organization.rb +140 -140
- data/lib/fruit_to_lime/model/person.rb +115 -115
- data/lib/fruit_to_lime/model/referencetosource.rb +42 -42
- data/lib/fruit_to_lime/model/rootmodel.rb +142 -142
- data/lib/fruit_to_lime/model/tag.rb +33 -33
- data/lib/fruit_to_lime/model_helpers.rb +19 -19
- data/lib/fruit_to_lime/roo_helper.rb +59 -59
- data/lib/fruit_to_lime/serialize_helper.rb +139 -139
- data/lib/fruit_to_lime/templating.rb +51 -51
- data/lib/fruit_to_lime.rb +13 -13
- data/spec/helpers/address_helper_spec.rb +48 -48
- data/spec/helpers/csv_helper_spec.rb +15 -15
- data/spec/helpers/roo_helper_spec.rb +10 -10
- data/spec/helpers/serialize_helper_spec.rb +211 -211
- data/spec/person_spec.rb +44 -44
- data/spec/spec_helper.rb +24 -24
- data/templates/csv/Gemfile +5 -5
- data/templates/csv/Rakefile.rb +7 -7
- data/templates/csv/convert.rb +2 -2
- data/templates/csv/lib/tomodel.rb +56 -56
- data/templates/csv/spec/sample_data/organizations.csv +2 -2
- data/templates/csv/spec/spec_helper.rb +24 -24
- data/templates/csv/spec/tomodel_spec.rb +14 -14
- data/templates/excel/Gemfile +6 -6
- data/templates/excel/Rakefile.rb +7 -7
- data/templates/excel/convert.rb +2 -2
- data/templates/excel/lib/tomodel.rb +53 -53
- data/templates/excel/spec/spec_helper.rb +20 -20
- data/templates/excel/spec/tomodel_spec.rb +18 -18
- data/templates/sqlserver/Gemfile +6 -6
- data/templates/sqlserver/Rakefile.rb +7 -7
- data/templates/sqlserver/convert.rb +2 -2
- data/templates/sqlserver/lib/tomodel.rb +67 -67
- data/templates/sqlserver/spec/spec_helper.rb +20 -20
- data/templates/sqlserver/spec/tomodel_spec.rb +9 -9
- metadata +2 -2
data/lib/fruit_to_lime.rb
CHANGED
@@ -1,13 +1,13 @@
|
|
1
|
-
module FruitToLime
|
2
|
-
def self.require_all_in(folder)
|
3
|
-
Dir.glob(File.join( File.dirname(File.absolute_path(__FILE__)),folder), &method(:require))
|
4
|
-
end
|
5
|
-
|
6
|
-
require 'fruit_to_lime/serialize_helper'
|
7
|
-
require 'fruit_to_lime/address_helper'
|
8
|
-
require 'fruit_to_lime/model_helpers'
|
9
|
-
FruitToLime::require_all_in 'fruit_to_lime/model/*.rb'
|
10
|
-
require 'fruit_to_lime/csv_helper'
|
11
|
-
require 'fruit_to_lime/roo_helper'
|
12
|
-
require 'fruit_to_lime/templating'
|
13
|
-
end
|
1
|
+
module FruitToLime
|
2
|
+
def self.require_all_in(folder)
|
3
|
+
Dir.glob(File.join( File.dirname(File.absolute_path(__FILE__)),folder), &method(:require))
|
4
|
+
end
|
5
|
+
|
6
|
+
require 'fruit_to_lime/serialize_helper'
|
7
|
+
require 'fruit_to_lime/address_helper'
|
8
|
+
require 'fruit_to_lime/model_helpers'
|
9
|
+
FruitToLime::require_all_in 'fruit_to_lime/model/*.rb'
|
10
|
+
require 'fruit_to_lime/csv_helper'
|
11
|
+
require 'fruit_to_lime/roo_helper'
|
12
|
+
require 'fruit_to_lime/templating'
|
13
|
+
end
|
@@ -1,49 +1,49 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'fruit_to_lime'
|
3
|
-
|
4
|
-
describe FruitToLime::AddressHelper do
|
5
|
-
describe "Parse line with swedish zip and city into zipcode" do
|
6
|
-
let (:zip_code) {
|
7
|
-
address = FruitToLime::Address.new
|
8
|
-
line = "114 45 STOCKHOLM"
|
9
|
-
address.parse_zip_and_address_se(line).zip_code
|
10
|
-
}
|
11
|
-
it "should have zipcode equal to '114 45'" do
|
12
|
-
zip_code.should eq '114 45'
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
describe "Parse line with swedish zip and city into city" do
|
17
|
-
let (:city){
|
18
|
-
address = FruitToLime::Address.new
|
19
|
-
line = "114 45 STOCKHOLM"
|
20
|
-
address.parse_zip_and_address_se(line).city
|
21
|
-
}
|
22
|
-
it "should have city equal to 'STOCKHOLM'" do
|
23
|
-
city.should eq 'STOCKHOLM'
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
describe "Parse line with non-swedish zip and city assuming swedish format" do
|
28
|
-
describe "praha example" do
|
29
|
-
let (:parse_result){
|
30
|
-
address = FruitToLime::Address.new
|
31
|
-
line = "CZ-140 00 PRAHA 4"
|
32
|
-
address.parse_zip_and_address_se(line)
|
33
|
-
}
|
34
|
-
it "should be nil" do
|
35
|
-
parse_result.should == nil
|
36
|
-
end
|
37
|
-
end
|
38
|
-
describe "finnish example" do
|
39
|
-
let (:parse_result){
|
40
|
-
address = FruitToLime::Address.new
|
41
|
-
line = "0511 HELSINKI"
|
42
|
-
address.parse_zip_and_address_se(line)
|
43
|
-
}
|
44
|
-
it "should be nil" do
|
45
|
-
parse_result.should == nil
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'fruit_to_lime'
|
3
|
+
|
4
|
+
describe FruitToLime::AddressHelper do
|
5
|
+
describe "Parse line with swedish zip and city into zipcode" do
|
6
|
+
let (:zip_code) {
|
7
|
+
address = FruitToLime::Address.new
|
8
|
+
line = "114 45 STOCKHOLM"
|
9
|
+
address.parse_zip_and_address_se(line).zip_code
|
10
|
+
}
|
11
|
+
it "should have zipcode equal to '114 45'" do
|
12
|
+
zip_code.should eq '114 45'
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
describe "Parse line with swedish zip and city into city" do
|
17
|
+
let (:city){
|
18
|
+
address = FruitToLime::Address.new
|
19
|
+
line = "114 45 STOCKHOLM"
|
20
|
+
address.parse_zip_and_address_se(line).city
|
21
|
+
}
|
22
|
+
it "should have city equal to 'STOCKHOLM'" do
|
23
|
+
city.should eq 'STOCKHOLM'
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
describe "Parse line with non-swedish zip and city assuming swedish format" do
|
28
|
+
describe "praha example" do
|
29
|
+
let (:parse_result){
|
30
|
+
address = FruitToLime::Address.new
|
31
|
+
line = "CZ-140 00 PRAHA 4"
|
32
|
+
address.parse_zip_and_address_se(line)
|
33
|
+
}
|
34
|
+
it "should be nil" do
|
35
|
+
parse_result.should == nil
|
36
|
+
end
|
37
|
+
end
|
38
|
+
describe "finnish example" do
|
39
|
+
let (:parse_result){
|
40
|
+
address = FruitToLime::Address.new
|
41
|
+
line = "0511 HELSINKI"
|
42
|
+
address.parse_zip_and_address_se(line)
|
43
|
+
}
|
44
|
+
it "should be nil" do
|
45
|
+
parse_result.should == nil
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
49
|
end
|
@@ -1,15 +1,15 @@
|
|
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
|
-
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
|
+
end
|
@@ -1,10 +1,10 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'fruit_to_lime'
|
3
|
-
require 'roo'
|
4
|
-
describe FruitToLime::RooHelper do
|
5
|
-
it "should handle sv chars" do
|
6
|
-
samplefile = File.join(File.dirname(__FILE__), '..', 'sample_data', 'excel.xlsx')
|
7
|
-
rows = FruitToLime::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
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'fruit_to_lime'
|
3
|
+
require 'roo'
|
4
|
+
describe FruitToLime::RooHelper do
|
5
|
+
it "should handle sv chars" do
|
6
|
+
samplefile = File.join(File.dirname(__FILE__), '..', 'sample_data', 'excel.xlsx')
|
7
|
+
rows = FruitToLime::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
|
@@ -1,211 +1,211 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'fruit_to_lime'
|
3
|
-
|
4
|
-
describe FruitToLime::SerializeHelper do
|
5
|
-
|
6
|
-
describe "Serialize note" do
|
7
|
-
let(:serialized) {
|
8
|
-
n = FruitToLime::Note.new
|
9
|
-
n.text = "text"
|
10
|
-
FruitToLime::SerializeHelper::serialize(n)
|
11
|
-
}
|
12
|
-
it "should contain text" do
|
13
|
-
serialized.should match(/<Text>text<\/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
|
-
describe "Serialize without data" do
|
23
|
-
let(:serialized) {
|
24
|
-
p = FruitToLime::Person.new
|
25
|
-
FruitToLime::SerializeHelper::serialize(p)
|
26
|
-
}
|
27
|
-
it "should not contain fields that are not set" do
|
28
|
-
#puts serialized
|
29
|
-
serialized.should_not match(/<Email>/)
|
30
|
-
serialized.should_not match(/<Position>/)
|
31
|
-
serialized.should_not match(/<AlternativeEmail>/)
|
32
|
-
serialized.should_not match(/<Tags>/)
|
33
|
-
serialized.should_not match(/<CustomFields>/)
|
34
|
-
end
|
35
|
-
it "should be utf-8" do
|
36
|
-
serialized.encoding.should equal Encoding::UTF_8
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
describe "Serialize person" do
|
41
|
-
let(:serialized) {
|
42
|
-
p = FruitToLime::Person.new
|
43
|
-
p.id = "1"
|
44
|
-
p.first_name = "Kalle"
|
45
|
-
p.last_name = "Anka"
|
46
|
-
p.with_source do |source|
|
47
|
-
source.par_se('122345')
|
48
|
-
end
|
49
|
-
#p.source_ref = {:name=>'Go',:id=>"PASE122345"}
|
50
|
-
p.with_postal_address do |addr|
|
51
|
-
addr.city = "Ankeborg"
|
52
|
-
end
|
53
|
-
p.add_tag("tag:anka")
|
54
|
-
p.add_tag("tag:Bj\u{00F6}rk")
|
55
|
-
p.set_custom_field({:id=>"2", :title=>"cf title", :value=>"cf value"})
|
56
|
-
p.set_custom_field({:id=>"3", :title=>"cf title2", :value=>"cf Bj\u{00F6}rk"})
|
57
|
-
FruitToLime::SerializeHelper::serialize(p)
|
58
|
-
}
|
59
|
-
it "should contain first and last name" do
|
60
|
-
serialized.should match(/<FirstName>Kalle<\/FirstName>/)
|
61
|
-
serialized.should match(/Anka/)
|
62
|
-
end
|
63
|
-
it "should tag name" do
|
64
|
-
serialized.should match(/tag:anka/)
|
65
|
-
end
|
66
|
-
it "should contain address" do
|
67
|
-
serialized.should match(/Ankeborg/)
|
68
|
-
end
|
69
|
-
it "should contain custom field" do
|
70
|
-
serialized.should match(/cf title/)
|
71
|
-
serialized.should match(/cf value/)
|
72
|
-
end
|
73
|
-
it "should contain reference to source" do
|
74
|
-
serialized.should match(/122345/)
|
75
|
-
end
|
76
|
-
it "should handle sv chars in tags" do
|
77
|
-
serialized.should match(/tag:Bj\u{00F6}rk/)
|
78
|
-
end
|
79
|
-
it "should handle sv chars in custom value" do
|
80
|
-
serialized.should match(/cf Bj\u{00F6}rk/)
|
81
|
-
end
|
82
|
-
it "should be utf-8" do
|
83
|
-
serialized.encoding.should equal Encoding::UTF_8
|
84
|
-
end
|
85
|
-
end
|
86
|
-
describe "Serialize organization" do
|
87
|
-
let(:serialized) {
|
88
|
-
o = FruitToLime::Organization.new
|
89
|
-
o.name = "Ankeborgs bibliotek"
|
90
|
-
o.with_source do |source|
|
91
|
-
source.par_se('122345')
|
92
|
-
end
|
93
|
-
#o.source_ref = {:name=>'Go',:id=>"PASE122345"}
|
94
|
-
o.add_tag("tag:bibliotek")
|
95
|
-
o.add_tag("tag:Bj\u{00F6}rk")
|
96
|
-
o.set_custom_field({:id=>"2", :title=>"cf title", :value=>"cf value"})
|
97
|
-
o.set_custom_field({:id=>"3", :title=>"cf title2", :value=>"cf Bj\u{00F6}rk"})
|
98
|
-
o.with_postal_address do |addr|
|
99
|
-
addr.city = "Ankeborg"
|
100
|
-
end
|
101
|
-
o.with_visit_address do |addr|
|
102
|
-
addr.city = "Gaaseborg"
|
103
|
-
end
|
104
|
-
o.add_employee({
|
105
|
-
:id => "1",
|
106
|
-
:first_name => "Kalle",
|
107
|
-
:last_name => "Anka"
|
108
|
-
})
|
109
|
-
FruitToLime::SerializeHelper::serialize(o)
|
110
|
-
}
|
111
|
-
it "should contain name" do
|
112
|
-
serialized.should match(/Ankeborgs bibliotek/)
|
113
|
-
end
|
114
|
-
it "should contain employee" do
|
115
|
-
serialized.should match(/Kalle/)
|
116
|
-
serialized.should match(/Anka/)
|
117
|
-
end
|
118
|
-
it "should contain address" do
|
119
|
-
serialized.should match(/Ankeborg/)
|
120
|
-
serialized.should match(/Gaaseborg/)
|
121
|
-
end
|
122
|
-
it "should tag name" do
|
123
|
-
serialized.should match(/<Tag>tag:bibliotek<\/Tag>/)
|
124
|
-
end
|
125
|
-
it "should contain custom field" do
|
126
|
-
serialized.should match(/cf title/)
|
127
|
-
serialized.should match(/cf value/)
|
128
|
-
#puts serialized
|
129
|
-
end
|
130
|
-
it "should contain reference to source" do
|
131
|
-
serialized.should match(/122345/)
|
132
|
-
end
|
133
|
-
it "should handle sv chars in tags" do
|
134
|
-
serialized.should match(/tag:Bj\u{00F6}rk/)
|
135
|
-
end
|
136
|
-
it "should handle sv chars in custom value" do
|
137
|
-
serialized.should match(/cf Bj\u{00F6}rk/)
|
138
|
-
end
|
139
|
-
it "should be utf-8" do
|
140
|
-
serialized.encoding.should equal Encoding::UTF_8
|
141
|
-
end
|
142
|
-
end
|
143
|
-
|
144
|
-
describe "Serialize goimport" do
|
145
|
-
let(:serialized) {
|
146
|
-
i = FruitToLime::RootModel.new
|
147
|
-
o = FruitToLime::Organization.new
|
148
|
-
o.name = "Ankeborgs bibliotek"
|
149
|
-
i.organizations.push(o)
|
150
|
-
FruitToLime::SerializeHelper::serialize(i)
|
151
|
-
}
|
152
|
-
it "should contain name" do
|
153
|
-
serialized.should match(/Ankeborgs bibliotek/)
|
154
|
-
end
|
155
|
-
it "should be utf-8" do
|
156
|
-
serialized.encoding.should equal Encoding::UTF_8
|
157
|
-
end
|
158
|
-
end
|
159
|
-
describe "Get import rows" do
|
160
|
-
describe "for person" do
|
161
|
-
let(:import_rows) { FruitToLime::Person.new.get_import_rows }
|
162
|
-
it "should contain integration id" do
|
163
|
-
import_rows.should include({:id=>'integration_id', :name=>'Integration id', :type=>:string})
|
164
|
-
import_rows.should include({:id=>'id', :name=>'Go id', :type=>:string})
|
165
|
-
end
|
166
|
-
it "should contain address" do
|
167
|
-
expected = {:id=>'postal_address', :name=>'Postal address', :type=>:address,
|
168
|
-
:model=>[
|
169
|
-
{:id=>'street',:name=>'Street', :type=>:string},
|
170
|
-
{:id=>'zip_code',:name=>'Zip code', :type=>:string},
|
171
|
-
{:id=>'city',:name=>'City', :type=>:string},
|
172
|
-
{:id=>'country_code',:name=>'Country code', :type=>:string},
|
173
|
-
{:id=>'location',:name=>'Location', :type=>:string},
|
174
|
-
{:id=>'country_name',:name=>'Country name', :type=>:string},
|
175
|
-
]}
|
176
|
-
import_rows.should include(expected)
|
177
|
-
end
|
178
|
-
it "should contain organization" do
|
179
|
-
import_rows.should include({
|
180
|
-
:id=>'organization',
|
181
|
-
:name=>'Organization',
|
182
|
-
:type=>:organization_reference,
|
183
|
-
:model=>[
|
184
|
-
{:id=>'id', :name=>'Go id', :type=>:string},
|
185
|
-
{:id=>'integration_id', :name=>'Integration id', :type=>:string},
|
186
|
-
{:id=>'heading', :name=>'Heading', :type=>:string}
|
187
|
-
]
|
188
|
-
})
|
189
|
-
end
|
190
|
-
end
|
191
|
-
describe "for organization" do
|
192
|
-
let(:import_rows) { FruitToLime::Organization.new.get_import_rows }
|
193
|
-
it "should contain integration id" do
|
194
|
-
import_rows.should include({:id=>'integration_id', :name=>'Integration id', :type=>:string})
|
195
|
-
import_rows.should include({:id=>'id', :name=>'Go id', :type=>:string})
|
196
|
-
end
|
197
|
-
it "should contain address" do
|
198
|
-
expected = {:id=>'postal_address', :name=>'Postal address', :type=>:address,
|
199
|
-
:model=>[
|
200
|
-
{:id=>'street',:name=>'Street', :type=>:string},
|
201
|
-
{:id=>'zip_code',:name=>'Zip code', :type=>:string},
|
202
|
-
{:id=>'city',:name=>'City', :type=>:string},
|
203
|
-
{:id=>'country_code',:name=>'Country code', :type=>:string},
|
204
|
-
{:id=>'location',:name=>'Location', :type=>:string},
|
205
|
-
{:id=>'country_name',:name=>'Country name', :type=>:string},
|
206
|
-
]}
|
207
|
-
import_rows.should include(expected)
|
208
|
-
end
|
209
|
-
end
|
210
|
-
end
|
211
|
-
end
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'fruit_to_lime'
|
3
|
+
|
4
|
+
describe FruitToLime::SerializeHelper do
|
5
|
+
|
6
|
+
describe "Serialize note" do
|
7
|
+
let(:serialized) {
|
8
|
+
n = FruitToLime::Note.new
|
9
|
+
n.text = "text"
|
10
|
+
FruitToLime::SerializeHelper::serialize(n)
|
11
|
+
}
|
12
|
+
it "should contain text" do
|
13
|
+
serialized.should match(/<Text>text<\/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
|
+
describe "Serialize without data" do
|
23
|
+
let(:serialized) {
|
24
|
+
p = FruitToLime::Person.new
|
25
|
+
FruitToLime::SerializeHelper::serialize(p)
|
26
|
+
}
|
27
|
+
it "should not contain fields that are not set" do
|
28
|
+
#puts serialized
|
29
|
+
serialized.should_not match(/<Email>/)
|
30
|
+
serialized.should_not match(/<Position>/)
|
31
|
+
serialized.should_not match(/<AlternativeEmail>/)
|
32
|
+
serialized.should_not match(/<Tags>/)
|
33
|
+
serialized.should_not match(/<CustomFields>/)
|
34
|
+
end
|
35
|
+
it "should be utf-8" do
|
36
|
+
serialized.encoding.should equal Encoding::UTF_8
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
describe "Serialize person" do
|
41
|
+
let(:serialized) {
|
42
|
+
p = FruitToLime::Person.new
|
43
|
+
p.id = "1"
|
44
|
+
p.first_name = "Kalle"
|
45
|
+
p.last_name = "Anka"
|
46
|
+
p.with_source do |source|
|
47
|
+
source.par_se('122345')
|
48
|
+
end
|
49
|
+
#p.source_ref = {:name=>'Go',:id=>"PASE122345"}
|
50
|
+
p.with_postal_address do |addr|
|
51
|
+
addr.city = "Ankeborg"
|
52
|
+
end
|
53
|
+
p.add_tag("tag:anka")
|
54
|
+
p.add_tag("tag:Bj\u{00F6}rk")
|
55
|
+
p.set_custom_field({:id=>"2", :title=>"cf title", :value=>"cf value"})
|
56
|
+
p.set_custom_field({:id=>"3", :title=>"cf title2", :value=>"cf Bj\u{00F6}rk"})
|
57
|
+
FruitToLime::SerializeHelper::serialize(p)
|
58
|
+
}
|
59
|
+
it "should contain first and last name" do
|
60
|
+
serialized.should match(/<FirstName>Kalle<\/FirstName>/)
|
61
|
+
serialized.should match(/Anka/)
|
62
|
+
end
|
63
|
+
it "should tag name" do
|
64
|
+
serialized.should match(/tag:anka/)
|
65
|
+
end
|
66
|
+
it "should contain address" do
|
67
|
+
serialized.should match(/Ankeborg/)
|
68
|
+
end
|
69
|
+
it "should contain custom field" do
|
70
|
+
serialized.should match(/cf title/)
|
71
|
+
serialized.should match(/cf value/)
|
72
|
+
end
|
73
|
+
it "should contain reference to source" do
|
74
|
+
serialized.should match(/122345/)
|
75
|
+
end
|
76
|
+
it "should handle sv chars in tags" do
|
77
|
+
serialized.should match(/tag:Bj\u{00F6}rk/)
|
78
|
+
end
|
79
|
+
it "should handle sv chars in custom value" do
|
80
|
+
serialized.should match(/cf Bj\u{00F6}rk/)
|
81
|
+
end
|
82
|
+
it "should be utf-8" do
|
83
|
+
serialized.encoding.should equal Encoding::UTF_8
|
84
|
+
end
|
85
|
+
end
|
86
|
+
describe "Serialize organization" do
|
87
|
+
let(:serialized) {
|
88
|
+
o = FruitToLime::Organization.new
|
89
|
+
o.name = "Ankeborgs bibliotek"
|
90
|
+
o.with_source do |source|
|
91
|
+
source.par_se('122345')
|
92
|
+
end
|
93
|
+
#o.source_ref = {:name=>'Go',:id=>"PASE122345"}
|
94
|
+
o.add_tag("tag:bibliotek")
|
95
|
+
o.add_tag("tag:Bj\u{00F6}rk")
|
96
|
+
o.set_custom_field({:id=>"2", :title=>"cf title", :value=>"cf value"})
|
97
|
+
o.set_custom_field({:id=>"3", :title=>"cf title2", :value=>"cf Bj\u{00F6}rk"})
|
98
|
+
o.with_postal_address do |addr|
|
99
|
+
addr.city = "Ankeborg"
|
100
|
+
end
|
101
|
+
o.with_visit_address do |addr|
|
102
|
+
addr.city = "Gaaseborg"
|
103
|
+
end
|
104
|
+
o.add_employee({
|
105
|
+
:id => "1",
|
106
|
+
:first_name => "Kalle",
|
107
|
+
:last_name => "Anka"
|
108
|
+
})
|
109
|
+
FruitToLime::SerializeHelper::serialize(o)
|
110
|
+
}
|
111
|
+
it "should contain name" do
|
112
|
+
serialized.should match(/Ankeborgs bibliotek/)
|
113
|
+
end
|
114
|
+
it "should contain employee" do
|
115
|
+
serialized.should match(/Kalle/)
|
116
|
+
serialized.should match(/Anka/)
|
117
|
+
end
|
118
|
+
it "should contain address" do
|
119
|
+
serialized.should match(/Ankeborg/)
|
120
|
+
serialized.should match(/Gaaseborg/)
|
121
|
+
end
|
122
|
+
it "should tag name" do
|
123
|
+
serialized.should match(/<Tag>tag:bibliotek<\/Tag>/)
|
124
|
+
end
|
125
|
+
it "should contain custom field" do
|
126
|
+
serialized.should match(/cf title/)
|
127
|
+
serialized.should match(/cf value/)
|
128
|
+
#puts serialized
|
129
|
+
end
|
130
|
+
it "should contain reference to source" do
|
131
|
+
serialized.should match(/122345/)
|
132
|
+
end
|
133
|
+
it "should handle sv chars in tags" do
|
134
|
+
serialized.should match(/tag:Bj\u{00F6}rk/)
|
135
|
+
end
|
136
|
+
it "should handle sv chars in custom value" do
|
137
|
+
serialized.should match(/cf Bj\u{00F6}rk/)
|
138
|
+
end
|
139
|
+
it "should be utf-8" do
|
140
|
+
serialized.encoding.should equal Encoding::UTF_8
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
describe "Serialize goimport" do
|
145
|
+
let(:serialized) {
|
146
|
+
i = FruitToLime::RootModel.new
|
147
|
+
o = FruitToLime::Organization.new
|
148
|
+
o.name = "Ankeborgs bibliotek"
|
149
|
+
i.organizations.push(o)
|
150
|
+
FruitToLime::SerializeHelper::serialize(i)
|
151
|
+
}
|
152
|
+
it "should contain name" do
|
153
|
+
serialized.should match(/Ankeborgs bibliotek/)
|
154
|
+
end
|
155
|
+
it "should be utf-8" do
|
156
|
+
serialized.encoding.should equal Encoding::UTF_8
|
157
|
+
end
|
158
|
+
end
|
159
|
+
describe "Get import rows" do
|
160
|
+
describe "for person" do
|
161
|
+
let(:import_rows) { FruitToLime::Person.new.get_import_rows }
|
162
|
+
it "should contain integration id" do
|
163
|
+
import_rows.should include({:id=>'integration_id', :name=>'Integration id', :type=>:string})
|
164
|
+
import_rows.should include({:id=>'id', :name=>'Go id', :type=>:string})
|
165
|
+
end
|
166
|
+
it "should contain address" do
|
167
|
+
expected = {:id=>'postal_address', :name=>'Postal address', :type=>:address,
|
168
|
+
:model=>[
|
169
|
+
{:id=>'street',:name=>'Street', :type=>:string},
|
170
|
+
{:id=>'zip_code',:name=>'Zip code', :type=>:string},
|
171
|
+
{:id=>'city',:name=>'City', :type=>:string},
|
172
|
+
{:id=>'country_code',:name=>'Country code', :type=>:string},
|
173
|
+
{:id=>'location',:name=>'Location', :type=>:string},
|
174
|
+
{:id=>'country_name',:name=>'Country name', :type=>:string},
|
175
|
+
]}
|
176
|
+
import_rows.should include(expected)
|
177
|
+
end
|
178
|
+
it "should contain organization" do
|
179
|
+
import_rows.should include({
|
180
|
+
:id=>'organization',
|
181
|
+
:name=>'Organization',
|
182
|
+
:type=>:organization_reference,
|
183
|
+
:model=>[
|
184
|
+
{:id=>'id', :name=>'Go id', :type=>:string},
|
185
|
+
{:id=>'integration_id', :name=>'Integration id', :type=>:string},
|
186
|
+
{:id=>'heading', :name=>'Heading', :type=>:string}
|
187
|
+
]
|
188
|
+
})
|
189
|
+
end
|
190
|
+
end
|
191
|
+
describe "for organization" do
|
192
|
+
let(:import_rows) { FruitToLime::Organization.new.get_import_rows }
|
193
|
+
it "should contain integration id" do
|
194
|
+
import_rows.should include({:id=>'integration_id', :name=>'Integration id', :type=>:string})
|
195
|
+
import_rows.should include({:id=>'id', :name=>'Go id', :type=>:string})
|
196
|
+
end
|
197
|
+
it "should contain address" do
|
198
|
+
expected = {:id=>'postal_address', :name=>'Postal address', :type=>:address,
|
199
|
+
:model=>[
|
200
|
+
{:id=>'street',:name=>'Street', :type=>:string},
|
201
|
+
{:id=>'zip_code',:name=>'Zip code', :type=>:string},
|
202
|
+
{:id=>'city',:name=>'City', :type=>:string},
|
203
|
+
{:id=>'country_code',:name=>'Country code', :type=>:string},
|
204
|
+
{:id=>'location',:name=>'Location', :type=>:string},
|
205
|
+
{:id=>'country_name',:name=>'Country name', :type=>:string},
|
206
|
+
]}
|
207
|
+
import_rows.should include(expected)
|
208
|
+
end
|
209
|
+
end
|
210
|
+
end
|
211
|
+
end
|