capsule_crm 1.1.0 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (36) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +1 -0
  3. data/CHANGELOG.md +19 -0
  4. data/README.md +1 -1
  5. data/lib/capsule_crm/associations/belongs_to.rb +12 -10
  6. data/lib/capsule_crm/associations/belongs_to_association.rb +80 -0
  7. data/lib/capsule_crm/associations/has_many.rb +8 -18
  8. data/lib/capsule_crm/associations/has_many_association.rb +80 -0
  9. data/lib/capsule_crm/associations.rb +26 -0
  10. data/lib/capsule_crm/capsule_jsonable.rb +5 -1
  11. data/lib/capsule_crm/case.rb +7 -9
  12. data/lib/capsule_crm/contacts.rb +1 -1
  13. data/lib/capsule_crm/custom_field.rb +5 -8
  14. data/lib/capsule_crm/history.rb +11 -11
  15. data/lib/capsule_crm/opportunity.rb +5 -7
  16. data/lib/capsule_crm/organization.rb +6 -7
  17. data/lib/capsule_crm/participant.rb +0 -4
  18. data/lib/capsule_crm/party.rb +1 -1
  19. data/lib/capsule_crm/person.rb +6 -7
  20. data/lib/capsule_crm/serializer.rb +56 -0
  21. data/lib/capsule_crm/task.rb +7 -5
  22. data/lib/capsule_crm/track.rb +1 -1
  23. data/lib/capsule_crm/user.rb +5 -1
  24. data/lib/capsule_crm/version.rb +1 -1
  25. data/lib/capsule_crm.rb +1 -0
  26. data/spec/fabricators/custom_field_fabricator.rb +7 -0
  27. data/spec/lib/capsule_crm/associations/belongs_to_association_spec.rb +78 -0
  28. data/spec/lib/capsule_crm/associations/has_many_association_spec.rb +84 -0
  29. data/spec/lib/capsule_crm/associations/has_many_proxy_spec.rb +2 -2
  30. data/spec/lib/capsule_crm/associations_spec.rb +46 -0
  31. data/spec/lib/capsule_crm/custom_field_spec.rb +20 -597
  32. data/spec/lib/capsule_crm/history_spec.rb +8 -9
  33. data/spec/lib/capsule_crm/person_spec.rb +0 -16
  34. data/spec/lib/capsule_crm/serializer_spec.rb +103 -0
  35. data/spec/lib/capsule_crm/task_spec.rb +6 -14
  36. metadata +15 -2
@@ -373,48 +373,32 @@ describe CapsuleCRM::Person do
373
373
  zip: '10117', country: 'de'
374
374
  )
375
375
  end
376
-
377
376
  let(:email) do
378
377
  CapsuleCRM::Email.new(type: 'Work', email_address: 'matt@gmail.com')
379
378
  end
380
-
381
379
  let(:contacts) do
382
380
  CapsuleCRM::Contacts.new(addresses: [address], emails: [email])
383
381
  end
384
-
385
382
  let(:person) do
386
383
  CapsuleCRM::Person.new(
387
384
  first_name: 'Matt', last_name: 'Beedle',
388
385
  organisation_name: "Matt's Company", contacts: contacts
389
386
  )
390
387
  end
391
-
392
388
  let(:email_json) { subject['contacts']['email'].first }
393
-
394
389
  let(:address_json) { subject['contacts']['address'].first }
395
-
396
390
  subject { person.to_capsule_json['person'] }
397
391
 
398
392
  it { should have_key('firstName') }
399
-
400
393
  it { should have_key('lastName') }
401
-
402
394
  it { should have_key('organisationName') }
403
-
404
395
  it { should have_key('contacts') }
405
-
406
396
  it { address_json.should have_key('street') }
407
-
408
397
  it { address_json.should have_key('city') }
409
-
410
398
  it { address_json.should have_key('state') }
411
-
412
399
  it { address_json.should have_key('zip') }
413
-
414
400
  it { address_json.should have_key('country') }
415
-
416
401
  it { email_json.should have_key('type') }
417
-
418
402
  it { email_json.should have_key('emailAddress') }
419
403
  end
420
404
  end
