fruit_to_lime 2.5.5 → 2.5.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (55) hide show
  1. data/lib/fruit_to_lime.rb +17 -17
  2. data/lib/fruit_to_lime/csv_helper.rb +47 -47
  3. data/lib/fruit_to_lime/email_helper.rb +10 -10
  4. data/lib/fruit_to_lime/errors.rb +16 -16
  5. data/lib/fruit_to_lime/excel_helper.rb +10 -10
  6. data/lib/fruit_to_lime/global_phone.json +6571 -6571
  7. data/lib/fruit_to_lime/model/address.rb +60 -60
  8. data/lib/fruit_to_lime/model/class_settings.rb +50 -50
  9. data/lib/fruit_to_lime/model/coworker.rb +76 -76
  10. data/lib/fruit_to_lime/model/coworker_reference.rb +33 -33
  11. data/lib/fruit_to_lime/model/customfield.rb +87 -87
  12. data/lib/fruit_to_lime/model/deal.rb +141 -141
  13. data/lib/fruit_to_lime/model/deal_status.rb +12 -12
  14. data/lib/fruit_to_lime/model/note.rb +80 -79
  15. data/lib/fruit_to_lime/model/organization.rb +203 -203
  16. data/lib/fruit_to_lime/model/person.rb +151 -151
  17. data/lib/fruit_to_lime/model/referencetosource.rb +45 -45
  18. data/lib/fruit_to_lime/model/relation.rb +23 -23
  19. data/lib/fruit_to_lime/model/rootmodel.rb +342 -338
  20. data/lib/fruit_to_lime/model/settings.rb +60 -60
  21. data/lib/fruit_to_lime/model/tag.rb +35 -35
  22. data/lib/fruit_to_lime/model_helpers.rb +54 -54
  23. data/lib/fruit_to_lime/phone_helper.rb +74 -74
  24. data/lib/fruit_to_lime/roo_helper.rb +72 -72
  25. data/lib/fruit_to_lime/serialize_helper.rb +186 -186
  26. data/lib/fruit_to_lime/templating.rb +52 -52
  27. data/spec/address_spec.rb +48 -48
  28. data/spec/class_settings_spec.rb +37 -37
  29. data/spec/coworker_spec.rb +94 -94
  30. data/spec/custom_field_spec.rb +22 -22
  31. data/spec/deal_spec.rb +101 -101
  32. data/spec/helpers/csv_helper_spec.rb +29 -29
  33. data/spec/helpers/email_helper_spec.rb +32 -32
  34. data/spec/helpers/phone_helper_spec.rb +97 -97
  35. data/spec/helpers/serialize_helper_spec.rb +249 -249
  36. data/spec/helpers/xsd_validate_spec.rb +58 -58
  37. data/spec/note_spec.rb +98 -98
  38. data/spec/organization_spec.rb +103 -103
  39. data/spec/person_spec.rb +134 -134
  40. data/spec/rootmodel_spec.rb +306 -277
  41. data/spec/templating_spec.rb +11 -11
  42. data/templates/csv/lib/tomodel.rb +230 -230
  43. data/templates/csv/spec/exporter_spec.rb +17 -17
  44. data/templates/csv/spec/sample_data/coworkers.csv +2 -2
  45. data/templates/csv/spec/sample_data/deals.csv +2 -2
  46. data/templates/csv/spec/sample_data/organizations.csv +2 -2
  47. data/templates/csv/spec/sample_data/persons.csv +2 -2
  48. data/templates/easy/Gemfile +5 -5
  49. data/templates/easy/Rakefile.rb +7 -7
  50. data/templates/easy/convert.rb +2 -2
  51. data/templates/easy/spec/exporter_spec.rb +10 -10
  52. data/templates/easy/spec/spec_helper.rb +24 -24
  53. data/templates/excel/lib/tomodel.rb +207 -207
  54. data/templates/sqlserver/lib/tomodel.rb +79 -79
  55. metadata +3 -3
