rubyzoho 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,344 +2,445 @@ $:.unshift File.join('..', File.dirname(__FILE__), 'lib')
2
2
 
3
3
  require 'spec_helper'
4
4
  require 'zoho_api'
5
+ require 'vcr'
6
+
7
+ VCR.configure do |c|
8
+ c.cassette_library_dir = 'spec/vcr'
9
+ c.hook_into :webmock
10
+ # c.default_cassette_options = {:record => :all}
11
+ # c.debug_logger = File.open('log/vcr_debug.log', 'w')
12
+ end
13
+
5
14
 
6
15
  describe RubyZoho::Crm do
7
16
 
8
17
  before(:all) do
9
- base_path = File.join(File.dirname(__FILE__), 'fixtures')
10
- @sample_pdf = File.join(base_path, 'sample.pdf')
11
- RubyZoho.configure do |config|
12
- config.api_key = ENV['ZOHO_API_KEY'].strip
13
- config.crm_modules = %w(Quotes)
14
- config.cache_fields = true
18
+ VCR.use_cassette 'zoho/initialization' do
19
+ base_path = File.join(File.dirname(__FILE__), 'fixtures')
20
+ @sample_pdf = File.join(base_path, 'sample.pdf')
21
+ RubyZoho.configure do |config|
22
+ config.api_key = ENV['ZOHO_API_KEY'].strip
23
+ config.crm_modules = %w(Quotes)
24
+ config.cache_fields = true
25
+ end
26
+ r = RubyZoho::Crm::Contact.find_by_last_name('Smithereens')
27
+ r.each { |m| RubyZoho::Crm::Contact.delete(m.contactid) } unless r.nil?
28
+ r = RubyZoho::Crm::Contact.find_by_email('raj@portra.com')
29
+ r.each { |contact| RubyZoho::Crm::Contact.delete(contact.contactid) } unless r.nil?
15
30
  end
16
- r = RubyZoho::Crm::Contact.find_by_last_name('Smithereens')
17
- r.each { |m| RubyZoho::Crm::Contact.delete(m.contactid) } unless r.nil?
18
- r = RubyZoho::Crm::Contact.find_by_email('raj@portra.com')
19
- r.each { |c| RubyZoho::Crm::Contact.delete(c.contactid) } unless r.nil?
20
31
  end
21
32
 
22
33
  it 'should add accessors using a list of names' do
23
- c = RubyZoho::Crm::Contact.new
24
- c.first_name = 'Raj'
25
- c.first_name.should eq('Raj')
26
- c.email = 'raj@portra.com'
27
- c.email.should eq('raj@portra.com')
28
- c.module_name.should eq('Contacts')
34
+ VCR.use_cassette 'zoho/accessors_names' do
35
+ c = RubyZoho::Crm::Contact.new
36
+ c.first_name = 'Raj'
37
+ c.first_name.should eq('Raj')
38
+ c.email = 'raj@portra.com'
39
+ c.email.should eq('raj@portra.com')
40
+ c.module_name.should eq('Contacts')
41
+ end
29
42
  end
30
43
 
31
44
  it 'should attach a file to an account' do
32
- r = RubyZoho::Crm::Account.all.first
33
- r.attach_file(@sample_pdf, '1_' + File.basename(@sample_pdf)).should eq('200')
45
+ VCR.use_cassette 'zoho/attach_file_to_account' do
46
+ r = RubyZoho::Crm::Account.all.first
47
+ r.attach_file(@sample_pdf, '1_' + File.basename(@sample_pdf)).should eq('200')
48
+ end
34
49
  end
35
50
 
36
51
  it 'should attach a file to a contact' do
37
- r = RubyZoho::Crm::Contact.all.first
38
- r.attach_file(@sample_pdf, File.basename(@sample_pdf)).should eq('200')
52
+ VCR.use_cassette 'zoho/attach_file_to_contact' do
53
+ r = RubyZoho::Crm::Contact.all.first
54
+ r.attach_file(@sample_pdf, File.basename(@sample_pdf)).should eq('200')
55
+ end
39
56
  end
40
57
 
41
58
  it 'should attach a file to a lead' do
42
- r = RubyZoho::Crm::Lead.all.first
43
- r.attach_file(@sample_pdf, File.basename(@sample_pdf)).should eq('200')
59
+ VCR.use_cassette 'zoho/attach_file_to_lead' do
60
+ r = RubyZoho::Crm::Lead.all.first
61
+ r.attach_file(@sample_pdf, File.basename(@sample_pdf)).should eq('200')
62
+ end
44
63
  end