@@ -0,0 +1,103 @@
1
+ require 'spec_helper'
2
+
3
+ class SerializableTest
4
+ include Virtus
5
+ include CapsuleCRM::Associations
6
+
7
+ attribute :id, Integer
8
+ attribute :name
9
+ attribute :description
10
+ attribute :something, Date
11
+ end
12
+
13
+ describe CapsuleCRM::Serializer do
14
+ describe '#serialize' do
15
+ let(:options) do
16
+ {}
17
+ end
18
+ let(:serializer) { described_class.new(object, options) }
19
+ let(:object) do
20
+ SerializableTest.new(
21
+ id: Random.rand(1..10), name: Faker::Lorem.word,
22
+ description: Faker::Lorem.word
23
+ )
24
+ end
25
+ subject { serializer.serialize }
26
+
27
+ context 'without an options' do
28
+ it 'should not include the ID' do
29
+ expect(subject['serializabletest'].keys).not_to include('id')
30
+ end
31
+ end
32
+
33
+ context 'when additional methods are supplied' do
34
+ before do
35
+ options.merge!(additional_methods: [:test])
36
+ object.stub(:test).and_return(test_object)
37
+ end
38
+ let(:test_object) { double(to_capsule_json: { foo: :bar }) }
39
+
40
+ it 'should serialize the additional methods' do
41
+ expect(subject['serializabletest']['test']).to eql({ foo: :bar })
42
+ end
43
+ end
44
+
45
+ context 'when excluded keys are supplied' do
46
+ before do
47
+ options.merge!(excluded_keys: [:description])
48
+ end
49
+
50
+ it 'should not include the excluded keys in the output' do
51
+ expect(subject['serializabletest'].keys).not_to include('description')
52
+ end
53
+ end
54
+
55
+ context 'when are root element name is supplied' do
56
+ before do
57
+ options.merge!(root: 'whatever')
58
+ end
59
+
60
+ it 'should use the root option as the root key' do
61
+ expect(subject.keys.first).to eql('whatever')
62
+ end
63
+ end
64
+
65
+ context 'when there are belongs to associations' do
66
+ before do
67
+ SerializableTest.send(
68
+ :belongs_to, :person, class_name: CapsuleCRM::Person
69
+ )
70
+ object.person = person
71
+ end
72
+ let(:person) { double('CapsuleCRM::Person', id: Random.rand(1..10)) }
73
+
74
+ context 'without a serializable key' do
75
+ it 'should include the person id' do
76
+ expect(subject['serializabletest']['personId']).to eql(person.id)
77
+ end
78
+ end
79
+
80
+ context 'with a serializable key' do
81
+ before do
82
+ SerializableTest.send(
83
+ :belongs_to, :person, class_name: CapsuleCRM::Person,
84
+ serializable_key: 'monkeys'
85
+ )
86
+ end
87
+
88
+ it 'should include the person id using the serializable key' do
89
+ expect(subject['serializabletest']['monkeys']).to eql(person.id)
90
+ end
91
+ end
92
+ end
93
+
94
+ context 'when there are dates' do
95
+ before { object.something = Date.today }
96
+
97
+ it 'should format the dates in :db format' do
98
+ expect(subject['serializabletest']['something']).
99
+ to eql(Date.today.to_s(:db))
100
+ end
101
+ end
102
+ end
103
+ end
@@ -92,17 +92,13 @@ describe CapsuleCRM::Task do
92
92
  stub_request(:post, /\/api\/opportunity\/#{opportunity.id}\/task$/).
93
93
  to_return(headers: { 'Location' => location })
94
94
  end
95
-
96
95
  let(:opportunity) { Fabricate.build(:opportunity, id: 2) }
97
-
98
- subject do
99
- CapsuleCRM::Task.create(
100
- Fabricate.attributes_for(:task, opportunity: opportunity)
101
- )
96
+ let(:task_attributes) do
97
+ Fabricate.attributes_for(:task).merge(opportunity: opportunity)
102
98
  end
99
+ subject { CapsuleCRM::Task.create task_attributes }
103
100
 
104
101
  it { should be_a(CapsuleCRM::Task) }
105
-
106
102
  it { should be_persisted }
107
103
  end
108
104
 
@@ -111,17 +107,13 @@ describe CapsuleCRM::Task do
111
107
  stub_request(:post, /\/api\/kase\/#{kase.id}\/task$/).
112
108
  to_return(headers: { 'Location' => location })
113
109
  end
114
-
115
110
  let(:kase) { Fabricate.build(:case, id: 5) }
116
-
117
- subject do
118
- CapsuleCRM::Task.create(
119
- Fabricate.attributes_for(:task, case: kase)
120
- )
111
+ let(:task_attributes) do
112
+ Fabricate.attributes_for(:task).merge(case: kase)
121
113
  end
114
+ subject { CapsuleCRM::Task.create(task_attributes) }
122
115
 
123
116
  it { should be_a(CapsuleCRM::Task) }
124
-
125
117
  it { should be_persisted }
126
118
  end
127
119
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: capsule_crm
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Beedle
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-01-08 00:00:00.000000000 Z
11
+ date: 2014-01-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel
@@ -256,7 +256,9 @@ files:
256
256
  - lib/capsule_crm/address.rb
257
257
  - lib/capsule_crm/associations.rb
258
258
  - lib/capsule_crm/associations/belongs_to.rb
259
+ - lib/capsule_crm/associations/belongs_to_association.rb
259
260
  - lib/capsule_crm/associations/has_many.rb
261
+ - lib/capsule_crm/associations/has_many_association.rb
260
262
  - lib/capsule_crm/associations/has_many_proxy.rb
261
263
  - lib/capsule_crm/attachment.rb
262
264
  - lib/capsule_crm/attributes.rb
@@ -286,6 +288,7 @@ files:
286
288
  - lib/capsule_crm/person.rb
287
289
  - lib/capsule_crm/phone.rb
288
290
  - lib/capsule_crm/results_proxy.rb
291
+ - lib/capsule_crm/serializer.rb
289
292
  - lib/capsule_crm/tag.rb
290
293
  - lib/capsule_crm/taggable.rb
291
294
  - lib/capsule_crm/task.rb
@@ -294,14 +297,18 @@ files:
294
297
  - lib/capsule_crm/version.rb
295
298
  - lib/capsule_crm/website.rb
296
299
  - spec/fabricators/case_fabricator.rb
300
+ - spec/fabricators/custom_field_fabricator.rb
297
301
  - spec/fabricators/history_fabricator.rb
298
302
  - spec/fabricators/opportunity_fabricator.rb
299
303
  - spec/fabricators/organization_fabricator.rb
300
304
  - spec/fabricators/person_fabricator.rb
301
305
  - spec/fabricators/task_fabricator.rb
302
306
  - spec/lib/capsule_crm/address_spec.rb
307
+ - spec/lib/capsule_crm/associations/belongs_to_association_spec.rb
308
+ - spec/lib/capsule_crm/associations/has_many_association_spec.rb
303
309
  - spec/lib/capsule_crm/associations/has_many_proxy_spec.rb
304
310
  - spec/lib/capsule_crm/associations/has_many_spec.rb
311
+ - spec/lib/capsule_crm/associations_spec.rb
305
312
  - spec/lib/capsule_crm/attachment_spec.rb
306
313
  - spec/lib/capsule_crm/case_spec.rb
307
314
  - spec/lib/capsule_crm/connection_spec.rb
@@ -316,6 +323,7 @@ files:
316
323
  - spec/lib/capsule_crm/organization_spec.rb
317
324
  - spec/lib/capsule_crm/party_spec.rb
318
325
  - spec/lib/capsule_crm/person_spec.rb
326
+ - spec/lib/capsule_crm/serializer_spec.rb
319
327
  - spec/lib/capsule_crm/tag_spec.rb
320
328
  - spec/lib/capsule_crm/taggable_spec.rb
321
329
  - spec/lib/capsule_crm/task_spec.rb
@@ -375,14 +383,18 @@ summary: Gem to communicate with CapsuleCRM
375
383
  test_files:
376
384
  - features/organizations.feature
377
385
  - spec/fabricators/case_fabricator.rb
386
+ - spec/fabricators/custom_field_fabricator.rb
378
387
  - spec/fabricators/history_fabricator.rb
379
388
  - spec/fabricators/opportunity_fabricator.rb
380
389
  - spec/fabricators/organization_fabricator.rb
381
390
  - spec/fabricators/person_fabricator.rb
382
391
  - spec/fabricators/task_fabricator.rb
383
392
  - spec/lib/capsule_crm/address_spec.rb
393
+ - spec/lib/capsule_crm/associations/belongs_to_association_spec.rb
394
+ - spec/lib/capsule_crm/associations/has_many_association_spec.rb
384
395
  - spec/lib/capsule_crm/associations/has_many_proxy_spec.rb
385
396
  - spec/lib/capsule_crm/associations/has_many_spec.rb
397
+ - spec/lib/capsule_crm/associations_spec.rb
386
398
  - spec/lib/capsule_crm/attachment_spec.rb
387
399
  - spec/lib/capsule_crm/case_spec.rb
388
400
  - spec/lib/capsule_crm/connection_spec.rb
@@ -397,6 +409,7 @@ test_files:
397
409
  - spec/lib/capsule_crm/organization_spec.rb
398
410
  - spec/lib/capsule_crm/party_spec.rb
399
411
  - spec/lib/capsule_crm/person_spec.rb
412
+ - spec/lib/capsule_crm/serializer_spec.rb
400
413
  - spec/lib/capsule_crm/tag_spec.rb
401
414
  - spec/lib/capsule_crm/taggable_spec.rb
402
415
  - spec/lib/capsule_crm/task_spec.rb