capsule_crm 1.1.0 → 1.2.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.
- checksums.yaml +4 -4
- data/.travis.yml +1 -0
- data/CHANGELOG.md +19 -0
- data/README.md +1 -1
- data/lib/capsule_crm/associations/belongs_to.rb +12 -10
- data/lib/capsule_crm/associations/belongs_to_association.rb +80 -0
- data/lib/capsule_crm/associations/has_many.rb +8 -18
- data/lib/capsule_crm/associations/has_many_association.rb +80 -0
- data/lib/capsule_crm/associations.rb +26 -0
- data/lib/capsule_crm/capsule_jsonable.rb +5 -1
- data/lib/capsule_crm/case.rb +7 -9
- data/lib/capsule_crm/contacts.rb +1 -1
- data/lib/capsule_crm/custom_field.rb +5 -8
- data/lib/capsule_crm/history.rb +11 -11
- data/lib/capsule_crm/opportunity.rb +5 -7
- data/lib/capsule_crm/organization.rb +6 -7
- data/lib/capsule_crm/participant.rb +0 -4
- data/lib/capsule_crm/party.rb +1 -1
- data/lib/capsule_crm/person.rb +6 -7
- data/lib/capsule_crm/serializer.rb +56 -0
- data/lib/capsule_crm/task.rb +7 -5
- data/lib/capsule_crm/track.rb +1 -1
- data/lib/capsule_crm/user.rb +5 -1
- data/lib/capsule_crm/version.rb +1 -1
- data/lib/capsule_crm.rb +1 -0
- data/spec/fabricators/custom_field_fabricator.rb +7 -0
- data/spec/lib/capsule_crm/associations/belongs_to_association_spec.rb +78 -0
- data/spec/lib/capsule_crm/associations/has_many_association_spec.rb +84 -0
- data/spec/lib/capsule_crm/associations/has_many_proxy_spec.rb +2 -2
- data/spec/lib/capsule_crm/associations_spec.rb +46 -0
- data/spec/lib/capsule_crm/custom_field_spec.rb +20 -597
- data/spec/lib/capsule_crm/history_spec.rb +8 -9
- data/spec/lib/capsule_crm/person_spec.rb +0 -16
- data/spec/lib/capsule_crm/serializer_spec.rb +103 -0
- data/spec/lib/capsule_crm/task_spec.rb +6 -14
- metadata +15 -2
@@ -17,7 +17,6 @@ describe CapsuleCRM::CustomField do
|
|
17
17
|
|
18
18
|
describe '._for_party' do
|
19
19
|
let(:party) { Fabricate.build(:organization, id: 1) }
|
20
|
-
|
21
20
|
subject { CapsuleCRM::CustomField._for_party(party.id) }
|
22
21
|
|
23
22
|
context 'when there are some custom fields' do
|
@@ -27,7 +26,6 @@ describe CapsuleCRM::CustomField do
|
|
27
26
|
end
|
28
27
|
|
29
28
|
it { should be_an(Array) }
|
30
|
-
|
31
29
|
it do
|
32
30
|
subject.all? { |item| item.is_a?(CapsuleCRM::CustomField) }.should be_true
|
33
31
|
end
|
@@ -46,613 +44,38 @@ describe CapsuleCRM::CustomField do
|
|
46
44
|
describe '.create' do
|
47
45
|
context 'when it belongs to a party' do
|
48
46
|
let(:organization) { Fabricate.build(:organization, id: 1) }
|
49
|
-
let(:location)
|
50
|
-
|
47
|
+
let(:location) do
|
48
|
+
'https://sample.capsulecrm.com/api/party/#{organization.id}/customfields'
|
49
|
+
end
|
51
50
|
subject do
|
52
51
|
CapsuleCRM::CustomField.create(
|
53
|
-
id: 100,
|
54
|
-
|
55
|
-
label: 'A field',
|
56
|
-
text: 'Some text',
|
57
|
-
date: Date.today,
|
58
|
-
boolean: true,
|
59
|
-
party: organization
|
52
|
+
id: 100, tag: 'The tag', label: 'A field', text: 'Some text',
|
53
|
+
date: Date.today, boolean: true, party: organization
|
60
54
|
)
|
61
55
|
end
|
62
|
-
|
63
56
|
before do
|
64
57
|
stub_request(:post, /\/api\/party\/#{organization.id}\/customfields$/).
|
65
58
|
to_return(headers: { 'Location' => location})
|
66
59
|
end
|
67
60
|
|
68
|
-
it { subject.id.
|
61
|
+
it { expect(subject.id).to eql(100) }
|
69
62
|
end
|
70
63
|
end
|
71
|
-
end
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
# describe '.create' do
|
77
|
-
# context 'when it belongs to a party' do
|
78
|
-
# let(:person) { Fabricate.build(:person, id: 1) }
|
79
|
-
|
80
|
-
# subject do
|
81
|
-
# CapsuleCRM::History.create(
|
82
|
-
# note: Faker::Lorem.paragraph, party: person
|
83
|
-
# )
|
84
|
-
# end
|
85
|
-
|
86
|
-
# let(:location) do
|
87
|
-
# "https://sample.capsulecrm.com/api/party/#{person.id}/history/101"
|
88
|
-
# end
|
89
|
-
|
90
|
-
# before do
|
91
|
-
# stub_request(:post, /\/api\/party\/#{person.id}\/history$/).
|
92
|
-
# to_return(headers: { 'Location' => location})
|
93
|
-
# end
|
94
|
-
|
95
|
-
# it { subject.id.should eql(101) }
|
96
|
-
# end
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
####
|
101
|
-
|
102
|
-
|
103
|
-
# describe 'find' do
|
104
|
-
# before do
|
105
|
-
# stub_request(:get, /\/api\/history\/100$/).
|
106
|
-
# to_return(body: File.read('spec/support/history.json'))
|
107
|
-
# stub_request(:get, /\/api\/users$/).
|
108
|
-
# to_return(body: File.read('spec/support/all_users.json'))
|
109
|
-
# end
|
110
|
-
|
111
|
-
# subject { CapsuleCRM::History.find(100) }
|
112
|
-
|
113
|
-
# it { subject.type.should eql('Note') }
|
114
|
-
|
115
|
-
# it { subject.creator.should be_a(CapsuleCRM::User) }
|
116
|
-
|
117
|
-
# it { subject.entry_date.should_not be_blank }
|
118
|
-
|
119
|
-
# it { subject.subject.should_not be_blank }
|
120
|
-
|
121
|
-
# it { subject.note.should_not be_blank }
|
122
|
-
|
123
|
-
# it { subject.attachments.should be_a(Array) }
|
124
|
-
|
125
|
-
# it { subject.attachments.first.should be_a(CapsuleCRM::Attachment) }
|
126
|
-
|
127
|
-
# it { subject.attachments.first.filename.should eql('latin.doc') }
|
128
|
-
|
129
|
-
# it { subject.participants.should be_a(Array) }
|
130
|
-
|
131
|
-
# it { subject.participants.first.should be_a(CapsuleCRM::Participant) }
|
132
|
-
|
133
|
-
# it { subject.participants.first.name.should eql('Matt Beedle') }
|
134
|
-
|
135
|
-
# context 'when it belongs to a party' do
|
136
|
-
# before do
|
137
|
-
# stub_request(:get, /\/api\/party\/1$/).
|
138
|
-
# to_return(body: File.read('spec/support/person.json'))
|
139
|
-
# end
|
140
|
-
|
141
|
-
# it { subject.party_id.should_not be_blank }
|
142
|
-
|
143
|
-
# it { subject.party.should_not be_blank }
|
144
|
-
# end
|
145
|
-
|
146
|
-
# context 'when it belongs to a case' do
|
147
|
-
# before do
|
148
|
-
# stub_request(:get, /\/api\/kase\/5$/).
|
149
|
-
# to_return(body: File.read('spec/support/case.json'))
|
150
|
-
# end
|
151
|
-
|
152
|
-
# it { subject.case_id.should_not be_blank }
|
153
|
-
|
154
|
-
# it { subject.kase.should_not be_blank }
|
155
|
-
# end
|
156
|
-
|
157
|
-
# context 'when it belongs to an opportunity' do
|
158
|
-
# before do
|
159
|
-
# stub_request(:get, /\/api\/opportunity\/2$/).
|
160
|
-
# to_return(body: File.read('spec/support/opportunity.json'))
|
161
|
-
# end
|
162
|
-
|
163
|
-
# it { subject.opportunity_id.should_not be_blank }
|
164
|
-
|
165
|
-
# it { subject.opportunity.should_not be_blank }
|
166
|
-
# end
|
167
|
-
# end
|
168
|
-
|
169
|
-
# describe '#creator=' do
|
170
|
-
# let(:history) { CapsuleCRM::History.new }
|
171
|
-
|
172
|
-
# context 'when a String is supplied' do
|
173
|
-
# before do
|
174
|
-
# stub_request(:get, /\/api\/users$/).
|
175
|
-
# to_return(body: File.read('spec/support/all_users.json'))
|
176
|
-
# end
|
177
|
-
|
178
|
-
# context 'when the user exists' do
|
179
|
-
# before { history.creator = 'a.user' }
|
180
|
-
|
181
|
-
# it { history.creator.should be_a(CapsuleCRM::User) }
|
182
|
-
# end
|
183
|
-
|
184
|
-
# context 'when the user does not exist' do
|
185
|
-
# before { history.creator = 'asdfadsfdsaf' }
|
186
|
-
|
187
|
-
# it { history.creator.should be_blank }
|
188
|
-
# end
|
189
|
-
# end
|
190
|
-
|
191
|
-
# context 'when a CapsuleCRM::Person is supplied' do
|
192
|
-
# let(:user) { CapsuleCRM::User.new }
|
193
|
-
|
194
|
-
# before { history.creator = user }
|
195
|
-
|
196
|
-
# it { history.creator.should eql(user) }
|
197
|
-
# end
|
198
|
-
# end
|
199
|
-
|
200
|
-
# describe '.create' do
|
201
|
-
# context 'when it belongs to a party' do
|
202
|
-
# let(:person) { Fabricate.build(:person, id: 1) }
|
203
|
-
|
204
|
-
# subject do
|
205
|
-
# CapsuleCRM::History.create(
|
206
|
-
# note: Faker::Lorem.paragraph, party: person
|
207
|
-
# )
|
208
|
-
# end
|
209
|
-
|
210
|
-
# let(:location) do
|
211
|
-
# "https://sample.capsulecrm.com/api/party/#{person.id}/history/101"
|
212
|
-
# end
|
213
|
-
|
214
|
-
# before do
|
215
|
-
# stub_request(:post, /\/api\/party\/#{person.id}\/history$/).
|
216
|
-
# to_return(headers: { 'Location' => location})
|
217
|
-
# end
|
218
|
-
|
219
|
-
# it { subject.id.should eql(101) }
|
220
|
-
# end
|
221
|
-
|
222
|
-
# context 'when it belongs to a kase' do
|
223
|
-
# let(:kase) { Fabricate.build(:case, id: 2) }
|
224
|
-
|
225
|
-
# let(:location) do
|
226
|
-
# "https://sample.capsulecrm.com/api/kase/#{kase.id}/history/10"
|
227
|
-
# end
|
228
|
-
|
229
|
-
# subject do
|
230
|
-
# CapsuleCRM::History.create(note: Faker::Lorem.paragraph, kase: kase)
|
231
|
-
# end
|
232
|
-
|
233
|
-
# before do
|
234
|
-
# stub_request(:post, /\/api\/kase\/#{kase.id}\/history$/).
|
235
|
-
# to_return(headers: { 'Location' => location })
|
236
|
-
# end
|
237
|
-
|
238
|
-
# it { subject.id.should eql(10) }
|
239
|
-
# end
|
240
|
-
|
241
|
-
# context 'when it belongs to an opportunity' do
|
242
|
-
# let(:opportunity) { Fabricate.build(:opportunity, id: 1) }
|
243
|
-
|
244
|
-
# subject do
|
245
|
-
# CapsuleCRM::History.create(
|
246
|
-
# note: Faker::Lorem.paragraph, opportunity: opportunity
|
247
|
-
# )
|
248
|
-
# end
|
249
|
-
|
250
|
-
# let(:location) do
|
251
|
-
# [
|
252
|
-
# 'https://sample.capsulecrm.com/api/opportunity/',
|
253
|
-
# opportunity.id, '/history/9'
|
254
|
-
# ].join
|
255
|
-
# end
|
256
|
-
|
257
|
-
# before do
|
258
|
-
# stub_request(:post, /\/api\/opportunity\/#{opportunity.id}\/history$/).
|
259
|
-
# to_return(headers: { 'Location' => location })
|
260
|
-
# end
|
261
|
-
|
262
|
-
# it { subject.id.should eql(9) }
|
263
|
-
# end
|
264
|
-
|
265
|
-
# context 'when it is invalid' do
|
266
|
-
# subject { CapsuleCRM::History.create }
|
267
|
-
|
268
|
-
# it { should_not be_valid }
|
269
|
-
# end
|
270
|
-
# end
|
271
|
-
|
272
|
-
# describe '.create!' do
|
273
|
-
# context 'when it belongs to a party' do
|
274
|
-
# let(:person) { Fabricate.build(:person, id: 1) }
|
275
|
-
|
276
|
-
# subject do
|
277
|
-
# CapsuleCRM::History.create!(
|
278
|
-
# note: Faker::Lorem.paragraph, party: person
|
279
|
-
# )
|
280
|
-
# end
|
281
|
-
|
282
|
-
# let(:location) do
|
283
|
-
# "https://sample.capsulecrm.com/api/party/#{person.id}/history/101"
|
284
|
-
# end
|
285
|
-
|
286
|
-
# before do
|
287
|
-
# stub_request(:post, /\/api\/party\/#{person.id}\/history$/).
|
288
|
-
# to_return(headers: { 'Location' => location})
|
289
|
-
# end
|
290
|
-
|
291
|
-
# it { subject.id.should eql(101) }
|
292
|
-
# end
|
293
|
-
|
294
|
-
# context 'when it belongs to a kase' do
|
295
|
-
# let(:kase) { Fabricate.build(:case, id: 2) }
|
296
|
-
|
297
|
-
# let(:location) do
|
298
|
-
# "https://sample.capsulecrm.com/api/kase/#{kase.id}/history/10"
|
299
|
-
# end
|
300
|
-
|
301
|
-
# subject do
|
302
|
-
# CapsuleCRM::History.create!(note: Faker::Lorem.paragraph, kase: kase)
|
303
|
-
# end
|
304
|
-
|
305
|
-
# before do
|
306
|
-
# stub_request(:post, /\/api\/kase\/#{kase.id}\/history$/).
|
307
|
-
# to_return(headers: { 'Location' => location })
|
308
|
-
# end
|
309
|
-
|
310
|
-
# it { subject.id.should eql(10) }
|
311
|
-
# end
|
312
|
-
|
313
|
-
# context 'when it belongs to an opportunity' do
|
314
|
-
# let(:opportunity) { Fabricate.build(:opportunity, id: 1) }
|
315
|
-
|
316
|
-
# subject do
|
317
|
-
# CapsuleCRM::History.create!(
|
318
|
-
# note: Faker::Lorem.paragraph, opportunity: opportunity
|
319
|
-
# )
|
320
|
-
# end
|
321
|
-
|
322
|
-
# let(:location) do
|
323
|
-
# [
|
324
|
-
# 'https://sample.capsulecrm.com/api/opportunity/',
|
325
|
-
# opportunity.id, '/history/9'
|
326
|
-
# ].join
|
327
|
-
# end
|
328
|
-
|
329
|
-
# before do
|
330
|
-
# stub_request(:post, /\/api\/opportunity\/#{opportunity.id}\/history$/).
|
331
|
-
# to_return(headers: { 'Location' => location })
|
332
|
-
# end
|
333
|
-
|
334
|
-
# it { subject.id.should eql(9) }
|
335
|
-
# end
|
336
|
-
|
337
|
-
# context 'when it is invalid' do
|
338
|
-
# it do
|
339
|
-
# expect { CapsuleCRM::History.create! }.
|
340
|
-
# to raise_error(CapsuleCRM::Errors::RecordInvalid)
|
341
|
-
# end
|
342
|
-
# end
|
343
|
-
# end
|
344
64
|
|
345
|
-
|
346
|
-
|
347
|
-
|
65
|
+
describe '#to_capsule_json' do
|
66
|
+
let(:custom_field) { Fabricate.build(:custom_field) }
|
67
|
+
subject { custom_field.to_capsule_json }
|
348
68
|
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
# end
|
353
|
-
|
354
|
-
# it { subject.note.should eql('changed note text') }
|
355
|
-
|
356
|
-
# it { should be_persisted }
|
357
|
-
# end
|
358
|
-
|
359
|
-
# context 'when the history is not valid' do
|
360
|
-
# subject do
|
361
|
-
# CapsuleCRM::History.new(id: 2)
|
362
|
-
# end
|
363
|
-
|
364
|
-
# before { subject.update_attributes subject: Faker::Lorem.sentence }
|
365
|
-
|
366
|
-
# it { subject.should_not be_valid }
|
367
|
-
# end
|
368
|
-
# end
|
369
|
-
|
370
|
-
# describe '#update_attributes!' do
|
371
|
-
# context 'when it is valid' do
|
372
|
-
# subject { Fabricate(:history, id: 3, party: Fabricate.build(:case)) }
|
373
|
-
|
374
|
-
# before do
|
375
|
-
# stub_request(:put, /api\/history\/3$/).to_return(status: 200)
|
376
|
-
# subject.update_attributes! note: 'some new note'
|
377
|
-
# end
|
378
|
-
|
379
|
-
# it { subject.note.should eql('some new note') }
|
380
|
-
|
381
|
-
# it { should be_persisted }
|
382
|
-
# end
|
383
|
-
|
384
|
-
# context 'when it is not valid' do
|
385
|
-
# subject { CapsuleCRM::History.new(id: 3) }
|
386
|
-
|
387
|
-
# it do
|
388
|
-
# expect { subject.update_attributes! subject: 'test' }.
|
389
|
-
# to raise_error(CapsuleCRM::Errors::RecordInvalid)
|
390
|
-
# end
|
391
|
-
# end
|
392
|
-
# end
|
393
|
-
|
394
|
-
# describe '#save' do
|
395
|
-
# context 'when it is a new record' do
|
396
|
-
# let(:history) { Fabricate.build(:history) }
|
397
|
-
|
398
|
-
# context 'when it belongs to a party' do
|
399
|
-
# let(:party) { Fabricate.build(:organization, id: 2) }
|
400
|
-
|
401
|
-
# let(:location) do
|
402
|
-
# "https://sample.capsulecrm.com/api/party/#{party.id}/history/101"
|
403
|
-
# end
|
404
|
-
|
405
|
-
# before do
|
406
|
-
# history.party = party
|
407
|
-
# stub_request(:post, /\/api\/party\/#{party.id}\/history$/).
|
408
|
-
# to_return(headers: { 'Location' => location })
|
409
|
-
# history.save
|
410
|
-
# end
|
411
|
-
|
412
|
-
# it { history.id.should eql(101) }
|
413
|
-
|
414
|
-
# it { history.should be_persisted }
|
415
|
-
# end
|
416
|
-
|
417
|
-
# context 'when it belongs to a kase' do
|
418
|
-
# let(:kase) { Fabricate.build(:case, id: 5) }
|
419
|
-
|
420
|
-
# let(:location) do
|
421
|
-
# "https://sample.capsulecrm.com/api/kase/#{kase.id}/history/10005"
|
422
|
-
# end
|
423
|
-
|
424
|
-
# before do
|
425
|
-
# history.kase = kase
|
426
|
-
# stub_request(:post, /\/api\/kase\/#{kase.id}\/history$/).
|
427
|
-
# to_return(headers: { 'Location' => location })
|
428
|
-
# history.save
|
429
|
-
# end
|
430
|
-
|
431
|
-
# it { history.id.should eql(10005) }
|
432
|
-
|
433
|
-
# it { history.should be_persisted }
|
434
|
-
# end
|
435
|
-
|
436
|
-
# context 'when it belongs to an opportunity' do
|
437
|
-
# let(:opportunity) { Fabricate.build(:opportunity, id: 3) }
|
438
|
-
|
439
|
-
# let(:location) do
|
440
|
-
# [
|
441
|
-
# 'https://sample.capsulecrm.com/api/opportunity/',
|
442
|
-
# opportunity.id, '/history/101'
|
443
|
-
# ].join
|
444
|
-
# end
|
445
|
-
|
446
|
-
# before do
|
447
|
-
# history.opportunity = opportunity
|
448
|
-
# stub_request(
|
449
|
-
# :post, /\/api\/opportunity\/#{opportunity.id}\/history$/
|
450
|
-
# ).to_return(headers: { 'Location' => location })
|
451
|
-
# history.save
|
452
|
-
# end
|
453
|
-
|
454
|
-
# it { history.id.should eql(101) }
|
455
|
-
|
456
|
-
# it { history.should be_persisted }
|
457
|
-
# end
|
458
|
-
# end
|
459
|
-
|
460
|
-
# context 'when it is an existing record' do
|
461
|
-
# let(:history) do
|
462
|
-
# Fabricate.build(:history, party: Fabricate.build(:person), id: 10)
|
463
|
-
# end
|
464
|
-
|
465
|
-
# before do
|
466
|
-
# stub_request(:put, /\/api\/history\/#{history.id}$/).
|
467
|
-
# to_return(status: 200)
|
468
|
-
# history.save
|
469
|
-
# end
|
470
|
-
|
471
|
-
# it { history.should be_persisted }
|
472
|
-
# end
|
473
|
-
# end
|
474
|
-
|
475
|
-
# describe '#save!' do
|
476
|
-
# context 'when it is a new record' do
|
477
|
-
# context 'when it is invalid' do
|
478
|
-
# let(:history) { CapsuleCRM::History.new(id: 5) }
|
479
|
-
|
480
|
-
# it 'should raise an error' do
|
481
|
-
# expect { history.save! }.
|
482
|
-
# to raise_error(CapsuleCRM::Errors::RecordInvalid)
|
483
|
-
# end
|
484
|
-
# end
|
485
|
-
|
486
|
-
# let(:history) { Fabricate.build(:history) }
|
487
|
-
|
488
|
-
# context 'when it belongs to a party' do
|
489
|
-
# let(:party) { Fabricate.build(:organization, id: 2) }
|
490
|
-
|
491
|
-
# let(:location) do
|
492
|
-
# "https://sample.capsulecrm.com/api/party/#{party.id}/history/101"
|
493
|
-
# end
|
494
|
-
|
495
|
-
# before do
|
496
|
-
# history.party = party
|
497
|
-
# stub_request(:post, /\/api\/party\/#{party.id}\/history$/).
|
498
|
-
# to_return(headers: { 'Location' => location })
|
499
|
-
# history.save!
|
500
|
-
# end
|
501
|
-
|
502
|
-
# it { history.id.should eql(101) }
|
503
|
-
|
504
|
-
# it { history.should be_persisted }
|
505
|
-
# end
|
506
|
-
|
507
|
-
# context 'when it belongs to a kase' do
|
508
|
-
# let(:kase) { Fabricate.build(:case, id: 5) }
|
509
|
-
|
510
|
-
# let(:location) do
|
511
|
-
# "https://sample.capsulecrm.com/api/kase/#{kase.id}/history/10005"
|
512
|
-
# end
|
513
|
-
|
514
|
-
# before do
|
515
|
-
# history.kase = kase
|
516
|
-
# stub_request(:post, /\/api\/kase\/#{kase.id}\/history$/).
|
517
|
-
# to_return(headers: { 'Location' => location })
|
518
|
-
# history.save!
|
519
|
-
# end
|
520
|
-
|
521
|
-
# it { history.id.should eql(10005) }
|
522
|
-
|
523
|
-
# it { history.should be_persisted }
|
524
|
-
# end
|
525
|
-
|
526
|
-
# context 'when it belongs to an opportunity' do
|
527
|
-
# let(:opportunity) { Fabricate.build(:opportunity, id: 3) }
|
528
|
-
|
529
|
-
# let(:location) do
|
530
|
-
# [
|
531
|
-
# 'https://sample.capsulecrm.com/api/opportunity/',
|
532
|
-
# opportunity.id, '/history/101'
|
533
|
-
# ].join
|
534
|
-
# end
|
535
|
-
|
536
|
-
# before do
|
537
|
-
# history.opportunity = opportunity
|
538
|
-
# stub_request(
|
539
|
-
# :post, /\/api\/opportunity\/#{opportunity.id}\/history$/
|
540
|
-
# ).to_return(headers: { 'Location' => location })
|
541
|
-
# history.save!
|
542
|
-
# end
|
543
|
-
|
544
|
-
# it { history.id.should eql(101) }
|
545
|
-
|
546
|
-
# it { history.should be_persisted }
|
547
|
-
# end
|
548
|
-
# end
|
549
|
-
|
550
|
-
# context 'when it is an existing record' do
|
551
|
-
# context 'when it is valid' do
|
552
|
-
# let(:history) do
|
553
|
-
# Fabricate.build(:history, party: Fabricate.build(:person), id: 10)
|
554
|
-
# end
|
555
|
-
|
556
|
-
# before do
|
557
|
-
# stub_request(:put, /\/api\/history\/#{history.id}$/).
|
558
|
-
# to_return(status: 200)
|
559
|
-
# history.save!
|
560
|
-
# end
|
561
|
-
|
562
|
-
# it { history.should be_persisted }
|
563
|
-
# end
|
564
|
-
|
565
|
-
# context 'when it is not valid' do
|
566
|
-
# let(:history) { CapsuleCRM::History.new(id: 1) }
|
567
|
-
|
568
|
-
# it 'should raise an error' do
|
569
|
-
# expect { history.save! }.
|
570
|
-
# to raise_error(CapsuleCRM::Errors::RecordInvalid)
|
571
|
-
# end
|
572
|
-
# end
|
573
|
-
# end
|
574
|
-
# end
|
575
|
-
|
576
|
-
# describe '#destroy' do
|
577
|
-
# let(:history) { Fabricate.build(:history, id: 19) }
|
578
|
-
|
579
|
-
# before do
|
580
|
-
# stub_request(:delete, /\/api\/history\/#{history.id}$/).
|
581
|
-
# to_return(status: 200)
|
582
|
-
# history.destroy
|
583
|
-
# end
|
584
|
-
|
585
|
-
# subject { history }
|
586
|
-
|
587
|
-
# it { should_not be_persisted }
|
588
|
-
# end
|
589
|
-
|
590
|
-
# describe '#new_record?' do
|
591
|
-
# context 'when the history item is a new record' do
|
592
|
-
# let(:history) { CapsuleCRM::History.new }
|
593
|
-
|
594
|
-
# subject { history.new_record? }
|
595
|
-
|
596
|
-
# it { should be_true }
|
597
|
-
# end
|
598
|
-
|
599
|
-
# context 'when the history item is not a new record' do
|
600
|
-
# let(:history) { CapsuleCRM::History.new(id: 1) }
|
601
|
-
|
602
|
-
# subject { history.new_record? }
|
603
|
-
|
604
|
-
# it { should be_false }
|
605
|
-
# end
|
606
|
-
# end
|
607
|
-
|
608
|
-
# describe '#persisted?' do
|
609
|
-
# context 'when the history item is persisted' do
|
610
|
-
# let(:history) { CapsuleCRM::History.new(id: 1) }
|
611
|
-
|
612
|
-
# subject { history.persisted? }
|
613
|
-
|
614
|
-
# it { should be_true }
|
615
|
-
# end
|
616
|
-
|
617
|
-
# context 'when the hitory item is not persisted' do
|
618
|
-
# let(:history) { CapsuleCRM::History.new }
|
619
|
-
|
620
|
-
# subject { history.persisted? }
|
621
|
-
|
622
|
-
# it { should be_false }
|
623
|
-
# end
|
624
|
-
# end
|
625
|
-
|
626
|
-
# describe '#to_capsule_json' do
|
627
|
-
# let(:creator) { CapsuleCRM::User.new(username: Faker::Name.name) }
|
628
|
-
|
629
|
-
# let(:history) do
|
630
|
-
# CapsuleCRM::History.new(
|
631
|
-
# type: 'Note', entry_date: Time.now, creator: creator,
|
632
|
-
# subject: Faker::Lorem.sentence, note: Faker::Lorem.paragraph,
|
633
|
-
# participants: [participant]
|
634
|
-
# )
|
635
|
-
# end
|
636
|
-
|
637
|
-
# let(:participant) do
|
638
|
-
# CapsuleCRM::Participant.new(
|
639
|
-
# name: Faker::Name.name, email_address: Faker::Internet.email,
|
640
|
-
# role: 'TO'
|
641
|
-
# )
|
642
|
-
# end
|
643
|
-
|
644
|
-
# subject { history.to_capsule_json }
|
645
|
-
|
646
|
-
# let(:participants_json) { subject[:historyItem]['participants'] }
|
647
|
-
|
648
|
-
# it { subject.keys.first.should eql(:historyItem) }
|
649
|
-
|
650
|
-
# it { subject[:historyItem]['entryDate'].should eql(history.entry_date) }
|
651
|
-
|
652
|
-
# it { subject[:historyItem]['creator'].should eql(creator.username) }
|
69
|
+
it 'should be a hash' do
|
70
|
+
expect(subject).to be_a(Hash)
|
71
|
+
end
|
653
72
|
|
654
|
-
|
73
|
+
it 'should have a root element of "customField"' do
|
74
|
+
expect(subject.keys.first).to eql('customFields')
|
75
|
+
end
|
655
76
|
|
656
|
-
|
657
|
-
|
658
|
-
|
77
|
+
it 'should have an element named "customField"' do
|
78
|
+
expect(subject['customFields'].keys.first).to eql('customField')
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
@@ -616,14 +616,13 @@ describe CapsuleCRM::History do
|
|
616
616
|
let(:participants_json) { subject[:historyItem]['participants'] }
|
617
617
|
subject { history.to_capsule_json }
|
618
618
|
|
619
|
-
it { expect(subject.keys.first).to eql(
|
620
|
-
|
621
|
-
|
622
|
-
|
623
|
-
|
624
|
-
|
625
|
-
it { expect(subject[
|
626
|
-
|
627
|
-
it { expect(subject[:historyItem]).to have_key('note') }
|
619
|
+
it { expect(subject.keys.first).to eql('historyItem') }
|
620
|
+
it do
|
621
|
+
expect(subject['historyItem']['entryDate']).
|
622
|
+
to eql(history.entry_date.strftime("%Y-%m-%dT%H:%M:%SZ"))
|
623
|
+
end
|
624
|
+
it { expect(subject['historyItem']['creator']).to eql(creator.username) }
|
625
|
+
it { expect(subject['historyItem']['note']).to eql(history.note) }
|
626
|
+
it { expect(subject['historyItem']).to have_key('note') }
|
628
627
|
end
|
629
628
|
end
|