45
64
 
46
65
  it 'should attach a file to a potential' do
47
- r = RubyZoho::Crm::Potential.all.first
48
- r.attach_file(@sample_pdf, File.basename(@sample_pdf)).should eq('200')
66
+ VCR.use_cassette 'zoho/attach_file_to_potential' do
67
+ r = RubyZoho::Crm::Potential.all.first
68
+ r.attach_file(@sample_pdf, File.basename(@sample_pdf)).should eq('200')
69
+ end
49
70
  end
50
71
 
51
72
  it 'should attach a file to a task' do
52
- r = RubyZoho::Crm::Task.all.first
53
- r.attach_file(@sample_pdf, File.basename(@sample_pdf)).should eq('200')
73
+ VCR.use_cassette 'zoho/attach_file_to_task' do
74
+ r = RubyZoho::Crm::Task.all.first
75
+ r.attach_file(@sample_pdf, File.basename(@sample_pdf)).should eq('200')
76
+ end
54
77
  end
55
78
 
56
79
  it 'should concatenate a related object and save it' do
57
- subject = "[DELETE THIS] New subject as of #{Time.now}"
58
- a = RubyZoho::Crm::Account.all.last
59
- a << RubyZoho::Crm::Task.new(
60
- :subject => subject,
61
- :description => 'Nothing',
62
- :status => 'Not Started',
63
- :priority => 'High',
64
- :send_notification_email => 'False',
65
- :due_date => '2014-02-16 16:00:00',
66
- :start_datetime => Time.now.to_s[1, 19],
67
- :end_datetime => '2014-02-16 16:00:00'
68
- )
69
- r = RubyZoho::Crm::Task.find_by_subject(subject)
70
- r.first.relatedtoid.should eq(a.accountid)
80
+ VCR.use_cassette 'zoho/concatenate_related_object' do
81
+ subject = '[DELETE THIS] New subject as of 112233'
82
+ a = RubyZoho::Crm::Account.all.last
83
+ #noinspection RubyArgCount
84
+ a << RubyZoho::Crm::Task.new(
85
+ :subject => subject,
86
+ :description => 'Nothing',
87
+ :status => 'Not Started',
88
+ :priority => 'High',
89
+ :send_notification_email => 'False',
90
+ :due_date => '2014-02-16 16:00:00',
91
+ :start_datetime => Time.now.to_s[1, 19],
92
+ :end_datetime => '2014-02-16 16:00:00'
93
+ )
94
+ r = RubyZoho::Crm::Task.find_by_subject(subject)
95
+ r.first.relatedtoid.should eq(a.accountid)
96
+ end
71
97
  end
72
98
 
73
99
  it 'should determine if a method is a module' do
74
- good_methods = [:contact, :contacts, 'contacts', 'lead', 'leads', :potentials, :quotes]
75
- good_methods.map { |m| RubyZoho::Crm.method_is_module?(m).should_not eq(nil) }
100
+ VCR.use_cassette 'zoho/determine_module' do
101
+ good_methods = [:contact, :contacts, 'contacts', 'lead', 'leads', :potentials, :quotes]
102
+ good_methods.map { |m| RubyZoho::Crm.method_is_module?(m).should_not eq(nil) }
103
+ end
76
104
  end
77
105
 
78
106
  it 'should find a contact by email or last name' do
79
- r = RubyZoho::Crm::Contact.find_by_email('bob@smith.com')
80
- r.each { |m| RubyZoho::Crm::Contact.delete(m.id) } unless r.nil?
81
- 1.upto(3) do
82
- c = RubyZoho::Crm::Contact.new(
83
- :first_name => 'Bob',
84
- :last_name => 'Smithereens',
85
- :email => 'bob@smith.com')
86
- c.save
107
+ VCR.use_cassette 'zoho/find_by_email_or_name' do
108
+ r = RubyZoho::Crm::Contact.find_by_email('bob@smith.com')
109
+ r.each { |m| RubyZoho::Crm::Contact.delete(m.id) } unless r.nil?
110
+ 1.upto(3) do
111
+ c = RubyZoho::Crm::Contact.new(
112
+ :first_name => 'Bob',
113
+ :last_name => 'Smithereens',
114
+ :email => 'bob@smith.com')
115
+ c.save
116
+ end
117
+ r = RubyZoho::Crm::Contact.find_by_email('bob@smith.com')
118
+ r.should_not eq(nil)
119
+ r.count.should eq(3)
120
+ r.each { |m| m.email.should eq('bob@smith.com') }
121
+ r = RubyZoho::Crm::Contact.find_by_last_name('Smithereens')
122
+ r.should_not eq(nil)
123
+ r.map { |c| c.last_name }.count.should eq(3)
124
+ r.first.last_name.should eq('Smithereens')
125
+ r.each { |m| RubyZoho::Crm::Contact.delete(m.id) }
87
126
  end
