move-to-go 5.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (138) hide show
  1. checksums.yaml +7 -0
  2. data/bin/move-to-go +210 -0
  3. data/lib/move-to-go/can_become_immutable.rb +29 -0
  4. data/lib/move-to-go/csv_helper.rb +47 -0
  5. data/lib/move-to-go/email_helper.rb +14 -0
  6. data/lib/move-to-go/errors.rb +31 -0
  7. data/lib/move-to-go/excel_helper.rb +10 -0
  8. data/lib/move-to-go/global_phone.json +6571 -0
  9. data/lib/move-to-go/model/address.rb +63 -0
  10. data/lib/move-to-go/model/class_settings.rb +50 -0
  11. data/lib/move-to-go/model/clientvisit.rb +10 -0
  12. data/lib/move-to-go/model/comment.rb +10 -0
  13. data/lib/move-to-go/model/coworker.rb +82 -0
  14. data/lib/move-to-go/model/coworker_reference.rb +33 -0
  15. data/lib/move-to-go/model/customfield.rb +87 -0
  16. data/lib/move-to-go/model/deal.rb +216 -0
  17. data/lib/move-to-go/model/deal_class_settings.rb +97 -0
  18. data/lib/move-to-go/model/deal_state.rb +15 -0
  19. data/lib/move-to-go/model/deal_status.rb +23 -0
  20. data/lib/move-to-go/model/deal_status_reference.rb +47 -0
  21. data/lib/move-to-go/model/deal_status_setting.rb +49 -0
  22. data/lib/move-to-go/model/documents.rb +76 -0
  23. data/lib/move-to-go/model/file.rb +193 -0
  24. data/lib/move-to-go/model/history.rb +148 -0
  25. data/lib/move-to-go/model/history_classification.rb +26 -0
  26. data/lib/move-to-go/model/link.rb +82 -0
  27. data/lib/move-to-go/model/organization.rb +250 -0
  28. data/lib/move-to-go/model/person.rb +164 -0
  29. data/lib/move-to-go/model/referencetosource.rb +58 -0
  30. data/lib/move-to-go/model/relation.rb +23 -0
  31. data/lib/move-to-go/model/rootmodel.rb +663 -0
  32. data/lib/move-to-go/model/salescall.rb +10 -0
  33. data/lib/move-to-go/model/settings.rb +61 -0
  34. data/lib/move-to-go/model/tag.rb +35 -0
  35. data/lib/move-to-go/model/talkedto.rb +10 -0
  36. data/lib/move-to-go/model/triedtoreach.rb +10 -0
  37. data/lib/move-to-go/model_helpers.rb +97 -0
  38. data/lib/move-to-go/phone_helper.rb +75 -0
  39. data/lib/move-to-go/roo_helper.rb +82 -0
  40. data/lib/move-to-go/serialize_helper.rb +199 -0
  41. data/lib/move-to-go/shard_helper.rb +96 -0
  42. data/lib/move-to-go/source.rb +108 -0
  43. data/lib/move-to-go/templating.rb +52 -0
  44. data/lib/move-to-go.rb +20 -0
  45. data/sources/VISMA/.gitignore +14 -0
  46. data/sources/VISMA/.move-to-go/readme.txt +1 -0
  47. data/sources/VISMA/.move-to-go/runner.rb +89 -0
  48. data/sources/VISMA/Database/KONTAKT.DBF +0 -0
  49. data/sources/VISMA/Database/KUND.DBF +0 -0
  50. data/sources/VISMA/Gemfile +5 -0
  51. data/sources/VISMA/converter.rb +120 -0
  52. data/sources/base-crm/.move-to-go/runner.rb +235 -0
  53. data/sources/base-crm/Gemfile +5 -0
  54. data/sources/base-crm/README.md +9 -0
  55. data/sources/base-crm/converter.rb +56 -0
  56. data/sources/base-crm/data/contacts.csv +13 -0
  57. data/sources/base-crm/data/coworkers.csv +3 -0
  58. data/sources/base-crm/data/deals.csv +5 -0
  59. data/sources/base-crm/data/histories.csv +6 -0
  60. data/sources/base-crm/data/leads.csv +4 -0
  61. data/sources/base-crm/data/tasks.csv +5 -0
  62. data/sources/csv/.gitignore +14 -0
  63. data/sources/csv/.move-to-go/readme.txt +1 -0
  64. data/sources/csv/.move-to-go/runner.rb +65 -0
  65. data/sources/csv/Gemfile +5 -0
  66. data/sources/csv/converter.rb +218 -0
  67. data/sources/csv/data/coworkers.csv +2 -0
  68. data/sources/csv/data/deals.csv +2 -0
  69. data/sources/csv/data/organizations.csv +2 -0
  70. data/sources/csv/data/persons.csv +2 -0
  71. data/sources/custom/.gitignore +14 -0
  72. data/sources/custom/.move-to-go/readme.txt +1 -0
  73. data/sources/custom/.move-to-go/runner.rb +30 -0
  74. data/sources/custom/Gemfile +4 -0
  75. data/sources/custom/converter.rb +45 -0
  76. data/sources/excel/.gitignore +14 -0
  77. data/sources/excel/.move-to-go/readme.txt +3 -0
  78. data/sources/excel/.move-to-go/runner.rb +140 -0
  79. data/sources/excel/Gemfile +7 -0
  80. data/sources/excel/converter.rb +188 -0
  81. data/sources/excel/files/avtal.docx +0 -0
  82. data/sources/excel/files/more/avtal.docx +0 -0
  83. data/sources/excel/files/more/offert-2.pdf +0 -0
  84. data/sources/excel/files/offert-2.docx +0 -0
  85. data/sources/excel/files/offert.docx +0 -0
  86. data/sources/excel/sample-data.xlsx +0 -0
  87. data/sources/excel-basic/.gitignore +14 -0
  88. data/sources/excel-basic/.move-to-go/readme.txt +3 -0
  89. data/sources/excel-basic/.move-to-go/runner.rb +139 -0
  90. data/sources/excel-basic/Exempelfil.xlsx +0 -0
  91. data/sources/excel-basic/Gemfile +6 -0
  92. data/sources/excel-basic/converter.rb +175 -0
  93. data/sources/excel-basic/files/avtal.docx +0 -0
  94. data/sources/excel-basic/files/more/avtal.docx +0 -0
  95. data/sources/excel-basic/files/more/offert-2.pdf +0 -0
  96. data/sources/excel-basic/files/offert-2.docx +0 -0
  97. data/sources/excel-basic/files/offert.docx +0 -0
  98. data/sources/lime-crm-basic/.gitignore +14 -0
  99. data/sources/lime-crm-basic/.move-to-go/readme.txt +1 -0
  100. data/sources/lime-crm-basic/.move-to-go/runner.rb +524 -0
  101. data/sources/lime-crm-basic/Gemfile +6 -0
  102. data/sources/lime-crm-basic/converter.rb +396 -0
  103. data/sources/lime-easy/.gitignore +14 -0
  104. data/sources/lime-easy/.move-to-go/readme.txt +1 -0
  105. data/sources/lime-easy/.move-to-go/runner.rb +348 -0
  106. data/sources/lime-easy/Export/readme.txt +6 -0
  107. data/sources/lime-easy/Gemfile +5 -0
  108. data/sources/lime-easy/converter.rb +362 -0
  109. data/sources/salesforce/.gitignore +14 -0
  110. data/sources/salesforce/.move-to-go/readme.txt +1 -0
  111. data/sources/salesforce/.move-to-go/runner.rb +404 -0
  112. data/sources/salesforce/Gemfile +6 -0
  113. data/sources/salesforce/Gemfile.lock +48 -0
  114. data/sources/salesforce/converter.rb +113 -0
  115. data/sources/salesforce/export/readme.txt +3 -0
  116. data/spec/address_spec.rb +49 -0
  117. data/spec/class_settings_spec.rb +37 -0
  118. data/spec/coworker_spec.rb +94 -0
  119. data/spec/custom_field_spec.rb +22 -0
  120. data/spec/deal_class_settings_spec.rb +116 -0
  121. data/spec/deal_spec.rb +232 -0
  122. data/spec/deal_status_reference_spec.rb +17 -0
  123. data/spec/documents_spec.rb +64 -0
  124. data/spec/file_spec.rb +178 -0
  125. data/spec/helpers/csv_helper_spec.rb +45 -0
  126. data/spec/helpers/email_helper_spec.rb +37 -0
  127. data/spec/helpers/phone_helper_spec.rb +119 -0
  128. data/spec/helpers/roo_helper_spec.rb +10 -0
  129. data/spec/helpers/serialize_helper_spec.rb +253 -0
  130. data/spec/helpers/shard_helper_spec.rb +141 -0
  131. data/spec/helpers/xsd_validate_spec.rb +57 -0
  132. data/spec/history_spec.rb +150 -0
  133. data/spec/link_spec.rb +107 -0
  134. data/spec/organization_spec.rb +221 -0
  135. data/spec/person_spec.rb +129 -0
  136. data/spec/rootmodel_spec.rb +993 -0
  137. data/spec/spec_helper.rb +30 -0
  138. metadata +362 -0
