capsule_crm 1.2.0 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +15 -0
- data/lib/capsule_crm/address.rb +4 -3
- data/lib/capsule_crm/associations/belongs_to.rb +2 -1
- data/lib/capsule_crm/associations/belongs_to_association.rb +19 -2
- data/lib/capsule_crm/associations/belongs_to_finder.rb +46 -0
- data/lib/capsule_crm/associations/has_many_association.rb +23 -9
- data/lib/capsule_crm/associations/has_many_proxy.rb +38 -4
- data/lib/capsule_crm/case.rb +33 -236
- data/lib/capsule_crm/configuration.rb +1 -1
- data/lib/capsule_crm/connection.rb +3 -0
- data/lib/capsule_crm/contactable.rb +1 -1
- data/lib/capsule_crm/country.rb +7 -13
- data/lib/capsule_crm/currency.rb +7 -13
- data/lib/capsule_crm/custom_field.rb +14 -54
- data/lib/capsule_crm/custom_field_definition.rb +36 -0
- data/lib/capsule_crm/email.rb +4 -3
- data/lib/capsule_crm/gettable.rb +11 -0
- data/lib/capsule_crm/hash_helper.rb +5 -0
- data/lib/capsule_crm/history.rb +37 -252
- data/lib/capsule_crm/milestone.rb +9 -9
- data/lib/capsule_crm/normalizer.rb +85 -0
- data/lib/capsule_crm/opportunity.rb +30 -271
- data/lib/capsule_crm/organization.rb +19 -197
- data/lib/capsule_crm/party.rb +13 -26
- data/lib/capsule_crm/persistence/configuration.rb +25 -0
- data/lib/capsule_crm/persistence/deletable.rb +14 -0
- data/lib/capsule_crm/persistence/persistable.rb +76 -0
- data/lib/capsule_crm/persistence.rb +3 -0
- data/lib/capsule_crm/person.rb +19 -194
- data/lib/capsule_crm/phone.rb +4 -3
- data/lib/capsule_crm/querying/configuration.rb +21 -0
- data/lib/capsule_crm/querying/find_all.rb +16 -0
- data/lib/capsule_crm/querying/find_one.rb +14 -0
- data/lib/capsule_crm/querying/findable.rb +14 -0
- data/lib/capsule_crm/querying.rb +4 -0
- data/lib/capsule_crm/serializable.rb +38 -0
- data/lib/capsule_crm/serializer.rb +54 -7
- data/lib/capsule_crm/task.rb +16 -96
- data/lib/capsule_crm/track.rb +5 -10
- data/lib/capsule_crm/user.rb +3 -15
- data/lib/capsule_crm/version.rb +1 -1
- data/lib/capsule_crm/website.rb +4 -2
- data/lib/capsule_crm.rb +15 -5
- data/spec/fabricators/case_fabricator.rb +1 -0
- data/spec/fabricators/history_fabricator.rb +1 -0
- data/spec/fabricators/opportunity_fabricator.rb +1 -0
- data/spec/lib/capsule_crm/associations/belongs_to_finder_spec.rb +48 -0
- data/spec/lib/capsule_crm/associations/belongs_to_spec.rb +34 -0
- data/spec/lib/capsule_crm/associations/has_many_proxy_spec.rb +54 -14
- data/spec/lib/capsule_crm/associations/has_many_spec.rb +15 -2
- data/spec/lib/capsule_crm/case_spec.rb +20 -330
- data/spec/lib/capsule_crm/country_spec.rb +1 -16
- data/spec/lib/capsule_crm/currency_spec.rb +1 -18
- data/spec/lib/capsule_crm/custom_field_definition_spec.rb +59 -0
- data/spec/lib/capsule_crm/custom_field_spec.rb +2 -27
- data/spec/lib/capsule_crm/history_spec.rb +14 -389
- data/spec/lib/capsule_crm/milestone_spec.rb +1 -23
- data/spec/lib/capsule_crm/normalizer_spec.rb +11 -0
- data/spec/lib/capsule_crm/opportunity_spec.rb +22 -341
- data/spec/lib/capsule_crm/organization_spec.rb +39 -60
- data/spec/lib/capsule_crm/party_spec.rb +37 -59
- data/spec/lib/capsule_crm/person_spec.rb +49 -247
- data/spec/lib/capsule_crm/serializer_spec.rb +25 -4
- data/spec/lib/capsule_crm/task_spec.rb +21 -250
- data/spec/lib/capsule_crm/track_spec.rb +1 -15
- data/spec/lib/capsule_crm/user_spec.rb +1 -14
- data/spec/support/{countries.json → all_countries.json} +0 -0
- data/spec/support/{currencies.json → all_currencies.json} +0 -0
- data/spec/support/{milestones.json → all_milestones.json} +0 -0
- data/spec/support/{tracks.json → all_tracks.json} +0 -0
- data/spec/support/custom_field_definitions.json +19 -0
- data/spec/support/helpers.rb +3 -2
- data/spec/support/no_cases.json +5 -0
- data/spec/support/no_countries.json +5 -0
- data/spec/support/no_currencies.json +5 -0
- data/spec/support/no_milestones.json +5 -0
- data/spec/support/no_opportunities.json +5 -0
- data/spec/support/no_tasks.json +5 -0
- data/spec/support/no_tracks.json +5 -0
- data/spec/support/no_users.json +5 -0
- data/spec/support/shared_examples/deletable.rb +15 -0
- data/spec/support/shared_examples/find_all.rb +34 -0
- data/spec/support/shared_examples/find_one.rb +23 -0
- data/spec/support/shared_examples/persistable.rb +318 -0
- data/spec/support/single_person.json +16 -0
- metadata +60 -15
- data/lib/capsule_crm/attributes.rb +0 -11
- data/lib/capsule_crm/capsule_jsonable.rb +0 -13
- data/lib/capsule_crm/collection.rb +0 -9
- data/spec/support/single_user.json +0 -25
@@ -5,7 +5,7 @@ describe CapsuleCRM::Opportunity do
|
|
5
5
|
|
6
6
|
before do
|
7
7
|
stub_request(:get, /\/api\/opportunity\/milestones$/).
|
8
|
-
to_return(body: File.read('spec/support/
|
8
|
+
to_return(body: File.read('spec/support/all_milestones.json'))
|
9
9
|
end
|
10
10
|
|
11
11
|
before do
|
@@ -13,6 +13,27 @@ describe CapsuleCRM::Opportunity do
|
|
13
13
|
to_return(body: File.read('spec/support/all_users.json'))
|
14
14
|
end
|
15
15
|
|
16
|
+
it_behaves_like 'persistable', 'https://sample.capsulecrm.com/api/opportunity/59', 59 do
|
17
|
+
let(:attributes) do
|
18
|
+
Fabricate.attributes_for(:opportunity).merge(party: party)
|
19
|
+
end
|
20
|
+
let(:party) { Fabricate.build(:person, id: Random.rand(1..10)) }
|
21
|
+
end
|
22
|
+
|
23
|
+
it_behaves_like 'deletable'
|
24
|
+
|
25
|
+
it_behaves_like 'listable', '/opportunity', 'opportunities', 1
|
26
|
+
|
27
|
+
it_behaves_like 'findable', '/api/opportunity/1', 1, 'opportunity' do
|
28
|
+
let(:attributes) do
|
29
|
+
{
|
30
|
+
value: 500.0, id: 43, duration_basis: 'DAY', milestone_id: 2,
|
31
|
+
duration: 10, currency: 'GBP',
|
32
|
+
description: 'Scope and design web site shopping cart'
|
33
|
+
}
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
16
37
|
describe 'validations' do
|
17
38
|
subject { described_class.new }
|
18
39
|
|
@@ -136,346 +157,6 @@ describe CapsuleCRM::Opportunity do
|
|
136
157
|
end
|
137
158
|
end
|
138
159
|
|
139
|
-
describe '.all' do
|
140
|
-
before do
|
141
|
-
stub_request(:get, /\/api\/opportunity$/).
|
142
|
-
to_return(body: File.read('spec/support/all_opportunities.json'))
|
143
|
-
end
|
144
|
-
|
145
|
-
subject { CapsuleCRM::Opportunity.all }
|
146
|
-
|
147
|
-
it { should be_a(Array) }
|
148
|
-
|
149
|
-
it { subject.length.should eql(1) }
|
150
|
-
|
151
|
-
it 'should only contain people' do
|
152
|
-
subject.all? { |item| item.is_a?(CapsuleCRM::Opportunity) }.should be_true
|
153
|
-
end
|
154
|
-
end
|
155
|
-
|
156
|
-
describe '.find' do
|
157
|
-
before do
|
158
|
-
stub_request(:get, /\/api\/opportunity\/1$/).
|
159
|
-
to_return(body: File.read('spec/support/opportunity.json'))
|
160
|
-
end
|
161
|
-
|
162
|
-
subject { CapsuleCRM::Opportunity.find(1) }
|
163
|
-
|
164
|
-
it { should be_a(CapsuleCRM::Opportunity) }
|
165
|
-
|
166
|
-
it { subject.value.should eql(500.0) }
|
167
|
-
|
168
|
-
it { subject.id.should eql(43) }
|
169
|
-
|
170
|
-
it { subject.duration_basis.should eql('DAY') }
|
171
|
-
|
172
|
-
it { subject.milestone_id.should eql(2) }
|
173
|
-
|
174
|
-
it { subject.duration.should eql(10) }
|
175
|
-
|
176
|
-
it { subject.currency.should eql('GBP') }
|
177
|
-
|
178
|
-
it do
|
179
|
-
subject.description.should eql('Scope and design web site shopping cart')
|
180
|
-
end
|
181
|
-
|
182
|
-
it { subject.name.should eql('Consulting') }
|
183
|
-
|
184
|
-
it { subject.owner.should eql('a.user') }
|
185
|
-
|
186
|
-
it { subject.milestone.name.should eql('Bid') }
|
187
|
-
|
188
|
-
it { subject.probability.should eql(50.0) }
|
189
|
-
|
190
|
-
it do
|
191
|
-
subject.expected_close_date.should eql(Date.parse('2012-09-30T00:00:00Z'))
|
192
|
-
end
|
193
|
-
|
194
|
-
it { subject.party_id.should eql(2) }
|
195
|
-
end
|
196
|
-
|
197
|
-
describe '#attributes=' do
|
198
|
-
let(:opportunity) { CapsuleCRM::Opportunity.new }
|
199
|
-
|
200
|
-
before do
|
201
|
-
opportunity.attributes = { partyId: '1', milestoneId: '3' }
|
202
|
-
end
|
203
|
-
|
204
|
-
it { opportunity.party_id.should eql(1) }
|
205
|
-
it { opportunity.milestone_id.should eql(3) }
|
206
|
-
end
|
207
|
-
|
208
|
-
describe '.create' do
|
209
|
-
context 'when the opportunity is valid' do
|
210
|
-
before do
|
211
|
-
stub_request(:post, request_path).to_return(headers: {
|
212
|
-
'Location' => 'https://sample.capsulecrm.com/api/opportunity/59'
|
213
|
-
})
|
214
|
-
end
|
215
|
-
let(:request_path) do
|
216
|
-
[
|
217
|
-
'https://1234:@company.capsulecrm.com/api/party/',
|
218
|
-
opportunity_attributes[:party].id, '/opportunity'
|
219
|
-
].join
|
220
|
-
end
|
221
|
-
let(:party) { Fabricate.build(:person, id: Random.rand(1..10)) }
|
222
|
-
let(:opportunity_attributes) do
|
223
|
-
Fabricate.attributes_for(:opportunity).merge(party: party)
|
224
|
-
end
|
225
|
-
|
226
|
-
subject do
|
227
|
-
CapsuleCRM::Opportunity.create opportunity_attributes
|
228
|
-
end
|
229
|
-
|
230
|
-
it { should be_a(CapsuleCRM::Opportunity) }
|
231
|
-
it { should be_persisted }
|
232
|
-
it { subject.id.should eql(59) }
|
233
|
-
|
234
|
-
context 'when the opportunity has a track' do
|
235
|
-
before do
|
236
|
-
stub_request(:post, "#{request_path}?trackId=#{track.id}").to_return(
|
237
|
-
headers: {
|
238
|
-
'Location' => 'https://sample.capsulecrm.com/api/opportunity/59'
|
239
|
-
}
|
240
|
-
)
|
241
|
-
end
|
242
|
-
|
243
|
-
let(:track) { CapsuleCRM::Track.new(id: rand(10)) }
|
244
|
-
|
245
|
-
subject do
|
246
|
-
CapsuleCRM::Opportunity.
|
247
|
-
create(opportunity_attributes.merge(track: track))
|
248
|
-
end
|
249
|
-
|
250
|
-
it { expect(subject).to be_a(CapsuleCRM::Opportunity) }
|
251
|
-
|
252
|
-
it do
|
253
|
-
subject
|
254
|
-
WebMock.should have_requested(
|
255
|
-
:post, "#{request_path}?trackId=#{track.id}"
|
256
|
-
)
|
257
|
-
end
|
258
|
-
end
|
259
|
-
end
|
260
|
-
|
261
|
-
context 'when the opportunity is not valid' do
|
262
|
-
subject { CapsuleCRM::Opportunity.create }
|
263
|
-
|
264
|
-
it { subject.errors.should_not be_blank }
|
265
|
-
end
|
266
|
-
end
|
267
|
-
|
268
|
-
describe '.create!' do
|
269
|
-
context 'when the opportunity is valid' do
|
270
|
-
before do
|
271
|
-
stub_request(:post, /.*/).to_return(headers: {
|
272
|
-
'Location' => 'https://sample.capsulecrm.com/api/opportunity/71'
|
273
|
-
})
|
274
|
-
end
|
275
|
-
let(:party) { Fabricate.build(:person, id: Random.rand(1..10)) }
|
276
|
-
let(:opportunity_attributes) do
|
277
|
-
Fabricate.attributes_for(:opportunity).merge(party: party)
|
278
|
-
end
|
279
|
-
|
280
|
-
subject do
|
281
|
-
CapsuleCRM::Opportunity.create opportunity_attributes
|
282
|
-
end
|
283
|
-
|
284
|
-
it { should be_a(CapsuleCRM::Opportunity) }
|
285
|
-
it { should be_persisted }
|
286
|
-
it { subject.id.should eql(71) }
|
287
|
-
end
|
288
|
-
|
289
|
-
context 'when the opportunity is not valid' do
|
290
|
-
it do
|
291
|
-
expect { CapsuleCRM::Opportunity.create! }.
|
292
|
-
to raise_error(CapsuleCRM::Errors::RecordInvalid)
|
293
|
-
end
|
294
|
-
end
|
295
|
-
end
|
296
|
-
|
297
|
-
describe '#update_attributes' do
|
298
|
-
context 'when the opportunity is valid' do
|
299
|
-
before do
|
300
|
-
stub_request(:put, /.*/).to_return(status: 200)
|
301
|
-
end
|
302
|
-
|
303
|
-
let(:opportunity) { CapsuleCRM::Opportunity.new(id: 1) }
|
304
|
-
|
305
|
-
before { opportunity.update_attributes name: 'renamed' }
|
306
|
-
|
307
|
-
it { opportunity.name.should eql('renamed') }
|
308
|
-
|
309
|
-
it { opportunity.id.should eql(1) }
|
310
|
-
end
|
311
|
-
|
312
|
-
context 'when the opportunity is not valid' do
|
313
|
-
let(:opportunity) { CapsuleCRM::Opportunity.new(id: 1) }
|
314
|
-
|
315
|
-
before { opportunity.update_attributes }
|
316
|
-
|
317
|
-
it { opportunity.should_not be_valid }
|
318
|
-
|
319
|
-
it { opportunity.errors.should_not be_blank }
|
320
|
-
end
|
321
|
-
end
|
322
|
-
|
323
|
-
describe '#update_attributes!' do
|
324
|
-
|
325
|
-
let(:opportunity) { CapsuleCRM::Opportunity.new(id: 1) }
|
326
|
-
|
327
|
-
context 'when the opportunity is valid' do
|
328
|
-
before do
|
329
|
-
stub_request(:put, /.*/).to_return(status: 200)
|
330
|
-
end
|
331
|
-
|
332
|
-
before { opportunity.update_attributes name: 'A New Name' }
|
333
|
-
|
334
|
-
it { opportunity.name.should eql('A New Name') }
|
335
|
-
|
336
|
-
it { opportunity.id.should eql(1) }
|
337
|
-
end
|
338
|
-
|
339
|
-
context 'when the opportunity is not valid' do
|
340
|
-
it do
|
341
|
-
expect { opportunity.update_attributes! }.
|
342
|
-
to raise_error(CapsuleCRM::Errors::RecordInvalid)
|
343
|
-
end
|
344
|
-
end
|
345
|
-
end
|
346
|
-
|
347
|
-
describe '#save' do
|
348
|
-
context 'when the opportunity is a new record' do
|
349
|
-
before do
|
350
|
-
stub_request(:post, /.*/).to_return(headers: {
|
351
|
-
'Location' => 'https://sample.capsulecrm.com/api/party/100'
|
352
|
-
}, status: 200)
|
353
|
-
end
|
354
|
-
let(:party) { Fabricate.build(:person) }
|
355
|
-
let(:opportunity) do
|
356
|
-
Fabricate.build(:opportunity, party: party)
|
357
|
-
end
|
358
|
-
|
359
|
-
before { opportunity.save }
|
360
|
-
|
361
|
-
it { opportunity.name.should eql('Test') }
|
362
|
-
|
363
|
-
it { opportunity.milestone_id.should eql(1) }
|
364
|
-
|
365
|
-
it { opportunity.should be_persisted }
|
366
|
-
end
|
367
|
-
end
|
368
|
-
|
369
|
-
describe '#save!' do
|
370
|
-
context 'when the opportunity is a new record' do
|
371
|
-
context 'when the opportunity is valid' do
|
372
|
-
before do
|
373
|
-
stub_request(:post, /.*/).to_return(headers: {
|
374
|
-
'Location' => 'https://sample.capsulecrm.com/api/party/100',
|
375
|
-
}, status: 200)
|
376
|
-
end
|
377
|
-
let(:party) { Fabricate.build(:person) }
|
378
|
-
let(:opportunity) do
|
379
|
-
Fabricate.build(:opportunity, party: party)
|
380
|
-
end
|
381
|
-
|
382
|
-
before { opportunity.save! }
|
383
|
-
|
384
|
-
it { opportunity.should be_persisted }
|
385
|
-
end
|
386
|
-
|
387
|
-
context 'when the opportunity is not valid' do
|
388
|
-
let(:opportunity) { CapsuleCRM::Opportunity.new }
|
389
|
-
|
390
|
-
it do
|
391
|
-
expect { opportunity.save! }.
|
392
|
-
to raise_error(CapsuleCRM::Errors::RecordInvalid)
|
393
|
-
end
|
394
|
-
end
|
395
|
-
end
|
396
|
-
|
397
|
-
context 'when the opportunity is not a new record' do
|
398
|
-
context 'when the opportunity is not valid' do
|
399
|
-
|
400
|
-
let(:opportunity) { CapsuleCRM::Opportunity.new(id: 1) }
|
401
|
-
|
402
|
-
it do
|
403
|
-
expect { opportunity.save! }.
|
404
|
-
to raise_exception(CapsuleCRM::Errors::RecordInvalid)
|
405
|
-
end
|
406
|
-
end
|
407
|
-
end
|
408
|
-
end
|
409
|
-
|
410
|
-
describe '#new_record?' do
|
411
|
-
context 'when the opportunity is a new record' do
|
412
|
-
let(:opportunity) { CapsuleCRM::Opportunity.new }
|
413
|
-
|
414
|
-
subject { opportunity.new_record? }
|
415
|
-
|
416
|
-
it { should be_true }
|
417
|
-
end
|
418
|
-
|
419
|
-
context 'when the opportunity is not a new record' do
|
420
|
-
let(:opportunity) { CapsuleCRM::Opportunity.new(id: 1) }
|
421
|
-
|
422
|
-
subject { opportunity.new_record? }
|
423
|
-
|
424
|
-
it { should be_false }
|
425
|
-
end
|
426
|
-
end
|
427
|
-
|
428
|
-
describe '#persisted?' do
|
429
|
-
context 'when the opportunity is persisted' do
|
430
|
-
let(:opportunity) { CapsuleCRM::Opportunity.new(id: 1) }
|
431
|
-
|
432
|
-
subject { opportunity.persisted? }
|
433
|
-
|
434
|
-
it { should be_true }
|
435
|
-
end
|
436
|
-
|
437
|
-
context 'when the opportunity is not persisted' do
|
438
|
-
let(:opportunity) { CapsuleCRM::Opportunity.new }
|
439
|
-
|
440
|
-
subject { opportunity.persisted? }
|
441
|
-
|
442
|
-
it { should be_false }
|
443
|
-
end
|
444
|
-
end
|
445
|
-
|
446
|
-
describe '.init_collection' do
|
447
|
-
subject do
|
448
|
-
CapsuleCRM::Opportunity.init_collection(
|
449
|
-
JSON.parse(
|
450
|
-
File.read('spec/support/all_opportunities.json')
|
451
|
-
)['opportunities']['opportunity']
|
452
|
-
)
|
453
|
-
end
|
454
|
-
|
455
|
-
it { should be_a(Array) }
|
456
|
-
|
457
|
-
it { subject.length.should eql(1) }
|
458
|
-
|
459
|
-
it do
|
460
|
-
subject.all? { |item| item.is_a?(CapsuleCRM::Opportunity) }.should be_true
|
461
|
-
end
|
462
|
-
end
|
463
|
-
|
464
|
-
describe '#destroy' do
|
465
|
-
let(:opportunity) do
|
466
|
-
CapsuleCRM::Opportunity.new(id: 1)
|
467
|
-
end
|
468
|
-
|
469
|
-
before do
|
470
|
-
stub_request(:delete, /.*/).to_return(status: 200)
|
471
|
-
opportunity.destroy
|
472
|
-
end
|
473
|
-
|
474
|
-
it { opportunity.id.should be_blank }
|
475
|
-
|
476
|
-
it { opportunity.should_not be_persisted }
|
477
|
-
end
|
478
|
-
|
479
160
|
describe '.deleted' do
|
480
161
|
before do
|
481
162
|
stub_request(:get, /.*/).
|
@@ -4,13 +4,50 @@ require 'spec_helper'
|
|
4
4
|
describe CapsuleCRM::Organization do
|
5
5
|
before { configure }
|
6
6
|
|
7
|
-
it_should_behave_like 'contactable'
|
8
|
-
|
9
7
|
before do
|
10
8
|
stub_request(:get, /\/api\/users$/).
|
11
9
|
to_return(body: File.read('spec/support/all_users.json'))
|
12
10
|
end
|
13
11
|
|
12
|
+
it_should_behave_like 'contactable'
|
13
|
+
|
14
|
+
it_behaves_like 'persistable', 'https://sample.capsulecrm.com/api/organisation/13', 13 do
|
15
|
+
let(:attributes) { Fabricate.attributes_for(:organization) }
|
16
|
+
end
|
17
|
+
|
18
|
+
it_behaves_like 'deletable'
|
19
|
+
|
20
|
+
it_behaves_like 'listable', '/party', 'parties', 1
|
21
|
+
|
22
|
+
it_behaves_like 'findable', '/api/party/10', 10, 'organisation' do
|
23
|
+
let(:attributes) do
|
24
|
+
{ name: 'Google Inc', about: 'A comment here' }
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'should get the contact address street' do
|
28
|
+
expect(subject.addresses.first.street).
|
29
|
+
to eql('1600 Amphitheatre Parkway')
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'should get the contact address city' do
|
33
|
+
expect(subject.addresses.first.city).
|
34
|
+
to eql('Mountain View')
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'should get the contact address state' do
|
38
|
+
expect(subject.addresses.first.state).to eql('CA')
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'should get the contact address zip' do
|
42
|
+
expect(subject.addresses.first.zip).to eql('94043')
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'should get the contact address country' do
|
46
|
+
expect(subject.addresses.first.country).
|
47
|
+
to eql('United States')
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
14
51
|
describe '#custom_fields' do
|
15
52
|
before do
|
16
53
|
stub_request(:get, /\/api\/party\/#{organization.id}\/customfields/).
|
@@ -27,36 +64,6 @@ describe CapsuleCRM::Organization do
|
|
27
64
|
end
|
28
65
|
end
|
29
66
|
|
30
|
-
describe '.all' do
|
31
|
-
context 'when some parties exist' do
|
32
|
-
before do
|
33
|
-
stub_request(:get, /\/api\/party$/).
|
34
|
-
to_return(body: File.read('spec/support/all_parties.json'))
|
35
|
-
end
|
36
|
-
|
37
|
-
subject { CapsuleCRM::Organization.all }
|
38
|
-
|
39
|
-
it { expect(subject).to be_a(Array) }
|
40
|
-
|
41
|
-
it { expect(subject.length).to eql(1) }
|
42
|
-
|
43
|
-
it { expect(subject.first).to be_a(CapsuleCRM::Organization) }
|
44
|
-
end
|
45
|
-
|
46
|
-
context 'when no parties exist' do
|
47
|
-
before do
|
48
|
-
stub_request(:get, /\/api\/party$/).
|
49
|
-
to_return(body: File.read('spec/support/no_parties.json'))
|
50
|
-
end
|
51
|
-
|
52
|
-
subject { CapsuleCRM::Organization.all }
|
53
|
-
|
54
|
-
it { expect(subject).to be_a(Array) }
|
55
|
-
|
56
|
-
it { expect(subject.length).to eql(0) }
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
67
|
describe '#people' do
|
61
68
|
let(:organization) { Fabricate.build(:organization, id: 1) }
|
62
69
|
|
@@ -97,58 +104,30 @@ describe CapsuleCRM::Organization do
|
|
97
104
|
zip: '10117', country: 'de'
|
98
105
|
)
|
99
106
|
end
|
100
|
-
|
101
107
|
let(:email) do
|
102
108
|
CapsuleCRM::Email.new(type: 'Work', email_address: 'mattscompany@gmail.com')
|
103
109
|
end
|
104
|
-
|
105
110
|
let(:contacts) do
|
106
111
|
CapsuleCRM::Contacts.new(addresses: [address], emails: [email])
|
107
112
|
end
|
108
|
-
|
109
113
|
let(:organization) do
|
110
114
|
CapsuleCRM::Organization.new(
|
111
115
|
name: "Matt's Company",
|
112
116
|
contacts: contacts
|
113
117
|
)
|
114
118
|
end
|
115
|
-
|
116
119
|
let(:email_json) { subject['contacts']['email'].first }
|
117
|
-
|
118
120
|
let(:address_json) { subject['contacts']['address'].first }
|
119
|
-
|
120
121
|
subject { organization.to_capsule_json['organisation'] }
|
121
122
|
|
122
123
|
it { should have_key('name') }
|
123
|
-
|
124
124
|
it { should have_key('contacts') }
|
125
|
-
|
126
125
|
it { address_json.should have_key('street') }
|
127
|
-
|
128
126
|
it { address_json.should have_key('city') }
|
129
|
-
|
130
127
|
it { address_json.should have_key('state') }
|
131
|
-
|
132
128
|
it { address_json.should have_key('zip') }
|
133
|
-
|
134
129
|
it { address_json.should have_key('country') }
|
135
|
-
|
136
130
|
it { email_json.should have_key('type') }
|
137
|
-
|
138
131
|
it { email_json.should have_key('emailAddress') }
|
139
132
|
end
|
140
|
-
|
141
|
-
describe '#destroy' do
|
142
|
-
let(:organization) { CapsuleCRM::Organization.new(id: 1) }
|
143
|
-
|
144
|
-
before do
|
145
|
-
stub_request(:delete, /\/api\/party\/#{organization.id}/).
|
146
|
-
to_return(status: 200)
|
147
|
-
organization.destroy
|
148
|
-
end
|
149
|
-
|
150
|
-
it { expect(organization.id).to be_blank }
|
151
|
-
|
152
|
-
it { expect(organization).to_not be_persisted }
|
153
|
-
end
|
154
133
|
end
|
@@ -3,78 +3,56 @@ require 'spec_helper'
|
|
3
3
|
describe CapsuleCRM::Party do
|
4
4
|
before { configure }
|
5
5
|
|
6
|
-
|
7
|
-
context 'when finding an organization' do
|
8
|
-
before do
|
9
|
-
stub_request(:get, /\/api\/party\/#{id}$/).
|
10
|
-
to_return(body: File.read('spec/support/organisation.json'))
|
11
|
-
end
|
6
|
+
it_behaves_like 'listable', '/party', 'parties', 3
|
12
7
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
it { expect(subject).to be_a(CapsuleCRM::Organization) }
|
18
|
-
|
19
|
-
it { expect(subject.contacts).to be_a(CapsuleCRM::Contacts) }
|
20
|
-
|
21
|
-
it 'should get the contact address street' do
|
22
|
-
expect(subject.addresses.first.street).
|
23
|
-
to eql('1600 Amphitheatre Parkway')
|
24
|
-
end
|
25
|
-
|
26
|
-
it 'should get the contact address city' do
|
27
|
-
expect(subject.addresses.first.city).
|
28
|
-
to eql('Mountain View')
|
29
|
-
end
|
30
|
-
|
31
|
-
it { expect(subject.addresses.first.state).to eql('CA') }
|
32
|
-
|
33
|
-
it { expect(subject.addresses.first.zip).to eql('94043') }
|
34
|
-
|
35
|
-
it 'should get the contact address country' do
|
36
|
-
expect(subject.addresses.first.country).
|
37
|
-
to eql('United States')
|
38
|
-
end
|
8
|
+
it_behaves_like 'findable', '/api/party/10', 10, 'organisation' do
|
9
|
+
let(:attributes) do
|
10
|
+
{ name: 'Google Inc', about: 'A comment here' }
|
39
11
|
end
|
40
12
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
end
|
46
|
-
|
47
|
-
subject { CapsuleCRM::Party.find(id) }
|
13
|
+
it 'should get the contact address street' do
|
14
|
+
expect(subject.addresses.first.street).
|
15
|
+
to eql('1600 Amphitheatre Parkway')
|
16
|
+
end
|
48
17
|
|
49
|
-
|
18
|
+
it 'should get the contact address city' do
|
19
|
+
expect(subject.addresses.first.city).
|
20
|
+
to eql('Mountain View')
|
21
|
+
end
|
50
22
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
end
|
23
|
+
it 'should get the contact address state' do
|
24
|
+
expect(subject.addresses.first.state).to eql('CA')
|
25
|
+
end
|
55
26
|
|
56
|
-
|
57
|
-
|
58
|
-
|
27
|
+
it 'should get the contact address zip' do
|
28
|
+
expect(subject.addresses.first.zip).to eql('94043')
|
29
|
+
end
|
59
30
|
|
60
|
-
|
61
|
-
|
62
|
-
|
31
|
+
it 'should get the contact address country' do
|
32
|
+
expect(subject.addresses.first.country).
|
33
|
+
to eql('United States')
|
63
34
|
end
|
64
35
|
end
|
65
36
|
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
37
|
+
it_behaves_like 'findable', '/api/party/12', 12, 'person' do
|
38
|
+
let(:attributes) do
|
39
|
+
{
|
40
|
+
first_name: 'Eric', last_name: 'Schmidt', job_title: 'Chairman',
|
41
|
+
about: 'A comment here'
|
42
|
+
}
|
70
43
|
end
|
71
44
|
|
72
|
-
|
73
|
-
|
74
|
-
|
45
|
+
it 'should get the email address' do
|
46
|
+
expect(subject.emails.first.email_address).
|
47
|
+
to eql('e.schmidt@google.com')
|
48
|
+
end
|
75
49
|
|
76
|
-
it
|
50
|
+
it 'should get the phone number' do
|
51
|
+
expect(subject.phones.first.phone_number).to eql('+1 888 555555')
|
52
|
+
end
|
77
53
|
|
78
|
-
it
|
54
|
+
it 'should get the website' do
|
55
|
+
expect(subject.websites.first.web_address).to eql('www.google.com')
|
56
|
+
end
|
79
57
|
end
|
80
58
|
end
|