88
- r = RubyZoho::Crm::Contact.find_by_email('bob@smith.com')
89
- r.should_not eq(nil)
90
- r.count.should eq(3)
91
- r.each { |m| m.email.should eq('bob@smith.com') }
92
- r = RubyZoho::Crm::Contact.find_by_last_name('Smithereens')
93
- r.should_not eq(nil)
94
- r.map { |c| c.last_name }.count.should eq(3)
95
- r.first.last_name.should eq('Smithereens')
96
- r.each { |m| RubyZoho::Crm::Contact.delete(m.id) }
97
127
  end
98
128
 
99
129
  it 'should find a contact by ID' do
100
- contacts = RubyZoho::Crm::Contact.all
101
- id = contacts.first.id
102
- c = RubyZoho::Crm::Contact.find_by_contactid(id)
103
- c.first.contactid.should eq(id)
104
- c.first.last_name.should eq(contacts.first.last_name)
105
- c.first.email.should eq(contacts.first.email)
130
+ VCR.use_cassette 'zoho/find_contact_by_id' do
131
+ contacts = RubyZoho::Crm::Contact.all
132
+ id = contacts.first.id
133
+ c = RubyZoho::Crm::Contact.find_by_contactid(id)
134
+ c.first.contactid.should eq(id)
135
+ c.first.last_name.should eq(contacts.first.last_name)
136
+ c.first.email.should eq(contacts.first.email)
137
+ end
106
138
  end
107
139
 
108
140
  it 'should find a lead by ID' do
109
- leads = RubyZoho::Crm::Lead.all
110
- lead_id = leads.first.id
111
- l = RubyZoho::Crm::Lead.find_by_leadid(lead_id)
112
- l.first.leadid.should eq(lead_id)
141
+ VCR.use_cassette 'zoho/find_lead_by_id' do
142
+ leads = RubyZoho::Crm::Lead.all
143
+ lead_id = leads.first.id
144
+ l = RubyZoho::Crm::Lead.find_by_leadid(lead_id)
145
+ l.first.leadid.should eq(lead_id)
146
+ end
113
147
  end
114
148
 
115
149
  it 'should find a user by email address' do
116
- users = RubyZoho::Crm::CRMUser.all
117
- r = RubyZoho::Crm::CRMUser.find_by_email(users.first.email)
118
- r.first.email.should eq(users.first.email)
150
+ VCR.use_cassette 'zoho/find_user_by_email' do
151
+ users = RubyZoho::Crm::CRMUser.all
152
+ r = RubyZoho::Crm::CRMUser.find_by_email(users.first.email)
153
+ r.first.email.should eq(users.first.email)
154
+ end
119
155
  end
120
156
 
121
157
  it 'should get a list of attr_writers for accounts' do
122
- c = RubyZoho::Crm::Account.new
123
- c.attr_writers.count.should be >= 18
158
+ VCR.use_cassette 'zoho/list_attr_writers' do
159
+ c = RubyZoho::Crm::Account.new
160
+ c.attr_writers.count.should be >= 18
161
+ end
124
162
  end
125
163
 
126
164
  it 'should get a list of attr_writers for contacts' do
127
- c = RubyZoho::Crm::Contact.new
128
- c.attr_writers.count.should be >= 10
165
+ VCR.use_cassette 'zoho/list_attr_writers_for_contacts' do
166
+ c = RubyZoho::Crm::Contact.new
167
+ c.attr_writers.count.should be >= 10
168
+ end
129
169
  end
130
170
 
131
171
  it 'should get a list of attr_writers for leads' do
132
- c = RubyZoho::Crm::Lead.new
133
- c.attr_writers.count.should be >= 16
172
+ VCR.use_cassette 'zoho/list_attr_writers_for_leads' do
173
+ c = RubyZoho::Crm::Lead.new
174
+ c.attr_writers.count.should be >= 16
175
+ end
134
176
  end
