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.
- 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 -141
- data/lib/fruit_to_lime/model/deal_status.rb +12 -12
- data/lib/fruit_to_lime/model/note.rb +80 -79
- data/lib/fruit_to_lime/model/organization.rb +203 -203
- 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 +342 -338
- 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 -101
- 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 -98
- data/spec/organization_spec.rb +103 -103
- data/spec/person_spec.rb +134 -134
- data/spec/rootmodel_spec.rb +306 -277
- 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 -5
- data/templates/easy/Rakefile.rb +7 -7
- data/templates/easy/convert.rb +2 -2
- data/templates/easy/spec/exporter_spec.rb +10 -10
- data/templates/easy/spec/spec_helper.rb +24 -24
- data/templates/excel/lib/tomodel.rb +207 -207
- data/templates/sqlserver/lib/tomodel.rb +79 -79
- 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
|
+
|
data/spec/rootmodel_spec.rb
CHANGED
@@ -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
|
123
|
-
# given
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
rootmodel.
|
130
|
-
|
131
|
-
#
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
end
|
150
|
-
|
151
|
-
it "
|
152
|
-
# given
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
rootmodel.
|
159
|
-
|
160
|
-
# then
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
rootmodel.
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
#
|
226
|
-
found_person
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
rootmodel.
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
org2
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
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
|