data/spec/person_spec.rb CHANGED
@@ -1,134 +1,134 @@
1
- require "spec_helper"
2
- require 'fruit_to_lime'
3
-
4
- describe "Person" do
5
- let(:person) {
6
- FruitToLime::Person.new
7
- }
8
-
9
- it "can set a customfield" do
10
- person.set_custom_field({:integration_id=>'the key',
11
- :value=> 'the value'})
12
-
13
- value = person.custom_values[0]
14
- field = value.field
15
- field.integration_id.should eq 'the key'
16
- value.value.should eq 'the value'
17
- end
18
-
19
- it "will set custom field with same integration_id to the last value" do
20
- person.set_custom_field({:integration_id=>'the key',
21
- :value=> 'the value'})
22
-
23
- person.set_custom_field({:integration_id=>'the key',
24
- :value=> 'the value 2'})
25
- value = person.custom_values[0]
26
- field = value.field
27
-
28
- person.custom_values.length.should eq 1
29
- field.integration_id.should eq 'the key'
30
- value.value.should eq 'the value 2'
31
- end
32
-
33
- it "will set custom field with same id to the last value" do
34
- person.set_custom_field({:id=>'the id',
35
- :value=> 'the value'})
36
-
37
- person.set_custom_field({:id=>'the id',
38
- :value=> 'the value 2'})
39
- value = person.custom_values[0]
40
- field = value.field
41
-
42
- person.custom_values.length.should eq 1
43
- field.id.should eq 'the id'
44
- value.value.should eq 'the value 2'
45
- end
46
-
47
- it "will set custom field (using set_custom_value) with same integration_id to the last value" do
48
- person.set_custom_value('the id','the value')
49
-
50
- person.set_custom_value('the id','the value 2')
51
- value = person.custom_values[0]
52
- field = value.field
53
-
54
- person.custom_values.length.should eq 1
55
- field.integration_id.should eq 'the id'
56
- value.value.should eq 'the value 2'
57
- end
58
-
59
- it "will only set tag once" do
60
- person.set_tag('tag1')
61
- person.set_tag('tag1')
62
- person.tags.length.should eq 1
63
- tag = person.tags[0]
64
- tag.value.should eq 'tag1'
65
- end
66
-
67
- it "should have a firstname if no lastname" do
68
- person.first_name = "Vincent"
69
- person.last_name = nil
70
-
71
- error = person.validate
72
- error.should be_empty
73
- end
74
-
75
- it "should be currently employed if nothing specified" do
76
- expect(person.currently_employed).to eq(true)
77
- end
78
-
79
- it "should have a lastname if no firstname" do
80
- person.first_name = String.new
81
- person.last_name = "Vega"
82
-
83
- error = person.validate
84
- error.should be_empty
85
- end
86
-
87
- it "shouldnt pass validation with no firstname and lastname" do
88
- person.first_name = String.new
89
- person.last_name = nil
90
-
91
- error = person.validate
92
- error.should start_with("A firstname or lastname is required for person")
93
- end
94
-
95
- it "should auto convert org to org.ref during assignment" do
96
- # given
97
- org = FruitToLime::Organization.new({:integration_id => "123", :name => "Lundalogik"})
98
-
99
- # when
100
- person.organization = org
101
-
102
- # then
103
- person.organization.is_a?(FruitToLime::OrganizationReference).should eq true
104
- end
105
-
106
- describe "parse_name_to_firstname_lastname_se" do
107
- it "can parse 'Kalle Nilsson' into firstname 'Kalle' and lastname 'Nilsson'" do
108
- person.parse_name_to_firstname_lastname_se 'Kalle Nilsson'
109
-
110
- person.first_name.should eq 'Kalle'
111
- person.last_name.should eq 'Nilsson'
112
- end
113
-
114
- it "can parse 'Kalle Svensson Nilsson' into firstname 'Kalle' and lastname 'Svensson Nilsson'" do
115
- person.parse_name_to_firstname_lastname_se 'Kalle Svensson Nilsson'
116
-
117
- person.first_name.should eq 'Kalle'
118
- person.last_name.should eq 'Svensson Nilsson'
119
- end
120
-
121
- it "sets default name when name is empty" do
122
- person.parse_name_to_firstname_lastname_se '', 'a default'
123
-
124
- person.first_name.should eq 'a default'
125
- end
126
-
127
- it "sets default name when name is nil" do
128
- person.parse_name_to_firstname_lastname_se nil, 'a default'
129
-
130
- person.first_name.should eq 'a default'
131
- end
132
- end
133
- end
134
-
1
+ require "spec_helper"
2
+ require 'fruit_to_lime'
3
+
4
+ describe "Person" do
5
+ let(:person) {
6
+ FruitToLime::Person.new
7
+ }
8
+
9
+ it "can set a customfield" do
10
+ person.set_custom_field({:integration_id=>'the key',
11
+ :value=> 'the value'})
12
+
13
+ value = person.custom_values[0]
14
+ field = value.field
15
+ field.integration_id.should eq 'the key'
16
+ value.value.should eq 'the value'
17
+ end
18
+
19
+ it "will set custom field with same integration_id to the last value" do
20
+ person.set_custom_field({:integration_id=>'the key',
21
+ :value=> 'the value'})
22
+
23
+ person.set_custom_field({:integration_id=>'the key',
24
+ :value=> 'the value 2'})
25
+ value = person.custom_values[0]
26
+ field = value.field
27
+
28
+ person.custom_values.length.should eq 1
29
+ field.integration_id.should eq 'the key'
30
+ value.value.should eq 'the value 2'
31
+ end
32
+
33
+ it "will set custom field with same id to the last value" do
34
+ person.set_custom_field({:id=>'the id',
35
+ :value=> 'the value'})
36
+
37
+ person.set_custom_field({:id=>'the id',
38
+ :value=> 'the value 2'})
39
+ value = person.custom_values[0]
40
+ field = value.field
41
+
42
+ person.custom_values.length.should eq 1
43
+ field.id.should eq 'the id'
44
+ value.value.should eq 'the value 2'
45
+ end
46
+
47
+ it "will set custom field (using set_custom_value) with same integration_id to the last value" do
48
+ person.set_custom_value('the id','the value')
49
+
50
+ person.set_custom_value('the id','the value 2')
51
+ value = person.custom_values[0]
52
+ field = value.field
53
+
54
+ person.custom_values.length.should eq 1
55
+ field.integration_id.should eq 'the id'
56
+ value.value.should eq 'the value 2'
57
+ end
58
+
59
+ it "will only set tag once" do
60
+ person.set_tag('tag1')
61
+ person.set_tag('tag1')
62
+ person.tags.length.should eq 1
63
+ tag = person.tags[0]
64
+ tag.value.should eq 'tag1'
65
+ end
66
+
67
+ it "should have a firstname if no lastname" do
68
+ person.first_name = "Vincent"
69
+ person.last_name = nil
70
+
71
+ error = person.validate
72
+ error.should be_empty
73
+ end
74
+
75
+ it "should be currently employed if nothing specified" do
76
+ expect(person.currently_employed).to eq(true)
77
+ end
78
+
79
+ it "should have a lastname if no firstname" do
80
+ person.first_name = String.new
81
+ person.last_name = "Vega"
82
+
83
+ error = person.validate
84
+ error.should be_empty
85
+ end
86
+
87
+ it "shouldnt pass validation with no firstname and lastname" do
88
+ person.first_name = String.new
89
+ person.last_name = nil
90
+
91
+ error = person.validate
92
+ error.should start_with("A firstname or lastname is required for person")
93
+ end
94
+
95
+ it "should auto convert org to org.ref during assignment" do
96
+ # given
97
+ org = FruitToLime::Organization.new({:integration_id => "123", :name => "Lundalogik"})
98
+
99
+ # when
100
+ person.organization = org
101
+
102
+ # then
103
+ person.organization.is_a?(FruitToLime::OrganizationReference).should eq true
104
+ end
105
+
106
+ describe "parse_name_to_firstname_lastname_se" do
107
+ it "can parse 'Kalle Nilsson' into firstname 'Kalle' and lastname 'Nilsson'" do
108
+ person.parse_name_to_firstname_lastname_se 'Kalle Nilsson'
109
+
110
+ person.first_name.should eq 'Kalle'
111
+ person.last_name.should eq 'Nilsson'
112
+ end
113
+
114
+ it "can parse 'Kalle Svensson Nilsson' into firstname 'Kalle' and lastname 'Svensson Nilsson'" do
115
+ person.parse_name_to_firstname_lastname_se 'Kalle Svensson Nilsson'
116
+
117
+ person.first_name.should eq 'Kalle'
118
+ person.last_name.should eq 'Svensson Nilsson'
119
+ end
120
+
121
+ it "sets default name when name is empty" do
122
+ person.parse_name_to_firstname_lastname_se '', 'a default'
123
+
124
+ person.first_name.should eq 'a default'
125
+ end
126
+
127
+ it "sets default name when name is nil" do
128
+ person.parse_name_to_firstname_lastname_se nil, 'a default'
129
+
130
+ person.first_name.should eq 'a default'
131
+ end
132
+ end
133
+ end
134
+
@@ -1,277 +1,306 @@
1
- require "spec_helper"
2
- require 'fruit_to_lime'
3
-
4
- describe "RootModel" do
5
- let(:rootmodel) {
6
- FruitToLime::RootModel.new
7
- }
8
-
9
- it "will contain integration coworker by default" do
10
- rootmodel.find_coworker_by_integration_id("import").first_name.should eq "Import"
11
- rootmodel.coworkers.length.should eq 1
12
- end
13
-
14
- it "can add a coworker from a hash" do
15
- rootmodel.add_coworker({
16
- :integration_id => "123key",
17
- :first_name => "Kalle",
18
- :last_name => "Anka",
19
- :email => "kalle.anka@vonanka.com"
20
- })
21
- rootmodel.find_coworker_by_integration_id("123key").first_name.should eq "Kalle"
22
- rootmodel.coworkers.length.should eq 2
23
- end
24
-
25
- it "can add a coworker from a new coworker" do
26
- coworker = FruitToLime::Coworker.new
27
- coworker.integration_id = "123key"
28
- coworker.first_name="Kalle"
29
- coworker.last_name="Anka"
30
- coworker.email = "kalle.anka@vonanka.com"
31
- rootmodel.add_coworker(coworker)
32
- rootmodel.find_coworker_by_integration_id("123key").first_name.should eq "Kalle"
33
- rootmodel.coworkers.length.should eq 2
34
- end
35
-
36
- it "will not add a new coworker when the coworker is already added (same integration id)" do
37
- rootmodel.add_coworker({
38
- :integration_id=>"123key",
39
- :first_name=>"Kalle",
40
- :last_name=>"Anka",
41
- :email=>"kalle.anka@vonanka.com"
42
- })
43
- rootmodel.coworkers.length.should eq 2
44
- expect {
45
- rootmodel.add_coworker({
46
- :integration_id=>"123key",
47
- :first_name=>"Knatte",
48
- :last_name=>"Anka",
49
- :email=>"knatte.anka@vonanka.com"
50
- })
51
- }.to raise_error(FruitToLime::AlreadyAddedError)
52
- rootmodel.find_coworker_by_integration_id("123key").first_name.should eq "Kalle"
53
- rootmodel.coworkers.length.should eq 2
54
- end
55
-
56
- it "can add an organization from hash" do
57
- rootmodel.add_organization({
58
- :integration_id => "123key",
59
- :name => "Beagle Boys"
60
- })
61
- rootmodel.find_organization_by_integration_id("123key").name.should eq "Beagle Boys"
62
- rootmodel.organizations.length.should eq 1
63
- end
64
-
65
- it "can add an organization from a new organization" do
66
- # given
67
- organization = FruitToLime::Organization.new
68
- organization.integration_id = "123key"
69
- organization.name = "Beagle Boys"
70
-
71
- # when
72
- rootmodel.add_organization(organization)
73
-
74
- # then
75
- rootmodel.find_organization_by_integration_id("123key").name.should eq "Beagle Boys"
76
- rootmodel.organizations.length.should eq 1
77
- end
78
-
79
- it "will not add a new organizations when the organizations is already added (same integration id)" do
80
- # given
81
- rootmodel.add_organization({
82
- :integration_id => "123key",
83
- :name => "Beagle Boys"
84
- })
85
- rootmodel.organizations.length.should eq 1
86
- rootmodel.find_organization_by_integration_id("123key").name.should eq "Beagle Boys"
87
-
88
- # when, then
89
- expect {
90
- rootmodel.add_organization({
91
- :integration_id => "123key",
92
- :name => "Beagle Boys 2"
93
- })
94
- }.to raise_error(FruitToLime::AlreadyAddedError)
95
- rootmodel.find_organization_by_integration_id("123key").name.should eq "Beagle Boys"
96
- rootmodel.organizations.length.should eq 1
97
- end
98
-
99
- it "can add a deal from hash" do
100
- rootmodel.add_deal({
101
- :integration_id => "123key",
102
- :name => "Big deal"
103
- })
104
- rootmodel.find_deal_by_integration_id("123key").name.should eq "Big deal"
105
- rootmodel.deals.length.should eq 1
106
- end
107
-
108
- it "can add a deal from a new deal" do
109
- # given
110
- deal = FruitToLime::Deal.new
111
- deal.integration_id = "123key"
112
- deal.name = "Big deal"
113
-
114
- # when
115
- rootmodel.add_deal(deal)
116
-
117
- # then
118
- rootmodel.find_deal_by_integration_id("123key").name.should eq "Big deal"
119
- rootmodel.deals.length.should eq 1
120
- end
121
-
122
- it "will not add a new deal when the deal is already added (same integration id)" do
123
- # given
124
- rootmodel.add_deal({
125
- :integration_id => "123key",
126
- :name => "Big deal"
127
- })
128
- rootmodel.deals.length.should eq 1
129
- rootmodel.find_deal_by_integration_id("123key").name.should eq "Big deal"
130
-
131
- # when, then
132
- expect {
133
- rootmodel.add_deal({
134
- :integration_id => "123key",
135
- :name => "Bigger deal"
136
- })
137
- }.to raise_error(FruitToLime::AlreadyAddedError)
138
- rootmodel.find_deal_by_integration_id("123key").name.should eq "Big deal"
139
- rootmodel.deals.length.should eq 1
140
- end
141
-
142
- it "can add a note from hash" do
143
- rootmodel.add_note({
144
- :integration_id => "123key",
145
- :text => "This is a note"
146
- })
147
- rootmodel.find_note_by_integration_id("123key").text.should eq "This is a note"
148
- rootmodel.notes.length.should eq 1
149
- end
150
-
151
- it "can add a note from a new note" do
152
- # given
153
- note = FruitToLime::Note.new
154
- note.integration_id = "123key"
155
- note.text = "This is a note"
156
-
157
- # when
158
- rootmodel.add_note(note)
159
-
160
- # then
161
- rootmodel.find_note_by_integration_id("123key").text.should eq "This is a note"
162
- rootmodel.notes.length.should eq 1
163
- end
164
-
165
- it "will not add a new organizations when the organizations is already added (same integration id)" do
166
- # given
167
- rootmodel.add_note({
168
- :integration_id => "123key",
169
- :text => "This is a note"
170
- })
171
- rootmodel.notes.length.should eq 1
172
-
173
- # when, then
174
- expect {
175
- rootmodel.add_note({
176
- :integration_id => "123key",
177
- :text => "This is another note"
178
- })
179
- }.to raise_error(FruitToLime::AlreadyAddedError)
180
- rootmodel.notes.length.should eq 1
181
- rootmodel.find_note_by_integration_id("123key").text.should eq "This is a note"
182
- end
183
-
184
- it "Will find a person by integration id" do
185
- # given
186
- organization = FruitToLime::Organization.new
187
- organization.name = "Hubba Bubba"
188
- organization.add_employee({
189
- :integration_id => "123",
190
- :first_name => "Billy",
191
- :last_name => "Bob"
192
- })
193
-
194
- rootmodel.add_organization(organization)
195
-
196
- # when
197
- found_person = rootmodel.find_person_by_integration_id("123")
198
-
199
- # then
200
- found_person.integration_id.should eq "123"
201
- found_person.first_name.should eq "Billy"
202
- found_person.last_name.should eq "Bob"
203
- end
204
-
205
- it "Will find a person by integration id from an organization with many employees" do
206
- # given
207
- organization = FruitToLime::Organization.new
208
- organization.name = "Hubba Bubba"
209
- organization.add_employee({
210
- :integration_id => "123",
211
- :first_name => "Billy",
212
- :last_name => "Bob"
213
- })
214
- organization.add_employee({
215
- :integration_id => "456",
216
- :first_name => "Vincent",
217
- :last_name => "Vega"
218
- })
219
-
220
- rootmodel.add_organization(organization)
221
-
222
- # when
223
- found_person = rootmodel.find_person_by_integration_id("123")
224
-
225
- # then
226
- found_person.integration_id.should eq "123"
227
- found_person.first_name.should eq "Billy"
228
- found_person.last_name.should eq "Bob"
229
- end
230
-
231
- it "will ignore empty integration ids during sanity check" do
232
- org1 = FruitToLime::Organization.new
233
- org1.name = "company 1"
234
- rootmodel.organizations.push org1
235
-
236
- org2 = FruitToLime::Organization.new
237
- org2.name = "company 2"
238
- rootmodel.organizations.push org2
239
-
240
- rootmodel.sanity_check.should eq ""
241
- end
242
-
243
- it "will report when the same integration id is used during sanity check" do
244
- org1 = FruitToLime::Organization.new
245
- org1.integration_id = "1"
246
- org1.name = "company 1"
247
- rootmodel.organizations.push org1
248
-
249
- org2 = FruitToLime::Organization.new
250
- org2.integration_id = "1"
251
- org2.name = "company 2"
252
- rootmodel.organizations.push org2
253
-
254
- rootmodel.sanity_check.should eq "Duplicate organization integration_id: 1."
255
- end
256
-
257
- it "will report when the same integrationid on person is used during sanity check" do
258
- org1 = FruitToLime::Organization.new
259
- org1.integration_id = "1"
260
- org1.name = "company 1"
261
- person1 = FruitToLime::Person.new
262
- person1.integration_id = '1'
263
- org1.add_employee person1
264
-
265
- rootmodel.organizations.push org1
266
-
267
- org2 = FruitToLime::Organization.new
268
- org2.integration_id = "2"
269
- org2.name = "company 2"
270
- person2 = FruitToLime::Person.new
271
- person2.integration_id = '1'
272
- org2.add_employee person2
273
- rootmodel.organizations.push org2
274
-
275
- rootmodel.sanity_check.should eq "Duplicate person integration_id: 1."
276
- end
277
- end
1
+ require "spec_helper"
2
+ require 'fruit_to_lime'
3
+
4
+ describe "RootModel" do
5
+ let(:rootmodel) {
6
+ FruitToLime::RootModel.new
7
+ }
8
+
9
+ it "will contain integration coworker by default" do
10
+ rootmodel.find_coworker_by_integration_id("import").first_name.should eq "Import"
11
+ rootmodel.coworkers.length.should eq 1
12
+ end
13
+
14
+ it "can add a coworker from a hash" do
15
+ rootmodel.add_coworker({
16
+ :integration_id => "123key",
17
+ :first_name => "Kalle",
18
+ :last_name => "Anka",
19
+ :email => "kalle.anka@vonanka.com"
20
+ })
21
+ rootmodel.find_coworker_by_integration_id("123key").first_name.should eq "Kalle"
22
+ rootmodel.coworkers.length.should eq 2
23
+ end
24
+
25
+ it "can add a coworker from a new coworker" do
26
+ coworker = FruitToLime::Coworker.new
27
+ coworker.integration_id = "123key"
28
+ coworker.first_name="Kalle"
29
+ coworker.last_name="Anka"
30
+ coworker.email = "kalle.anka@vonanka.com"
31
+ rootmodel.add_coworker(coworker)
32
+ rootmodel.find_coworker_by_integration_id("123key").first_name.should eq "Kalle"
33
+ rootmodel.coworkers.length.should eq 2
34
+ end
35
+
36
+ it "will not add a new coworker when the coworker is already added (same integration id)" do
37
+ rootmodel.add_coworker({
38
+ :integration_id=>"123key",
39
+ :first_name=>"Kalle",
40
+ :last_name=>"Anka",
41
+ :email=>"kalle.anka@vonanka.com"
42
+ })
43
+ rootmodel.coworkers.length.should eq 2
44
+ expect {
45
+ rootmodel.add_coworker({
46
+ :integration_id=>"123key",
47
+ :first_name=>"Knatte",
48
+ :last_name=>"Anka",
49
+ :email=>"knatte.anka@vonanka.com"
50
+ })
51
+ }.to raise_error(FruitToLime::AlreadyAddedError)
52
+ rootmodel.find_coworker_by_integration_id("123key").first_name.should eq "Kalle"
53
+ rootmodel.coworkers.length.should eq 2
54
+ end
55
+
56
+ it "can add an organization from hash" do
57
+ rootmodel.add_organization({
58
+ :integration_id => "123key",
59
+ :name => "Beagle Boys"
60
+ })
61
+ rootmodel.find_organization_by_integration_id("123key").name.should eq "Beagle Boys"
62
+ rootmodel.organizations.length.should eq 1
63
+ end
64
+
65
+ it "can add an organization from a new organization" do
66
+ # given
67
+ organization = FruitToLime::Organization.new
68
+ organization.integration_id = "123key"
69
+ organization.name = "Beagle Boys"
70
+
71
+ # when
72
+ rootmodel.add_organization(organization)
73
+
74
+ # then
75
+ rootmodel.find_organization_by_integration_id("123key").name.should eq "Beagle Boys"
76
+ rootmodel.organizations.length.should eq 1
77
+ end
78
+
79
+ it "will not add a new organizations when the organizations is already added (same integration id)" do
80
+ # given
81
+ rootmodel.add_organization({
82
+ :integration_id => "123key",
83
+ :name => "Beagle Boys"
84
+ })
85
+ rootmodel.organizations.length.should eq 1
86
+ rootmodel.find_organization_by_integration_id("123key").name.should eq "Beagle Boys"
87
+
88
+ # when, then
89
+ expect {
90
+ rootmodel.add_organization({
91
+ :integration_id => "123key",
92
+ :name => "Beagle Boys 2"
93
+ })
94
+ }.to raise_error(FruitToLime::AlreadyAddedError)
95
+ rootmodel.find_organization_by_integration_id("123key").name.should eq "Beagle Boys"
96
+ rootmodel.organizations.length.should eq 1
97
+ end
98
+
99
+ it "can add a deal from hash" do
100
+ rootmodel.add_deal({
101
+ :integration_id => "123key",
102
+ :name => "Big deal"
103
+ })
104
+ rootmodel.find_deal_by_integration_id("123key").name.should eq "Big deal"
105
+ rootmodel.deals.length.should eq 1
106
+ end
107
+
108
+ it "can add a deal from a new deal" do
109
+ # given
110
+ deal = FruitToLime::Deal.new
111
+ deal.integration_id = "123key"
112
+ deal.name = "Big deal"
113
+
114
+ # when
115
+ rootmodel.add_deal(deal)
116
+
117
+ # then
118
+ rootmodel.find_deal_by_integration_id("123key").name.should eq "Big deal"
119
+ rootmodel.deals.length.should eq 1
120
+ end
121
+
122
+ it "will set reponsible coworker to import_coworker if none specifed" do
123
+ # given
124
+ deal = FruitToLime::Deal.new
125
+ deal.integration_id = "123key"
126
+ deal.name = "Big deal"
127
+
128
+ # when
129
+ rootmodel.add_deal(deal)
130
+
131
+ # then
132
+ deal.responsible_coworker.integration_id.should eq rootmodel.import_coworker.integration_id
133
+ end
134
+
135
+ it "will not set reponsible coworker to import_coworker if specifed" do
136
+ # given
137
+ deal = FruitToLime::Deal.new
138
+ deal.integration_id = "123key"
139
+ deal.name = "Big deal"
140
+ coworker = FruitToLime::Coworker.new
141
+ coworker.integration_id = "123"
142
+ deal.responsible_coworker = coworker
143
+
144
+ # when
145
+ rootmodel.add_deal(deal)
146
+
147
+ # then
148
+ deal.responsible_coworker.integration_id.should eq coworker.integration_id
149
+ end
150
+
151
+ it "will not add a new deal when the deal is already added (same integration id)" do
152
+ # given
153
+ rootmodel.add_deal({
154
+ :integration_id => "123key",
155
+ :name => "Big deal"
156
+ })
157
+ rootmodel.deals.length.should eq 1
158
+ rootmodel.find_deal_by_integration_id("123key").name.should eq "Big deal"
159
+
160
+ # when, then
161
+ expect {
162
+ rootmodel.add_deal({
163
+ :integration_id => "123key",
164
+ :name => "Bigger deal"
165
+ })
166
+ }.to raise_error(FruitToLime::AlreadyAddedError)
167
+ rootmodel.find_deal_by_integration_id("123key").name.should eq "Big deal"
168
+ rootmodel.deals.length.should eq 1
169
+ end
170
+
171
+ it "can add a note from hash" do
172
+ rootmodel.add_note({
173
+ :integration_id => "123key",
174
+ :text => "This is a note"
175
+ })
176
+ rootmodel.find_note_by_integration_id("123key").text.should eq "This is a note"
177
+ rootmodel.notes.length.should eq 1
178
+ end
179
+
180
+ it "can add a note from a new note" do
181
+ # given
182
+ note = FruitToLime::Note.new
183
+ note.integration_id = "123key"
184
+ note.text = "This is a note"
185
+
186
+ # when
187
+ rootmodel.add_note(note)
188
+
189
+ # then
190
+ rootmodel.find_note_by_integration_id("123key").text.should eq "This is a note"
191
+ rootmodel.notes.length.should eq 1
192
+ end
193
+
194
+ it "will not add a new organizations when the organizations is already added (same integration id)" do
195
+ # given
196
+ rootmodel.add_note({
197
+ :integration_id => "123key",
198
+ :text => "This is a note"
199
+ })
200
+ rootmodel.notes.length.should eq 1
201
+
202
+ # when, then
203
+ expect {
204
+ rootmodel.add_note({
205
+ :integration_id => "123key",
206
+ :text => "This is another note"
207
+ })
208
+ }.to raise_error(FruitToLime::AlreadyAddedError)
209
+ rootmodel.notes.length.should eq 1
210
+ rootmodel.find_note_by_integration_id("123key").text.should eq "This is a note"
211
+ end
212
+
213
+ it "Will find a person by integration id" do
214
+ # given
215
+ organization = FruitToLime::Organization.new
216
+ organization.name = "Hubba Bubba"
217
+ organization.add_employee({
218
+ :integration_id => "123",
219
+ :first_name => "Billy",
220
+ :last_name => "Bob"
221
+ })
222
+
223
+ rootmodel.add_organization(organization)
224
+
225
+ # when
226
+ found_person = rootmodel.find_person_by_integration_id("123")
227
+
228
+ # then
229
+ found_person.integration_id.should eq "123"
230
+ found_person.first_name.should eq "Billy"
231
+ found_person.last_name.should eq "Bob"
232
+ end
233
+
234
+ it "Will find a person by integration id from an organization with many employees" do
235
+ # given
236
+ organization = FruitToLime::Organization.new
237
+ organization.name = "Hubba Bubba"
238
+ organization.add_employee({
239
+ :integration_id => "123",
240
+ :first_name => "Billy",
241
+ :last_name => "Bob"
242
+ })
243
+ organization.add_employee({
244
+ :integration_id => "456",
245
+ :first_name => "Vincent",
246
+ :last_name => "Vega"
247
+ })
248
+
249
+ rootmodel.add_organization(organization)
250
+
251
+ # when
252
+ found_person = rootmodel.find_person_by_integration_id("123")
253
+
254
+ # then
255
+ found_person.integration_id.should eq "123"
256
+ found_person.first_name.should eq "Billy"
257
+ found_person.last_name.should eq "Bob"
258
+ end
259
+
260
+ it "will ignore empty integration ids during sanity check" do
261
+ org1 = FruitToLime::Organization.new
262
+ org1.name = "company 1"
263
+ rootmodel.organizations.push org1
264
+
265
+ org2 = FruitToLime::Organization.new
266
+ org2.name = "company 2"
267
+ rootmodel.organizations.push org2
268
+
269
+ rootmodel.sanity_check.should eq ""
270
+ end
271
+
272
+ it "will report when the same integration id is used during sanity check" do
273
+ org1 = FruitToLime::Organization.new
274
+ org1.integration_id = "1"
275
+ org1.name = "company 1"
276
+ rootmodel.organizations.push org1
277
+
278
+ org2 = FruitToLime::Organization.new
279
+ org2.integration_id = "1"
280
+ org2.name = "company 2"
281
+ rootmodel.organizations.push org2
282
+
283
+ rootmodel.sanity_check.should eq "Duplicate organization integration_id: 1."
284
+ end
285
+
286
+ it "will report when the same integrationid on person is used during sanity check" do
287
+ org1 = FruitToLime::Organization.new
288
+ org1.integration_id = "1"
289
+ org1.name = "company 1"
290
+ person1 = FruitToLime::Person.new
291
+ person1.integration_id = '1'
292
+ org1.add_employee person1
293
+
294
+ rootmodel.organizations.push org1
295
+
296
+ org2 = FruitToLime::Organization.new
297
+ org2.integration_id = "2"
298
+ org2.name = "company 2"
299
+ person2 = FruitToLime::Person.new
300
+ person2.integration_id = '1'
301
+ org2.add_employee person2
302
+ rootmodel.organizations.push org2
303
+
304
+ rootmodel.sanity_check.should eq "Duplicate person integration_id: 1."
305
+ end
306
+ end