135
177
 
136
178
  it 'should get a list of attr_writers for potentials' do
137
- c = RubyZoho::Crm::Potential.new
138
- c.attr_writers.count.should be >= 14
179
+ VCR.use_cassette 'zoho/list_attr_writers_for_potentials' do
180
+ c = RubyZoho::Crm::Potential.new
181
+ c.attr_writers.count.should be >= 14
182
+ end
139
183
  end
140
184
 
141
185
  it 'should get a list of attr_writers for tasks' do
142
- c = RubyZoho::Crm::Task.new
143
- c.attr_writers.count.should be >= 14
186
+ VCR.use_cassette 'zoho/list_attr_writers_for_taskss' do
187
+ c = RubyZoho::Crm::Task.new
188
+ c.attr_writers.count.should be >= 14
189
+ end
144
190
  end
145
191
 
146
192
  it 'should get a list of attr_writers for quotes' do
147
- c = RubyZoho::Crm::Quote.new
148
- c.attr_writers.count.should be >= 18 unless c.nil?
193
+ VCR.use_cassette 'zoho/list_attr_writers_for_quotes' do
194
+ c = RubyZoho::Crm::Quote.new
195
+ c.attr_writers.count.should be >= 18 unless c.nil?
196
+ end
149
197
  end
150
198
 
151
199
  it 'should get a list of accounts' do
152
- r = RubyZoho::Crm::Account.all
153
- r.count.should be > 1
154
- r.map { |r| r.class.should eq(RubyZoho::Crm::Account) }
200
+ VCR.use_cassette 'zoho/list_of_accounts' do
201
+ r = RubyZoho::Crm::Account.all
202
+ r.count.should be > 1
203
+ r.map { |account| account.class.should eq(RubyZoho::Crm::Account) }
204
+ end
155
205
  end
156
206
 
157
207
  it 'should get a list of calls' do
158
- r = RubyZoho::Crm::Call.all
159
- unless r.nil?
160
- r.map { |e| e.class.should eq(RubyZoho::Crm::Call) }
161
- r.map { |e| e.id.should eq(e.activityid) }
208
+ VCR.use_cassette 'zoho/list_of_calls' do
209
+ r = RubyZoho::Crm::Call.all
210
+ unless r.nil?
211
+ r.map { |e| e.class.should eq(RubyZoho::Crm::Call) }
212
+ r.map { |e| e.id.should eq(e.activityid) }
213
+ end
162
214
  end
163
215
  end
164
216
 
165
217
  it 'should get a list of contacts' do
166
- r = RubyZoho::Crm::Contact.all
167
- r.count.should be > 1
168
- r.map { |e| e.class.should eq(RubyZoho::Crm::Contact) }
169
- r.map { |e| e.id.should eq(e.contactid) }
218
+ VCR.use_cassette 'zoho/list_of_contacts' do
219
+ r = RubyZoho::Crm::Contact.all
220
+ r.count.should be > 1
221
+ r.map { |e| e.class.should eq(RubyZoho::Crm::Contact) }
222
+ r.map { |e| e.id.should eq(e.contactid) }
223
+ end
170
224
  end
171
225
 
172
226
  it 'should get a list of events' do
173
227
  pending
174
- r = RubyZoho::Crm::Event.all
175
- r.map { |r| r.class.should eq(RubyZoho::Crm::Event) } unless r.nil?
176
- r.map { |e| e.id.should eq(e.eventid) }
228
+ VCR.use_cassette 'zoho/list_of_events' do
229
+ r = RubyZoho::Crm::Event.all
230
+ r.map { |event| event.class.should eq(RubyZoho::Crm::Event) } unless r.nil?
231
+ r.map { |e| e.id.should eq(e.eventid) }
232
+ true.should eq(false)
233
+ end
177
234
  end
178
235
 
179
236
  it 'should get a list of potentials' do
180
- r = RubyZoho::Crm::Potential.all
181
- r.count.should be > 1
182
- r.map { |r| r.class.should eq(RubyZoho::Crm::Potential) }
183
- r.map { |e| e.id.should eq(e.potentialid) }
237
+ VCR.use_cassette 'zoho/list_of_potentials' do
238
+ r = RubyZoho::Crm::Potential.all
239
+ r.count.should be > 1
240
+ r.map { |potential| potential.class.should eq(RubyZoho::Crm::Potential) }
241
+ r.map { |e| e.id.should eq(e.potentialid) }
242
+ end
184
243
  end
