capsule_crm 0.0.4 → 0.0.5
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/README.md +3 -0
- data/capsule_crm.gemspec +1 -0
- data/lib/capsule_crm/associations/belongs_to.rb +64 -0
- data/lib/capsule_crm/associations/has_many.rb +58 -0
- data/lib/capsule_crm/associations/has_many_proxy.rb +47 -0
- data/lib/capsule_crm/associations.rb +3 -0
- data/lib/capsule_crm/opportunity.rb +41 -7
- data/lib/capsule_crm/organization.rb +9 -4
- data/lib/capsule_crm/party.rb +23 -0
- data/lib/capsule_crm/person.rb +238 -267
- data/lib/capsule_crm/version.rb +1 -1
- data/lib/capsule_crm.rb +2 -0
- data/spec/fabricators/opportunity_fabricator.rb +5 -0
- data/spec/fabricators/organization_fabricator.rb +3 -0
- data/spec/lib/capsule_crm/associations/has_many_proxy_spec.rb +71 -0
- data/spec/lib/capsule_crm/associations/has_many_spec.rb +4 -0
- data/spec/lib/capsule_crm/opportunity_spec.rb +113 -9
- data/spec/lib/capsule_crm/organization_spec.rb +24 -0
- data/spec/spec_helper.rb +5 -3
- data/spec/support/all_people.json +16 -0
- data/spec/support/deleted_opportunities.json +14 -0
- data/spec/support/organisation.json +8 -0
- metadata +35 -2
@@ -21,6 +21,76 @@ describe CapsuleCRM::Opportunity do
|
|
21
21
|
it { should_not validate_presence_of(:milestone_id) }
|
22
22
|
end
|
23
23
|
|
24
|
+
describe '#party=' do
|
25
|
+
let(:opportunity) { Fabricate.build(:opportunity, party: nil) }
|
26
|
+
|
27
|
+
let(:person) { CapsuleCRM::Person.new(id: 2) }
|
28
|
+
|
29
|
+
before { opportunity.party= person }
|
30
|
+
|
31
|
+
it 'should set the party_id' do
|
32
|
+
opportunity.party_id.should eql(2)
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'should set the party' do
|
36
|
+
opportunity.party.should eql(person)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
describe '#party' do
|
41
|
+
let(:person) { CapsuleCRM::Person.new(id: 1) }
|
42
|
+
|
43
|
+
let(:organization) { CapsuleCRM::Organization.new(id: 2) }
|
44
|
+
|
45
|
+
let(:opportunity) { Fabricate.build(:opportunity, party: nil) }
|
46
|
+
|
47
|
+
context 'when the party is set' do
|
48
|
+
context 'when the party is a person' do
|
49
|
+
before { opportunity.party = person }
|
50
|
+
|
51
|
+
it { opportunity.party.should eql(person) }
|
52
|
+
end
|
53
|
+
|
54
|
+
context 'when the party is an organization' do
|
55
|
+
before { opportunity.party = organization }
|
56
|
+
|
57
|
+
it { opportunity.party.should eql(organization) }
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
context 'when the party_id is set' do
|
62
|
+
context 'when the party is a person' do
|
63
|
+
before do
|
64
|
+
stub_request(:get, /.*/).
|
65
|
+
to_return(body: File.read('spec/support/person.json'))
|
66
|
+
opportunity.party_id = person.id
|
67
|
+
end
|
68
|
+
|
69
|
+
it 'should return the party' do
|
70
|
+
opportunity.party.should be_a(CapsuleCRM::Person)
|
71
|
+
end
|
72
|
+
|
73
|
+
it { opportunity.party.id.should eql(opportunity.party_id) }
|
74
|
+
end
|
75
|
+
|
76
|
+
context 'when the party is an opportunity' do
|
77
|
+
before do
|
78
|
+
stub_request(:get, /.*/).
|
79
|
+
to_return(body: File.read('spec/support/organisation.json'))
|
80
|
+
opportunity.party_id = organization.id
|
81
|
+
end
|
82
|
+
|
83
|
+
it { opportunity.party.should be_a(CapsuleCRM::Organization) }
|
84
|
+
|
85
|
+
it { opportunity.party.id.should eql(opportunity.party_id) }
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
context 'when the party_id is nil' do
|
90
|
+
it { opportunity.party.should be_nil }
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
24
94
|
describe '.all' do
|
25
95
|
before do
|
26
96
|
stub_request(:get, /\/api\/opportunity$/).
|
@@ -94,15 +164,23 @@ describe CapsuleCRM::Opportunity do
|
|
94
164
|
describe '.create' do
|
95
165
|
context 'when the opportunity is valid' do
|
96
166
|
before do
|
97
|
-
stub_request(:post,
|
167
|
+
stub_request(:post, request_path).to_return(headers: {
|
98
168
|
'Location' => 'https://sample.capsulecrm.com/api/opportunity/59'
|
99
169
|
})
|
100
170
|
end
|
101
171
|
|
172
|
+
let(:request_path) do
|
173
|
+
[
|
174
|
+
'https://1234:@company.capsulecrm.com/api/party/',
|
175
|
+
opportunity_attributes[:party_id],
|
176
|
+
'/opportunity'
|
177
|
+
].join
|
178
|
+
end
|
179
|
+
|
180
|
+
let(:opportunity_attributes) { Fabricate.attributes_for(:opportunity) }
|
181
|
+
|
102
182
|
subject do
|
103
|
-
CapsuleCRM::Opportunity.create
|
104
|
-
name: 'Test Opportunity', milestone_id: 1
|
105
|
-
)
|
183
|
+
CapsuleCRM::Opportunity.create opportunity_attributes
|
106
184
|
end
|
107
185
|
|
108
186
|
it { should be_a(CapsuleCRM::Opportunity) }
|
@@ -128,9 +206,7 @@ describe CapsuleCRM::Opportunity do
|
|
128
206
|
end
|
129
207
|
|
130
208
|
subject do
|
131
|
-
CapsuleCRM::Opportunity.create(
|
132
|
-
name: 'Test Opportunity', milestone_id: 1
|
133
|
-
)
|
209
|
+
CapsuleCRM::Opportunity.create Fabricate.attributes_for(:opportunity)
|
134
210
|
end
|
135
211
|
|
136
212
|
it { should be_a(CapsuleCRM::Opportunity) }
|
@@ -207,7 +283,7 @@ describe CapsuleCRM::Opportunity do
|
|
207
283
|
end
|
208
284
|
|
209
285
|
let(:opportunity) do
|
210
|
-
|
286
|
+
Fabricate.build(:opportunity)
|
211
287
|
end
|
212
288
|
|
213
289
|
before { opportunity.save }
|
@@ -230,7 +306,7 @@ describe CapsuleCRM::Opportunity do
|
|
230
306
|
end
|
231
307
|
|
232
308
|
let(:opportunity) do
|
233
|
-
|
309
|
+
Fabricate.build(:opportunity)
|
234
310
|
end
|
235
311
|
|
236
312
|
before { opportunity.save! }
|
@@ -314,4 +390,32 @@ describe CapsuleCRM::Opportunity do
|
|
314
390
|
subject.all? { |item| item.is_a?(CapsuleCRM::Opportunity) }.should be_true
|
315
391
|
end
|
316
392
|
end
|
393
|
+
|
394
|
+
describe '#destroy' do
|
395
|
+
let(:opportunity) do
|
396
|
+
CapsuleCRM::Opportunity.new(id: 1)
|
397
|
+
end
|
398
|
+
|
399
|
+
before do
|
400
|
+
stub_request(:delete, /.*/).to_return(status: 200)
|
401
|
+
opportunity.destroy
|
402
|
+
end
|
403
|
+
|
404
|
+
it { opportunity.id.should be_blank }
|
405
|
+
|
406
|
+
it { opportunity.should_not be_persisted }
|
407
|
+
end
|
408
|
+
|
409
|
+
describe '.deleted' do
|
410
|
+
before do
|
411
|
+
stub_request(:get, /.*/).
|
412
|
+
to_return(body: File.read('spec/support/deleted_opportunities.json'))
|
413
|
+
end
|
414
|
+
|
415
|
+
subject { CapsuleCRM::Opportunity.deleted(1.week.ago) }
|
416
|
+
|
417
|
+
it { should be_a(Array) }
|
418
|
+
|
419
|
+
it { subject.length.should eql(2) }
|
420
|
+
end
|
317
421
|
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe CapsuleCRM::Organization do
|
4
|
+
before { configure }
|
5
|
+
|
6
|
+
describe '#people' do
|
7
|
+
let(:organization) { Fabricate.build(:organization, id: 1) }
|
8
|
+
|
9
|
+
subject { organization.people }
|
10
|
+
|
11
|
+
before do
|
12
|
+
stub_request(
|
13
|
+
:get,
|
14
|
+
"https://1234:@company.capsulecrm.com/api/party/#{organization.id}/people"
|
15
|
+
).to_return(body: File.read('spec/support/all_people.json'))
|
16
|
+
end
|
17
|
+
|
18
|
+
it { should be_a(Array) }
|
19
|
+
|
20
|
+
it do
|
21
|
+
subject.all? { |item| item.is_a?(CapsuleCRM::Person) }.should be_true
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,10 +1,12 @@
|
|
1
1
|
require 'rubygems'
|
2
2
|
require 'bundler/setup'
|
3
|
-
|
4
|
-
require 'support/helpers'
|
3
|
+
|
5
4
|
require 'capsule_crm'
|
6
|
-
require 'shoulda-matchers'
|
7
5
|
require 'coveralls'
|
6
|
+
require 'fabrication'
|
7
|
+
require 'shoulda-matchers'
|
8
|
+
require 'support/helpers'
|
9
|
+
require 'webmock/rspec'
|
8
10
|
|
9
11
|
Coveralls.wear!
|
10
12
|
|
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: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matt Beedle
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-05-
|
11
|
+
date: 2013-05-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|
@@ -108,6 +108,20 @@ dependencies:
|
|
108
108
|
- - '>='
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: fabrication
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - '>='
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - '>='
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
111
125
|
- !ruby/object:Gem::Dependency
|
112
126
|
name: guard
|
113
127
|
requirement: !ruby/object:Gem::Requirement
|
@@ -212,6 +226,9 @@ files:
|
|
212
226
|
- lib/capsule_crm.rb
|
213
227
|
- lib/capsule_crm/address.rb
|
214
228
|
- lib/capsule_crm/associations.rb
|
229
|
+
- lib/capsule_crm/associations/belongs_to.rb
|
230
|
+
- lib/capsule_crm/associations/has_many.rb
|
231
|
+
- lib/capsule_crm/associations/has_many_proxy.rb
|
215
232
|
- lib/capsule_crm/capsule_jsonable.rb
|
216
233
|
- lib/capsule_crm/configuration.rb
|
217
234
|
- lib/capsule_crm/connection.rb
|
@@ -228,16 +245,24 @@ files:
|
|
228
245
|
- lib/capsule_crm/results_proxy.rb
|
229
246
|
- lib/capsule_crm/version.rb
|
230
247
|
- lib/capsule_crm/website.rb
|
248
|
+
- spec/fabricators/opportunity_fabricator.rb
|
249
|
+
- spec/fabricators/organization_fabricator.rb
|
231
250
|
- spec/lib/capsule_crm/address_spec.rb
|
251
|
+
- spec/lib/capsule_crm/associations/has_many_proxy_spec.rb
|
252
|
+
- spec/lib/capsule_crm/associations/has_many_spec.rb
|
232
253
|
- spec/lib/capsule_crm/contacts_spec.rb
|
233
254
|
- spec/lib/capsule_crm/email_spec.rb
|
234
255
|
- spec/lib/capsule_crm/opportunity_spec.rb
|
256
|
+
- spec/lib/capsule_crm/organization_spec.rb
|
235
257
|
- spec/lib/capsule_crm/person_spec.rb
|
236
258
|
- spec/spec_helper.rb
|
237
259
|
- spec/support/all_opportunities.json
|
238
260
|
- spec/support/all_parties.json
|
261
|
+
- spec/support/all_people.json
|
262
|
+
- spec/support/deleted_opportunities.json
|
239
263
|
- spec/support/helpers.rb
|
240
264
|
- spec/support/opportunity.json
|
265
|
+
- spec/support/organisation.json
|
241
266
|
- spec/support/person.json
|
242
267
|
homepage: ''
|
243
268
|
licenses: []
|
@@ -264,14 +289,22 @@ specification_version: 4
|
|
264
289
|
summary: Gem to communicate with CapsuleCRM
|
265
290
|
test_files:
|
266
291
|
- features/organizations.feature
|
292
|
+
- spec/fabricators/opportunity_fabricator.rb
|
293
|
+
- spec/fabricators/organization_fabricator.rb
|
267
294
|
- spec/lib/capsule_crm/address_spec.rb
|
295
|
+
- spec/lib/capsule_crm/associations/has_many_proxy_spec.rb
|
296
|
+
- spec/lib/capsule_crm/associations/has_many_spec.rb
|
268
297
|
- spec/lib/capsule_crm/contacts_spec.rb
|
269
298
|
- spec/lib/capsule_crm/email_spec.rb
|
270
299
|
- spec/lib/capsule_crm/opportunity_spec.rb
|
300
|
+
- spec/lib/capsule_crm/organization_spec.rb
|
271
301
|
- spec/lib/capsule_crm/person_spec.rb
|
272
302
|
- spec/spec_helper.rb
|
273
303
|
- spec/support/all_opportunities.json
|
274
304
|
- spec/support/all_parties.json
|
305
|
+
- spec/support/all_people.json
|
306
|
+
- spec/support/deleted_opportunities.json
|
275
307
|
- spec/support/helpers.rb
|
276
308
|
- spec/support/opportunity.json
|
309
|
+
- spec/support/organisation.json
|
277
310
|
- spec/support/person.json
|