@@ -0,0 +1,141 @@
1
+ require 'spec_helper'
2
+ require 'move-to-go'
3
+
4
+ describe MoveToGo::ShardHelper do
5
+ it "should shard 50 objects of a single type into two shards" do
6
+ # given
7
+ model = MoveToGo::RootModel.new
8
+
9
+ (1..50).each do |n|
10
+ organization = MoveToGo::Organization.new
11
+ organization.name = "Ankeborgs bibliotek"
12
+ organization.integration_id = n.to_s
13
+ model.add_organization(organization)
14
+ end
15
+
16
+ sharder = MoveToGo::ShardHelper.new(25)
17
+
18
+ # when, the
19
+ sharder.shard_model(model).length.should eq 2
20
+ end
21
+
22
+ it "should shard 60 objects of different type into three shards" do
23
+ # given
24
+ model = MoveToGo::RootModel.new
25
+
26
+ (1..10).each do |n|
27
+ organization = MoveToGo::Organization.new
28
+ organization.name = "Ankeborgs bibliotek"
29
+ organization.integration_id = n.to_s
30
+
31
+ person = MoveToGo::Person.new
32
+ person.first_name = "Kalle"
33
+ person.last_name = "Kula"
34
+ organization.add_employee(person)
35
+
36
+ person = MoveToGo::Person.new
37
+ person.first_name = "Nisse"
38
+ person.last_name = "Nice"
39
+ organization.add_employee(person)
40
+
41
+ model.add_organization(organization)
42
+ end
43
+
44
+ (1..10).each do |n|
45
+ deal = MoveToGo::Deal.new
46
+ deal.name = "Big deal"
47
+ deal.integration_id = n.to_s
48
+ model.add_deal(deal)
49
+ end
50
+
51
+ (1..10).each do |n|
52
+ comment = MoveToGo::Comment.new
53
+ comment.text = "Important comment"
54
+ model.add_comment(comment)
55
+ end
56
+
57
+ (1..10).each do |n|
58
+ link = MoveToGo::Link.new
59
+ link.url = "https://go.lime-go.com"
60
+ link.name = "Our url"
61
+ model.add_link(link)
62
+ end
63
+
64
+ sharder = MoveToGo::ShardHelper.new(20)
65
+
66
+ # when, then
67
+ sharder.shard_model(model).length.should eq 3
68
+ end
69
+
70
+ it "should be able to change the shard size" do
71
+ # given
72
+ model = MoveToGo::RootModel.new
73
+
74
+ (1..20).each do |n|
75
+ organization = MoveToGo::Organization.new
76
+ organization.name = "Ankeborgs bibliotek"
77
+ organization.integration_id = n.to_s
78
+ model.add_organization(organization)
79
+ end
80
+
81
+ sharder = MoveToGo::ShardHelper.new(5)
82
+
83
+ # when, then
84
+ sharder.shard_model(model).length.should eq 4
85
+ end
86
+
87
+ it "should add an organization into a shard" do
88
+ # given
89
+
90
+ model = MoveToGo::RootModel.new
91
+
92
+ organization = MoveToGo::Organization.new
93
+ organization.name = "Ankeborgs bibliotek"
94
+ organization.integration_id = "123"
95
+
96
+ sharder = MoveToGo::ShardHelper.new()
97
+ model.add_organization(organization)
98
+
99
+ # when, then
100
+ sharder.shard_model(model)[0].find_organization_by_integration_id("123").should eq organization
101
+ end
102
+
103
+ it "should add a deal into a shard" do
104
+ # given
105
+
106
+ model = MoveToGo::RootModel.new
107
+
108
+ deal = MoveToGo::Deal.new
109
+ deal.name = "Big deal"
110
+ deal.integration_id = "123"
111
+
112
+ sharder = MoveToGo::ShardHelper.new()
113
+ model.add_deal(deal)
114
+
115
+ # when, then
116
+ sharder.shard_model(model)[0].find_deal_by_integration_id("123").should eq deal
117
+ end
118
+
119
+ it "should keep the settings into a shard" do
120
+ # given
121
+
122
+ model = MoveToGo::RootModel.new
123
+
124
+ model.settings.with_organization do |organization|
125
+ organization.set_custom_field( { :integrationid => 'external_url', :title => 'Link to external system', :type => :Link } )
126
+ end
127
+
128
+ model.settings.with_deal do |deal|
129
+ deal.add_status({:label => "Prospecting", :integration_id => "prospect"})
130
+ deal.add_status({:label => "Qualified", :integration_id => "qualification"})
131
+ deal.add_status({:label => "Won", :integration_id => "won", :assessment => MoveToGo::DealState::PositiveEndState })
132
+ deal.add_status({:label => "Lost", :integration_id => "Lost", :assessment => MoveToGo::DealState::NegativeEndState })
133
+ end
134
+
135
+ sharder = MoveToGo::ShardHelper.new()
136
+
137
+ # when, then
138
+ sharder.shard_model(model)[0].settings.should eq model.settings
139
+ end
140
+
141
+ end
@@ -0,0 +1,57 @@
1
+ require 'spec_helper'
2
+ require 'move-to-go'
3
+ require 'nokogiri'
4
+ describe MoveToGo::SerializeHelper do
5
+ describe "Validate according to xsd" do
6
+ let(:validate_result) {
7
+ rootmodel = MoveToGo::RootModel.new
8
+ rootmodel.settings.with_organization do |s|
9
+ s.set_custom_field({:integration_id => "2", :title => "cf title"})
10
+ s.set_custom_field({:integration_id => "3", :title => "cf title2"})
11
+ end
12
+ coworker = MoveToGo::Coworker.new({
13
+ :integration_id => "123",
14
+ :first_name => "Kalle",
15
+ :last_name => "Anka",
16
+ :email => "kalle.anka@vonanka.com"
17
+ })
18
+ rootmodel.add_coworker(coworker)
19
+ organization = MoveToGo::Organization.new
20
+ organization.name = "Ankeborgs bibliotek"
21
+ organization.with_source do |source|
22
+ source.par_se('122345')
23
+ end
24
+ #organization.source_ref = {:name => 'Go',:id => "PASE122345"}
25
+ organization.set_tag("tag:bibliotek")
26
+ organization.set_tag("tag:Bj\u{00F6}rk")
27
+ organization.set_custom_value("2", "cf value")
28
+ organization.set_custom_value("3", "cf Bj\u{00F6}rk")
29
+ organization.integration_id = "313"
30
+ organization.with_postal_address do |addr|
31
+ addr.city = "Ankeborg"
32
+ end
33
+ organization.with_visit_address do |addr|
34
+ addr.city = "Gaaseborg"
35
+ end
36
+ coworker = MoveToGo::Coworker.new({:integration_id => "1", :first_name => "Vincent", :last_name => "Vega"})
37
+ organization.responsible_coworker = coworker
38
+
39
+ emp = MoveToGo::Person.new
40
+ emp.integration_id = "1"
41
+ emp.first_name = "Kalle"
42
+ emp.last_name = "Anka"
43
+ emp.direct_phone_number = '234234234'
44
+ emp.currently_employed = true
45
+ rootmodel.add_organization organization
46
+ xsd_file = File.join(File.dirname(__FILE__), '..', 'sample_data', 'schema0.xsd')
47
+
48
+ xsd = Nokogiri::XML::Schema(File.read(xsd_file))
49
+ doc = Nokogiri::XML(MoveToGo::SerializeHelper::serialize(rootmodel, -1))
50
+ xsd.validate(doc)
51
+ }
52
+
53
+ it "Should not contain validation errors" do
54
+ expect(validate_result).to eq([])
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,150 @@
1
+ require "spec_helper"
2
+ require 'move-to-go'
3
+
4
+ describe "History" do
5
+ let("history") {
6
+ MoveToGo::History.new
7
+ }
8
+
9
+ it "must have a text" do
10
+ history.validate.length.should be > 0
11
+ end
12
+
13
+ it "is valid when it has text, created_by and organization" do
14
+ # given
15
+ history.text = "They are very interested in the new deal (the one where you get a free bike as a gift)"
16
+ history.created_by = MoveToGo::Coworker.new( { :integration_id => "123", :heading => "kalle anka" } )
17
+ history.organization = MoveToGo::Organization.new({ :integration_id => "456", :heading => "Lundalogik" })
18
+
19
+ # when, then
20
+ history.validate.should eq ""
21
+ end
22
+
23
+ it "is valid when it has text, created_by and person" do
24
+ # given
25
+ history.text = "They are very interested in the new deal (the one where you get a free bike as a gift)"
26
+ history.created_by = MoveToGo::Coworker.new( { :integration_id => "123", :heading => "kalle anka" } )
27
+ history.person = MoveToGo::Person.new({ :integration_id => "456", :heading => "Billy Bob" })
28
+
29
+ # when, then
30
+ history.validate.should eq ""
31
+ end
32
+
33
+ it "is valid when it has text, created_by and deal" do
34
+ # given
35
+ history.text = "They are very interested in the new deal (the one where you get a free bike as a gift)"
36
+ history.created_by = MoveToGo::Coworker.new( { :integration_id => "123", :heading => "kalle anka" } )
37
+ history.deal = MoveToGo::Deal.new({ :integration_id => "456", :heading => "The new deal" })
38
+
39
+ # when, then
40
+ history.validate.should eq ""
41
+ end
42
+
43
+ it "is invalid if no history has no attached objects" do
44
+ # given
45
+ history.text = "They are very interested in the new deal (the one where you get a free bike as a gift)"
46
+ history.created_by = MoveToGo::Coworker.new( { :integration_id => "123", :heading => "kalle anka" } )
47
+
48
+ # when, then
49
+ history.validate.length.should be > 0
50
+ end
51
+
52
+ it "will set organization ref when organization is assigned" do
53
+ # given
54
+ org = MoveToGo::Organization.new({:integration_id => "123", :name => "Beagle Boys!"})
55
+
56
+ # when
57
+ history.organization = org
58
+
59
+ # then
60
+ history.organization.is_a?(MoveToGo::Organization).should eq true
61
+ history.instance_variable_get(:@organization_reference).is_a?(MoveToGo::OrganizationReference).should eq true
62
+ end
63
+
64
+ it "will set person ref when person is assigned" do
65
+ # given
66
+ person = MoveToGo::Person.new({:integration_id => "123" })
67
+ person.parse_name_to_firstname_lastname_se "Billy Bob"
68
+
69
+ # when
70
+ history.person = person
71
+
72
+ # then
73
+ history.person.is_a?(MoveToGo::Person).should eq true
74
+ history.instance_variable_get(:@person_reference).is_a?(MoveToGo::PersonReference).should eq true
75
+ end
76
+
77
+ it "will set coworker ref when coworker is assigned" do
78
+ # given
79
+ coworker = MoveToGo::Coworker.new({:integration_id => "123" })
80
+ coworker.parse_name_to_firstname_lastname_se "Billy Bob"
81
+
82
+ # when
83
+ history.created_by = coworker
84
+
85
+ # then
86
+ history.created_by.is_a?(MoveToGo::Coworker).should eq true
87
+ history.instance_variable_get(:@created_by_reference).is_a?(MoveToGo::CoworkerReference).should eq true
88
+ end
89
+
90
+ it "will set deal ref when deal is assigned" do
91
+ # given
92
+ deal = MoveToGo::Deal.new({:integration_id => "123" })
93
+ deal.name = "The new deal"
94
+
95
+ # when
96
+ history.deal = deal
97
+
98
+ # then
99
+ history.deal.is_a?(MoveToGo::Deal).should eq true
100
+ history.instance_variable_get(:@deal_reference).is_a?(MoveToGo::DealReference).should eq true
101
+ end
102
+
103
+ it "should have Comment as default classification" do
104
+ # then
105
+ history.classification.should eq MoveToGo::HistoryClassification::Comment
106
+ end
107
+
108
+ it "should not accept invalid classifications" do
109
+ # when, then
110
+ expect {
111
+ history.classification = "hubbabubba"
112
+ }.to raise_error(MoveToGo::InvalidHistoryClassificationError)
113
+ end
114
+
115
+ it "should remove form feed from text" do
116
+ # given
117
+ textWithFormFeed = "Text with form feed"
118
+ textWithoutFormFeed = "Text with form feed"
119
+
120
+ # when
121
+ history.text = textWithFormFeed
122
+
123
+ # then
124
+ history.text.should eq textWithoutFormFeed
125
+ end
126
+
127
+ it "should remove vertical tab from text" do
128
+ # given
129
+ textWithVerticalTab = "Text with \vvertical tab"
130
+ textWithoutVerticalTab = "Text with vertical tab"
131
+
132
+ # when
133
+ history.text = textWithVerticalTab
134
+
135
+ # then
136
+ history.text.should eq textWithoutVerticalTab
137
+ end
138
+
139
+ it "should remove backspace from text" do
140
+ # given
141
+ textWithBackSpace = "Text with \bbackspace"
142
+ textWithoutBackSpace = "Text with backspace"
143
+
144
+ # when
145
+ history.text = textWithBackSpace
146
+
147
+ # then
148
+ history.text.should eq textWithoutBackSpace
149
+ end
150
+ end
data/spec/link_spec.rb ADDED
@@ -0,0 +1,107 @@
1
+ require "spec_helper"
2
+ require 'move-to-go'
3
+
4
+ describe "Link" do
5
+ let("link") {
6
+ MoveToGo::Link.new
7
+ }
8
+
9
+ it "is valid when it has url, created_by and organization" do
10
+ # given
11
+ link.url = "http://dropbox.com/"
12
+ link.created_by = MoveToGo::CoworkerReference.new( { :integration_id => "123", :heading => "billy bob" } )
13
+ link.organization = MoveToGo::OrganizationReference.new({ :integration_id => "456", :heading => "Lundalogik" })
14
+
15
+ # when, then
16
+ link.validate.should eq ""
17
+ end
18
+
19
+ it "is valid when it has url, created_by and deal" do
20
+ # given
21
+ link.url = "http://dropbox.com/"
22
+ link.created_by = MoveToGo::CoworkerReference.new( { :integration_id => "123", :heading => "billy bob" } )
23
+ link.deal = MoveToGo::DealReference.new({ :integration_id => "456", :heading => "The new deal" })
24
+
25
+ # when, then
26
+ link.validate.should eq ""
27
+ end
28
+
29
+ it "is not valid when it has url and deal" do
30
+ # must have a created_by
31
+ # given
32
+ link.url = "http://dropbox.com/"
33
+ link.deal = MoveToGo::DealReference.new({ :integration_id => "456", :heading => "The new deal" })
34
+
35
+ # when, then
36
+ link.validate.length.should be > 0
37
+ end
38
+
39
+ it "is not valid when it has url and created_by" do
40
+ # must have an deal or organization
41
+ # given
42
+ link.url = "http://dropbox.com/"
43
+ link.created_by = MoveToGo::CoworkerReference.new( { :integration_id => "123", :heading => "billy bob" } )
44
+
45
+ # when, then
46
+ link.validate.length.should be > 0
47
+ end
48
+
49
+ it "is not valid when it has deal and created_by" do
50
+ # must have an url
51
+ # given
52
+ link.created_by = MoveToGo::CoworkerReference.new( { :integration_id => "123", :heading => "billy bob" } )
53
+ link.deal = MoveToGo::DealReference.new({ :integration_id => "456", :heading => "The new deal" })
54
+
55
+ # when, then
56
+ link.validate.length.should be > 0
57
+ end
58
+
59
+ it "is not valid when it has url, created_by, deal and orgaization" do
60
+ # given
61
+ link.url = "http://dropbox.com/"
62
+ link.created_by = MoveToGo::CoworkerReference.new( { :integration_id => "123", :heading => "billy bob" } )
63
+ link.deal = MoveToGo::DealReference.new({ :integration_id => "456", :heading => "The new deal" })
64
+ link.organization = MoveToGo::OrganizationReference.new({ :integration_id => "456", :heading => "Lundalogik" })
65
+
66
+ # when, then
67
+ link.validate.length.should be > 0
68
+ end
69
+
70
+ it "will set organization ref when organization is assigned" do
71
+ # given
72
+ org = MoveToGo::Organization.new({:integration_id => "123", :name => "Beagle Boys!"})
73
+
74
+ # when
75
+ link.organization = org
76
+
77
+ # then
78
+ link.organization.is_a?(MoveToGo::Organization).should eq true
79
+ link.instance_variable_get(:@organization_reference).is_a?(MoveToGo::OrganizationReference).should eq true
80
+ end
81
+
82
+ it "will set deal ref when deal is assigned" do
83
+ # given
84
+ deal = MoveToGo::Deal.new({:integration_id => "123" })
85
+ deal.name = "The new deal"
86
+
87
+ # when
88
+ link.deal = deal
89
+
90
+ # then
91
+ link.deal.is_a?(MoveToGo::Deal).should eq true
92
+ link.instance_variable_get(:@deal_reference).is_a?(MoveToGo::DealReference).should eq true
93
+ end
94
+
95
+ it "will set coworker ref when coworker is assigned" do
96
+ # given
97
+ coworker = MoveToGo::Coworker.new({:integration_id => "123" })
98
+ coworker.parse_name_to_firstname_lastname_se "Billy Bob"
99
+
100
+ # when
101
+ link.created_by = coworker
102
+
103
+ # then
104
+ link.created_by.is_a?(MoveToGo::Coworker).should eq true
105
+ link.instance_variable_get(:@created_by_reference).is_a?(MoveToGo::CoworkerReference).should eq true
106
+ end
107
+ end
@@ -0,0 +1,221 @@
1
+ require "spec_helper"
2
+ require 'move-to-go'
3
+
4
+ describe "Organization" do
5
+ let(:organization) {
6
+ MoveToGo::Organization.new
7
+ }
8
+
9
+ it "should have import tag as default" do
10
+ # given, when, then
11
+ organization.tags.count.should eq 1
12
+ organization.tags[0].value.should eq 'Import'
13
+ end
14
+
15
+ it "should not accept empty tags" do
16
+ # given
17
+ organization.tags.count.should eq 1
18
+
19
+ # when
20
+ organization.set_tag ""
21
+
22
+ # then
23
+ organization.tags.count.should eq 1
24
+ end
25
+
26
+ it "should not accept nil tags" do
27
+ # given
28
+ organization.tags.count.should eq 1
29
+
30
+ # when
31
+ organization.set_tag ""
32
+
33
+ # then
34
+ organization.tags.count.should eq 1
35
+ end
36
+
37
+ it "should not accept objects as tags" do
38
+ # given
39
+ organization.tags.count.should eq 1
40
+
41
+ # when
42
+ not_a_tag = {}
43
+ not_a_tag[:text] = 'this is not a tag'
44
+ organization.set_tag not_a_tag
45
+
46
+ # then
47
+ organization.tags.count.should eq 1
48
+ end
49
+
50
+
51
+ it "must have a name" do
52
+ # given, when
53
+ organization.name = "Lundalogik"
54
+
55
+ # then
56
+ organization.validate.should eq ""
57
+ end
58
+
59
+ it "will fail on validateion if it has a source with no sourceid" do
60
+ # given
61
+ organization.name = "Lundalogik"
62
+
63
+ # when
64
+ organization.with_source do |source|
65
+ source.par_se('')
66
+ end
67
+
68
+ # then
69
+ organization.validate.length.should be > 0
70
+ end
71
+
72
+ it "will fail on validation if no name is specified" do
73
+ # given
74
+ organization.name = ""
75
+
76
+ # when, then
77
+ organization.validate.length.should be > 0
78
+ end
79
+
80
+ it "will set coworker ref when coworker is assigned" do
81
+ # given
82
+ coworker = MoveToGo::Coworker.new({:integration_id => "456", :first_name => "Billy", :last_name => "Bob"})
83
+
84
+ # when
85
+ organization.responsible_coworker = coworker
86
+
87
+ # then
88
+ organization.responsible_coworker.is_a?(MoveToGo::Coworker).should eq true
89
+ organization.instance_variable_get(:@responsible_coworker_reference).is_a?(MoveToGo::CoworkerReference).should eq true
90
+ end
91
+
92
+ it "will have a no relation as default" do
93
+ # given, when, then
94
+ organization.relation.should eq MoveToGo::Relation::NoRelation
95
+ end
96
+
97
+ it "should only accept relations from Relations enum" do
98
+ # given, when
99
+ organization.relation = MoveToGo::Relation::IsACustomer
100
+
101
+ # then
102
+ organization.relation.should eq MoveToGo::Relation::IsACustomer
103
+ end
104
+
105
+ it "should not accept invalid relations" do
106
+ # when, then
107
+ expect {
108
+ organization.relation = "hubbabubba"
109
+ }.to raise_error(MoveToGo::InvalidRelationError)
110
+ end
111
+
112
+ it "should not have a relation modified date if relation is NoRelation" do
113
+ # given, when
114
+ organization.relation = MoveToGo::Relation::NoRelation
115
+
116
+ # then
117
+ organization.relation_last_modified.nil?.should eq true
118
+ end
119
+
120
+ it "should have a relation modified date if relation is IsACustomer" do
121
+ # given, when
122
+ organization.relation = MoveToGo::Relation::IsACustomer
123
+
124
+ # then
125
+ organization.relation_last_modified.nil?.should eq false
126
+ end
127
+
128
+ it "should set relation last modified when relation is set" do
129
+ # given
130
+ organization.relation = MoveToGo::Relation::IsACustomer
131
+
132
+ # when
133
+ organization.relation_last_modified = "2014-07-01"
134
+
135
+ # then
136
+ organization.relation_last_modified.should eq "2014-07-01"
137
+ end
138
+
139
+ it "should not set relation last modified when relation is NoRelation" do
140
+ # given
141
+ organization.relation = MoveToGo::Relation::NoRelation
142
+
143
+ # when
144
+ organization.relation_last_modified = "2014-07-01"
145
+
146
+ # then
147
+ organization.relation_last_modified.nil?.should eq true
148
+ end
149
+
150
+ it "should only set relation last modified to valid date" do
151
+ # given
152
+ organization.relation = MoveToGo::Relation::IsACustomer
153
+
154
+ # when, then
155
+ expect {
156
+ organization.relation_last_modified = "hubbabubba"
157
+ }.to raise_error(MoveToGo::InvalidValueError)
158
+ end
159
+
160
+ it "can have custom value" do
161
+ # given, when
162
+ organization.set_custom_value "field_integration_id", "the is a value"
163
+
164
+ # then
165
+ organization.custom_values.length.should eq 1
166
+ end
167
+
168
+ it "can have a custom numeric value" do
169
+ # given, when
170
+ organization.set_custom_value "price", 100
171
+
172
+ # then
173
+ organization.custom_values.length.should eq 1
174
+ organization.custom_values[0].value.should eq "100"
175
+ end
176
+
177
+ it "a custom value can not be empty" do
178
+ # given, when
179
+ organization.set_custom_value "field_integration_id", ""
180
+
181
+ # then
182
+ organization.custom_values.length.should eq 0
183
+ end
184
+ end
185
+
186
+ describe "OrganizationReference" do
187
+ it "can be created from an organization" do
188
+ # given
189
+ org = MoveToGo::Organization.new
190
+ org.name = "Lundalogik"
191
+ org.integration_id = "123"
192
+
193
+ # when
194
+ ref = MoveToGo::OrganizationReference.from_organization(org)
195
+
196
+ # then
197
+ ref.is_a?(MoveToGo::OrganizationReference).should eq true
198
+ ref.heading.should eq "Lundalogik"
199
+ ref.integration_id.should eq "123"
200
+ end
201
+
202
+ it "can be created from an organization_reference" do
203
+ # given
204
+ orgref = MoveToGo::OrganizationReference.new
205
+ orgref.heading = "Lundalogik"
206
+
207
+ # when
208
+ ref = MoveToGo::OrganizationReference.from_organization(orgref)
209
+
210
+ # then
211
+ ref.is_a?(MoveToGo::OrganizationReference).should eq true
212
+ end
213
+
214
+ it "is nil when created from nil" do
215
+ # given, when
216
+ ref = MoveToGo::OrganizationReference.from_organization(nil)
217
+
218
+ # then
219
+ ref.should eq nil
220
+ end
221
+ end