185
244
 
186
245
  it 'should get a list of quotes' do
187
246
  pending
188
- r = RubyZoho::Crm::Quote.all
189
- r.count.should be >= 1
190
- r.map { |r| r.class.should eq(RubyZoho::Crm::Quote) }
191
- r.map { |e| e.id.should eq(e.quoteid) }
247
+ VCR.use_cassette 'zoho/list_of_quotes' do
248
+ r = RubyZoho::Crm::Quote.all
249
+ r.count.should be >= 1
250
+ r.map { |quote| quote.class.should eq(RubyZoho::Crm::Quote) }
251
+ r.map { |e| e.id.should eq(e.quoteid) }
252
+ end
192
253
  end
193
254
 
194
255
  it 'should get a list of tasks' do
195
- r = RubyZoho::Crm::Task.all
196
- r.map { |r| r.class.should eq(RubyZoho::Crm::Task) } unless r.nil?
197
- r.map { |e| e.id.should eq(e.activityid) }
256
+ VCR.use_cassette 'zoho/list_of_tasks' do
257
+ r = RubyZoho::Crm::Task.all
258
+ r.map { |task| task.class.should eq(RubyZoho::Crm::Task) } unless r.nil?
259
+ r.map { |e| e.id.should eq(e.activityid) }
260
+ end
198
261
  end
199
262
 
200
263
  it 'should get a list of users' do
201
- r = RubyZoho::Crm::CRMUser.all
202
- r.count.should be >= 1
264
+ VCR.use_cassette 'zoho/list_of_users' do
265
+ r = RubyZoho::Crm::CRMUser.all
266
+ r.count.should be >= 1
267
+ end
203
268
  end
204
269
 
205
270
  it 'should save a contact record' do
206
- c = RubyZoho::Crm::Contact.new(
207
- :first_name => 'Raj',
208
- :last_name => 'Portra',
209
- :email => 'raj@portra.com')
210
- c.save
211
- r = RubyZoho::Crm::Contact.find_by_email('raj@portra.com')
212
- r.first.email.should eq('raj@portra.com')
213
- r.each { |c| RubyZoho::Crm::Contact.delete(c.contactid) }
271
+ VCR.use_cassette 'zoho/save_contact' do
272
+ c = RubyZoho::Crm::Contact.new(
273
+ :first_name => 'Raj',
274
+ :last_name => 'Portra',
275
+ :email => 'raj@portra.com')
276
+ c.save
277
+ r = RubyZoho::Crm::Contact.find_by_email('raj@portra.com')
278
+ r.first.email.should eq('raj@portra.com')
279
+ r.each { |contact| RubyZoho::Crm::Contact.delete(contact.contactid) }
280
+ end
214
281
  end
215
282
 
216
283
  it 'should save a lead record' do
217
- l = RubyZoho::Crm::Lead.new(
218
- :first_name => 'Raj',
219
- :last_name => 'Portra',
220
- :email => 'raj@portra.com')
221
- l.save
222
- r = RubyZoho::Crm::Lead.find_by_email('raj@portra.com')
223
- r.should_not eq(nil)
224
- r.first.email.should eq(l.email)
225
- r.each { |c| RubyZoho::Crm::Lead.delete(c.id) }
284
+ VCR.use_cassette 'zoho/save_lead' do
285
+ l = RubyZoho::Crm::Lead.new(
286
+ :first_name => 'Raj',
287
+ :last_name => 'Portra',
288
+ :email => 'raj@portra.com')
289
+ l.save
290
+ r = RubyZoho::Crm::Lead.find_by_email('raj@portra.com')
291
+ r.should_not eq(nil)
292
+ r.first.email.should eq(l.email)
293
+ r.each { |c| RubyZoho::Crm::Lead.delete(c.id) }
294
+ end
226
295
  end
227
296
 
228
297
  it 'should save and retrieve an account record with a custom field' do
229
- accounts = RubyZoho::Crm::Account.all
230
- a = accounts.first
231
- if defined?(a.par_ltd)
232
- RubyZoho::Crm::Lead.update(
233
- :id => a.id,
234
- :test_custom => '$1,000,000'
235
- )
236
- a2 = RubyZoho::Crm::Account.find(a.accountid)
237
- a2.first.test_custom.should eq('$1,000,000')
298
+ VCR.use_cassette 'zoho/save_account_custom_field' do
299
+ accounts = RubyZoho::Crm::Account.all
300
+ a = accounts.first
301
+ if defined?(a.par_lifetime_to_dat)
302
+ RubyZoho::Crm::Account.update(
303
+ :id => a.id,
304
+ :par_lifetime_to_date => '$1000000'
305
+ )
306
+ a2 = RubyZoho::Crm::Account.find(a.accountid)
307
+ a2.first.test_custom.should eq('1000000')
308
+ end
309
+ end
310
+ end
311
+
312
+ it 'should save and retrieve a lead record with a custom field' do
313
+ VCR.use_cassette 'zoho/save_lead_custom_field' do
314
+ l = RubyZoho::Crm::Lead.first
315
+ if defined?(l.test_label)
316
+ RubyZoho::Crm::Lead.update(
317
+ :id => l.id,
318
+ :test_label => '$1000000'
319
+ )
320
+ l2 = RubyZoho::Crm::Lead.find(l.id)
321
+ l2.first.test_label.should eq('$1000000')
322
+ end
238
323
  end
239
324
  end
240
325
 
241
326
  it 'should save and retrieve a potential record' do
242
- accounts = RubyZoho::Crm::Account.all
243
- h = {
244
- :potential_name => 'A very big potential INDEED!!!!!!!!!!!!!',
245
- :accountid => accounts.first.accountid,
246
- :account_name => accounts.first.account_name,
247
- :closing_date => '1/1/2014',
248
- :type => 'New Business',
249
- :stage => 'Needs Analysis'}
250
- r = RubyZoho::Crm::Potential.find_by_potential_name(h[:potential_name])
251
- r.each { |c| RubyZoho::Crm::Potential.delete(c.potentialid) } unless r.nil?
252
- p = RubyZoho::Crm::Potential.new(h)
253
- p.save
254
- r = RubyZoho::Crm::Potential.find_by_potential_name(p.potential_name)
255
- r.first.potential_name.should eq(h[:potential_name])
256
- potential = RubyZoho::Crm::Potential.find(r.first.potentialid)
257
- potential.first.potentialid.should eq(r.first.potentialid)
258
- p_by_account_id = RubyZoho::Crm::Potential.find_by_accountid(accounts.first.accountid)
259
- p_found = p_by_account_id.map { |pn| pn if pn.potential_name == h[:potential_name] }.compact
260
- p_found.first.potentialid.should eq(r.first.potentialid)
261
- r.each { |c| RubyZoho::Crm::Potential.delete(c.potentialid) }
327
+ VCR.use_cassette 'zoho/potential_record' do
328
+ accounts = RubyZoho::Crm::Account.all
329
+ h = {
330
+ :potential_name => 'A very big potential INDEED!!!!!!!!!!!!!',
331
+ :accountid => accounts.first.accountid,
332
+ :account_name => accounts.first.account_name,
333
+ :closing_date => '1/1/2014',
334
+ :type => 'New Business',
335
+ :stage => 'Needs Analysis'}
336
+ r = RubyZoho::Crm::Potential.find_by_potential_name(h[:potential_name])
337
+ r.each { |c| RubyZoho::Crm::Potential.delete(c.potentialid) } unless r.nil?
338
+ p = RubyZoho::Crm::Potential.new(h)
339
+ p.save
340
+ r = RubyZoho::Crm::Potential.find_by_potential_name(p.potential_name)
341
+ r.first.potential_name.should eq(h[:potential_name])
342
+ potential = RubyZoho::Crm::Potential.find(r.first.potentialid)
343
+ potential.first.potentialid.should eq(r.first.potentialid)
344
+ p_by_account_id = RubyZoho::Crm::Potential.find_by_accountid(accounts.first.accountid)
345
+ p_found = p_by_account_id.map { |pn| pn if pn.potential_name == h[:potential_name] }.compact
346
+ p_found.first.potentialid.should eq(r.first.potentialid)
347
+ r.each { |c| RubyZoho::Crm::Potential.delete(c.potentialid) }
348
+ end
262
349
  end
263
350
 
264
351
  it 'should save and retrieve a task record' do
265
- accounts = RubyZoho::Crm::Account.all
266
- h = {
267
- :subject => 'Test Task',
268
- :due_date => Date.today.to_s + '23:59',
269
- :semodule => 'Accounts',
270
- :relatedtoid => accounts.first.accountid,
271
- :related_to => accounts.first.account_name,
272
- :priority => 'Low'}
273
- r = RubyZoho::Crm::Task.find_by_subject(h[:subject])
274
- r.each { |t| RubyZoho::Crm::Task.delete(t.activityid) } unless r.nil?
275
- t = RubyZoho::Crm::Task.new(h)
276
- t.save
277
- r = RubyZoho::Crm::Task.find_by_subject(h[:subject])
278
- r.first.subject.should eq(h[:subject])
279
- tasks = RubyZoho::Crm::Task.find_by_activityid(r.first.activityid)
280
- tasks.first.activityid.should eq(r.first.activityid)
281
- r.each { |c| RubyZoho::Crm::Task.delete(c.activityid) }
352
+ VCR.use_cassette 'zoho/task_record' do
353
+ accounts = RubyZoho::Crm::Account.all
354
+ h = {
355
+ :subject => 'Test Task',
356
+ :due_date => Date.today.to_s + '23:59',
357
+ :semodule => 'Accounts',
358
+ :relatedtoid => accounts.first.accountid,
359
+ :related_to => accounts.first.account_name,
360
+ :priority => 'Low'}
361
+ r = RubyZoho::Crm::Task.find_by_subject(h[:subject])
362
+ r.each { |t| RubyZoho::Crm::Task.delete(t.activityid) } unless r.nil?
363
+ t = RubyZoho::Crm::Task.new(h)
364
+ t.save
365
+ r = RubyZoho::Crm::Task.find_by_subject(h[:subject])
366
+ r.first.subject.should eq(h[:subject])
367
+ tasks = RubyZoho::Crm::Task.find_by_activityid(r.first.activityid)
368
+ tasks.first.activityid.should eq(r.first.activityid)
369
+ r.each { |c| RubyZoho::Crm::Task.delete(c.activityid) }
370
+ end
282
371
  end
283
372
 
284
373
  it 'should save an task record related to an account' do
285
- a = RubyZoho::Crm::Account.all.first
286
- e = RubyZoho::Crm::Task.new(
287
- :task_owner => a.account_owner,
288
- :subject => "Task should be related to #{a.account_name} #{Time.now}",
289
- :description => 'Nothing',
290
- :smownerid => "#{a.smownerid}",
291
- :status => 'Not Started',
292
- :priority => 'High',
293
- :send_notification_email => 'False',
294
- :due_date => '2014-02-16 16:00:00',
295
- :start_datetime => Time.now.to_s[1, 19],
296
- :end_datetime => '2014-02-16 16:00:00',
297
- :related_to => "#{a.account_name}",
298
- :seid => "#{a.accountid}",
299
- :semodule => "Accounts"
300
- )
301
- r_expected = e.save
302
- r = RubyZoho::Crm::Task.find_by_activityid(r_expected.id)
303
- r.first.subject.should eq(r_expected.subject)
374
+ VCR.use_cassette 'zoho/task_related_to_account' do
375
+ a = RubyZoho::Crm::Account.all.first
376
+ e = RubyZoho::Crm::Task.new(
377
+ :task_owner => a.account_owner,
378
+ :subject => "Task should be related to #{a.account_name} #{Time.now}",
379
+ :description => 'Nothing',
380
+ :smownerid => "#{a.smownerid}",
381
+ :status => 'Not Started',
382
+ :priority => 'High',
383
+ :send_notification_email => 'False',
384
+ :due_date => '2014-02-16 16:00:00',
385
+ :start_datetime => Time.now.to_s[1, 19],
386
+ :end_datetime => '2014-02-16 16:00:00',
387
+ :related_to => "#{a.account_name}",
388
+ :seid => "#{a.accountid}",
389
+ :semodule => 'Accounts'
390
+ )
391
+ r_expected = e.save
392
+ r = RubyZoho::Crm::Task.find_by_activityid(r_expected.id)
393
+ r.first.subject[0..20].should eq(r_expected.subject[0..20])
394
+ end
304
395
  end
305
396
 
306
397
  it 'should get tasks by user' do
307
398
  pending
308
- pp task_owner = RubyZoho::Crm::Task.first.task_owner
309
- pp tasks = RubyZoho::Crm::Task.find_by_task_owner(task_owner)
310
- #tasks.map { |t| RubyZoho::Crm::Task.delete(t.activityid)} unless tasks.nil?
399
+ VCR.use_cassette 'zoho/tasks_by_owner' do
400
+ task_owner = RubyZoho::Crm::Task.first.task_owner
401
+ tasks = RubyZoho::Crm::Task.find_by_task_owner(task_owner)
402
+ tasks.should_not eq(nil)
403
+ tasks.map { |t| RubyZoho::Crm::Task.delete(t.activityid) } unless tasks.nil?
404
+ true.should eq(false)
405
+ end
311
406
  end
312
407
 
313
408
  it 'should sort contact records' do
314
- r = RubyZoho::Crm::Contact.all
315
- sorted = r.sort { |a, b| a.last_name <=> b.last_name }
316
- sorted.collect { |c| c.last_name }.should_not eq(nil)
409
+ VCR.use_cassette 'zoho/sort_contacts' do
410
+ r = RubyZoho::Crm::Contact.all
411
+ sorted = r.sort { |a, b| a.last_name <=> b.last_name }
412
+ sorted.collect { |c| c.last_name }.should_not eq(nil)
413
+ end
317
414
  end
318
415
 
319
416
  it 'should update a lead record' do
320
- r_changed = RubyZoho::Crm::Lead.find_by_email('changed_raj@portra.com')
321
- r_changed.each { |c| RubyZoho::Crm::Lead.delete(c.leadid) } unless r_changed.nil?
322
- l = RubyZoho::Crm::Lead.new(
323
- :first_name => 'Raj',
324
- :last_name => 'Portra',
325
- :email => 'raj@portra.com')
326
- l.save
327
- r = RubyZoho::Crm::Lead.find_by_email('raj@portra.com')
328
- RubyZoho::Crm::Lead.update(
329
- :id => r.first.leadid,
330
- :email => 'changed_raj@portra.com'
331
- )
332
- r_changed = RubyZoho::Crm::Lead.find_by_email('changed_raj@portra.com')
333
- r.first.leadid.should eq(r_changed.first.leadid)
334
- r.each { |c| RubyZoho::Crm::Lead.delete(c.leadid) }
335
- r_changed.each { |c| RubyZoho::Crm::Lead.delete(c.leadid) }
417
+ VCR.use_cassette 'zoho/update_lead' do
418
+ r_changed = RubyZoho::Crm::Lead.find_by_email('changed_raj@portra.com')
419
+ r_changed.each { |c| RubyZoho::Crm::Lead.delete(c.leadid) } unless r_changed.nil?
420
+ l = RubyZoho::Crm::Lead.new(
421
+ :first_name => 'Raj',
422
+ :last_name => 'Portra',
423
+ :email => 'raj@portra.com')
424
+ l.save
425
+ r = RubyZoho::Crm::Lead.find_by_email('raj@portra.com')
426
+ RubyZoho::Crm::Lead.update(
427
+ :id => r.first.leadid,
428
+ :email => 'changed_raj@portra.com'
429
+ )
430
+ r_changed = RubyZoho::Crm::Lead.find_by_email('changed_raj@portra.com')
431
+ r.first.leadid.should eq(r_changed.first.leadid)
432
+ r.each { |c| RubyZoho::Crm::Lead.delete(c.leadid) }
433
+ r_changed.each { |c| RubyZoho::Crm::Lead.delete(c.leadid) }
434
+ end
336
435
  end
337
436
 
338
437
  it 'should validate a field name' do
339
- good_names = ['This is OK', 'OK_to_use', 'field()']
340
- bad_names = ['This %#{@} is not']
341
- good_names.map { |f| RubyZoho::Crm.method_name?(ApiUtils.string_to_symbol(f)).should_not eq(false) }
342
- bad_names.map { |f| RubyZoho::Crm.method_name?(ApiUtils.string_to_symbol(f)).should eq(false) }
438
+ VCR.use_cassette 'zoho/validate_field' do
439
+ good_names = ['This is OK', 'OK_to_use', 'field()']
440
+ bad_names = ['This %#{@} is not']
441
+ good_names.map { |f| RubyZoho::Crm.method_name?(ApiUtils.string_to_symbol(f)).should_not eq(false) }
442
+ bad_names.map { |f| RubyZoho::Crm.method_name?(ApiUtils.string_to_symbol(f)).should eq(false) }
443
+ end
343
444
  end
344
445
 
345
446
  end