capsule_crm 1.2.0 → 1.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.
- 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
@@ -6,6 +6,36 @@ describe CapsuleCRM::Person do
|
|
6
6
|
|
7
7
|
it_should_behave_like 'contactable'
|
8
8
|
|
9
|
+
it_behaves_like 'persistable', 'https://sample.capsulecrm.com/api/person/34', 34 do
|
10
|
+
let(:attributes) { Fabricate.attributes_for(:person) }
|
11
|
+
end
|
12
|
+
|
13
|
+
it_behaves_like 'deletable'
|
14
|
+
|
15
|
+
it_behaves_like 'listable', '/party', 'parties', 2
|
16
|
+
|
17
|
+
it_behaves_like 'findable', '/api/party/12', 12, 'person' do
|
18
|
+
let(:attributes) do
|
19
|
+
{
|
20
|
+
first_name: 'Eric', last_name: 'Schmidt', job_title: 'Chairman',
|
21
|
+
about: 'A comment here'
|
22
|
+
}
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'should get the email address' do
|
26
|
+
expect(subject.emails.first.email_address).
|
27
|
+
to eql('e.schmidt@google.com')
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'should get the phone number' do
|
31
|
+
expect(subject.phones.first.phone_number).to eql('+1 888 555555')
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'should get the website' do
|
35
|
+
expect(subject.websites.first.web_address).to eql('www.google.com')
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
9
39
|
before do
|
10
40
|
stub_request(:get, /\/api\/users$/).
|
11
41
|
to_return(body: File.read('spec/support/all_users.json'))
|
@@ -64,276 +94,48 @@ describe CapsuleCRM::Person do
|
|
64
94
|
|
65
95
|
describe '._for_organization' do
|
66
96
|
context 'when there are many people for the organization' do
|
67
|
-
pending
|
68
|
-
end
|
69
|
-
|
70
|
-
context 'when there is 1 person for the organization' do
|
71
97
|
before do
|
72
|
-
stub_request(:get,
|
73
|
-
to_return(body: File.read('spec/support/
|
98
|
+
stub_request(:get, /.*/).
|
99
|
+
to_return(body: File.read('spec/support/all_people.json'))
|
74
100
|
end
|
75
101
|
subject { CapsuleCRM::Person._for_organization(1) }
|
76
102
|
|
77
|
-
it
|
78
|
-
|
79
|
-
|
80
|
-
context 'when there are no people for the organization' do
|
81
|
-
pending
|
82
|
-
end
|
83
|
-
end
|
84
|
-
|
85
|
-
describe '.all' do
|
86
|
-
before do
|
87
|
-
stub_request(:get, /\/api\/party$/).
|
88
|
-
to_return(body: File.read('spec/support/all_parties.json'))
|
89
|
-
end
|
90
|
-
|
91
|
-
subject { CapsuleCRM::Person.all }
|
92
|
-
|
93
|
-
it { should be_a(Array) }
|
94
|
-
|
95
|
-
it { subject.length.should eql(2) }
|
96
|
-
|
97
|
-
it 'should only contain people' do
|
98
|
-
subject.all? { |item| item.is_a?(CapsuleCRM::Person) }.should be_true
|
99
|
-
end
|
100
|
-
end
|
101
|
-
|
102
|
-
describe '.find' do
|
103
|
-
before do
|
104
|
-
stub_request(:get, /.*/).
|
105
|
-
to_return(body: File.read('spec/support/person.json'))
|
106
|
-
end
|
107
|
-
|
108
|
-
subject { CapsuleCRM::Person.find(1) }
|
109
|
-
|
110
|
-
it { should be_a(CapsuleCRM::Person) }
|
111
|
-
|
112
|
-
it { subject.first_name.should eql('Eric') }
|
113
|
-
|
114
|
-
it { subject.last_name.should eql('Schmidt') }
|
115
|
-
end
|
116
|
-
|
117
|
-
describe '#attributes=' do
|
118
|
-
let(:person) { CapsuleCRM::Person.new }
|
119
|
-
|
120
|
-
before do
|
121
|
-
person.attributes= { firstName: 'Matt', lastName: 'Beedle' }
|
122
|
-
end
|
123
|
-
|
124
|
-
it { person.first_name.should eql('Matt') }
|
125
|
-
|
126
|
-
it { person.last_name.should eql('Beedle') }
|
127
|
-
end
|
128
|
-
|
129
|
-
describe '.create' do
|
130
|
-
context 'when the person is valid' do
|
131
|
-
before do
|
132
|
-
stub_request(:post, /.*/).to_return(headers: {
|
133
|
-
'Location' => 'https://sample.capsulecrm.com/api/party/100'
|
134
|
-
})
|
103
|
+
it 'should be an array' do
|
104
|
+
expect(subject).to be_a(Array)
|
135
105
|
end
|
136
106
|
|
137
|
-
|
138
|
-
|
139
|
-
it { should be_a(CapsuleCRM::Person) }
|
140
|
-
|
141
|
-
it { subject.id.should eql(100) }
|
142
|
-
end
|
143
|
-
|
144
|
-
context 'when the person is not valid' do
|
145
|
-
subject { CapsuleCRM::Person.create }
|
146
|
-
|
147
|
-
it { subject.errors.should_not be_blank }
|
148
|
-
end
|
149
|
-
end
|
150
|
-
|
151
|
-
describe '.create!' do
|
152
|
-
context 'when the person is valid' do
|
153
|
-
before do
|
154
|
-
stub_request(:post, /.*/).to_return(headers: {
|
155
|
-
'Location' => 'https://sample.capsulecrm.com/api/party/101'
|
156
|
-
})
|
157
|
-
end
|
158
|
-
|
159
|
-
subject { CapsuleCRM::Person.create(first_name: 'Eric') }
|
160
|
-
|
161
|
-
it { should be_a(CapsuleCRM::Person) }
|
162
|
-
|
163
|
-
it { should be_persisted }
|
164
|
-
|
165
|
-
it { subject.id.should eql(101) }
|
166
|
-
end
|
167
|
-
|
168
|
-
context 'when the person is not valid' do
|
169
|
-
it do
|
170
|
-
expect { CapsuleCRM::Person.create! }.
|
171
|
-
to raise_error(CapsuleCRM::Errors::RecordInvalid)
|
172
|
-
end
|
173
|
-
end
|
174
|
-
end
|
175
|
-
|
176
|
-
describe '#update_attributes' do
|
177
|
-
context 'when the person is valid' do
|
178
|
-
before do
|
179
|
-
stub_request(:put, /.*/).to_return(status: 200)
|
107
|
+
it 'should contain 2 items' do
|
108
|
+
expect(subject.length).to eql(2)
|
180
109
|
end
|
181
|
-
|
182
|
-
let(:person) { CapsuleCRM::Person.new(id: 1) }
|
183
|
-
|
184
|
-
before { person.update_attributes first_name: 'James' }
|
185
|
-
|
186
|
-
it { person.first_name.should eql('James') }
|
187
|
-
|
188
|
-
it { person.id.should eql(1) }
|
189
|
-
end
|
190
|
-
|
191
|
-
context 'when the person is not valid' do
|
192
|
-
let(:person) { CapsuleCRM::Person.new(id: 1) }
|
193
|
-
|
194
|
-
before { person.update_attributes }
|
195
|
-
|
196
|
-
it { person.should_not be_valid }
|
197
|
-
|
198
|
-
it { person.errors.should_not be_blank }
|
199
110
|
end
|
200
|
-
end
|
201
|
-
|
202
|
-
describe '#update_attributes!' do
|
203
111
|
|
204
|
-
|
205
|
-
|
206
|
-
context 'when the person is valid' do
|
112
|
+
context 'when there is 1 person for the organization' do
|
207
113
|
before do
|
208
|
-
stub_request(:
|
114
|
+
stub_request(:get, /\/api\/party\/1\/people$/).
|
115
|
+
to_return(body: File.read('spec/support/single_person.json'))
|
209
116
|
end
|
117
|
+
subject { CapsuleCRM::Person._for_organization(1) }
|
210
118
|
|
211
|
-
|
212
|
-
|
213
|
-
it { person.first_name.should eql('James') }
|
214
|
-
|
215
|
-
it { person.id.should eql(1) }
|
216
|
-
end
|
217
|
-
|
218
|
-
context 'when the person is not valid' do
|
219
|
-
it do
|
220
|
-
expect { person.update_attributes! }.
|
221
|
-
to raise_error(CapsuleCRM::Errors::RecordInvalid)
|
222
|
-
end
|
119
|
+
it { should be_a(Array) }
|
223
120
|
end
|
224
|
-
end
|
225
121
|
|
226
|
-
|
227
|
-
context 'when the person is a new record' do
|
122
|
+
context 'when there are no people for the organization' do
|
228
123
|
before do
|
229
|
-
stub_request(:
|
230
|
-
|
231
|
-
}, status: 200)
|
232
|
-
end
|
233
|
-
|
234
|
-
let(:person) { CapsuleCRM::Person.new(first_name: 'Eric') }
|
235
|
-
|
236
|
-
before { person.save }
|
237
|
-
|
238
|
-
it { person.first_name.should eql('Eric') }
|
239
|
-
|
240
|
-
it { person.should be_persisted }
|
241
|
-
end
|
242
|
-
end
|
243
|
-
|
244
|
-
describe '#save!' do
|
245
|
-
context 'when the person is a new record' do
|
246
|
-
context 'when the person is valid' do
|
247
|
-
before do
|
248
|
-
stub_request(:post, /.*/).to_return(headers: {
|
249
|
-
'Location' => 'https://sample.capsulecrm.com/api/party/100',
|
250
|
-
}, status: 200)
|
251
|
-
end
|
252
|
-
|
253
|
-
let(:person) { CapsuleCRM::Person.new(first_name: 'Eric') }
|
254
|
-
|
255
|
-
before { person.save! }
|
256
|
-
|
257
|
-
it { person.should be_persisted }
|
124
|
+
stub_request(:get, /.*/).
|
125
|
+
to_return(body: File.read('spec/support/no_parties.json'))
|
258
126
|
end
|
127
|
+
subject { CapsuleCRM::Person._for_organization(1) }
|
259
128
|
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
it do
|
264
|
-
expect { person.save! }.
|
265
|
-
to raise_error(CapsuleCRM::Errors::RecordInvalid)
|
266
|
-
end
|
129
|
+
it 'should be an array' do
|
130
|
+
expect(subject).to be_a(Array)
|
267
131
|
end
|
268
|
-
end
|
269
|
-
|
270
|
-
context 'when the person is not a new record' do
|
271
|
-
context 'when the person is not valid' do
|
272
132
|
|
273
|
-
|
274
|
-
|
275
|
-
it do
|
276
|
-
expect { person.save! }.
|
277
|
-
to raise_exception(CapsuleCRM::Errors::RecordInvalid)
|
278
|
-
end
|
133
|
+
it 'should be empty' do
|
134
|
+
expect(subject).to be_empty
|
279
135
|
end
|
280
136
|
end
|
281
137
|
end
|
282
138
|
|
283
|
-
describe '#new_record?' do
|
284
|
-
context 'when the person is a new record' do
|
285
|
-
let(:person) { CapsuleCRM::Person.new }
|
286
|
-
|
287
|
-
subject { person.new_record? }
|
288
|
-
|
289
|
-
it { should be_true }
|
290
|
-
end
|
291
|
-
|
292
|
-
context 'when the person is not a new record' do
|
293
|
-
let(:person) { CapsuleCRM::Person.new(id: 1) }
|
294
|
-
|
295
|
-
subject { person.new_record? }
|
296
|
-
|
297
|
-
it { should be_false }
|
298
|
-
end
|
299
|
-
end
|
300
|
-
|
301
|
-
describe '#persisted?' do
|
302
|
-
context 'when the person is persisted' do
|
303
|
-
let(:person) { CapsuleCRM::Person.new(id: 1) }
|
304
|
-
|
305
|
-
subject { person.persisted? }
|
306
|
-
|
307
|
-
it { should be_true }
|
308
|
-
end
|
309
|
-
|
310
|
-
context 'when the person is not persisted' do
|
311
|
-
let(:person) { CapsuleCRM::Person.new }
|
312
|
-
|
313
|
-
subject { person.persisted? }
|
314
|
-
|
315
|
-
it { should be_false }
|
316
|
-
end
|
317
|
-
end
|
318
|
-
|
319
|
-
describe '.init_collection' do
|
320
|
-
subject do
|
321
|
-
CapsuleCRM::Person.init_collection(
|
322
|
-
JSON.parse(
|
323
|
-
File.read('spec/support/all_parties.json')
|
324
|
-
)['parties']['person']
|
325
|
-
)
|
326
|
-
end
|
327
|
-
|
328
|
-
it { should be_a(Array) }
|
329
|
-
|
330
|
-
it { subject.length.should eql(2) }
|
331
|
-
|
332
|
-
it do
|
333
|
-
subject.all? { |item| item.is_a?(CapsuleCRM::Person) }.should be_true
|
334
|
-
end
|
335
|
-
end
|
336
|
-
|
337
139
|
describe '#first_name_required?' do
|
338
140
|
let(:person) { CapsuleCRM::Person.new }
|
339
141
|
|
@@ -10,19 +10,24 @@ class SerializableTest
|
|
10
10
|
attribute :something, Date
|
11
11
|
end
|
12
12
|
|
13
|
+
class SerializableInverse
|
14
|
+
include Virtus
|
15
|
+
include CapsuleCRM::Associations
|
16
|
+
end
|
17
|
+
|
13
18
|
describe CapsuleCRM::Serializer do
|
14
19
|
describe '#serialize' do
|
15
20
|
let(:options) do
|
16
21
|
{}
|
17
22
|
end
|
18
|
-
let(:serializer) { described_class.new(
|
23
|
+
let(:serializer) { described_class.new(options) }
|
19
24
|
let(:object) do
|
20
25
|
SerializableTest.new(
|
21
26
|
id: Random.rand(1..10), name: Faker::Lorem.word,
|
22
27
|
description: Faker::Lorem.word
|
23
28
|
)
|
24
29
|
end
|
25
|
-
subject { serializer.serialize }
|
30
|
+
subject { serializer.serialize(object) }
|
26
31
|
|
27
32
|
context 'without an options' do
|
28
33
|
it 'should not include the ID' do
|
@@ -30,6 +35,18 @@ describe CapsuleCRM::Serializer do
|
|
30
35
|
end
|
31
36
|
end
|
32
37
|
|
38
|
+
context 'when include_root is false' do
|
39
|
+
before do
|
40
|
+
options.merge!(include_root: false)
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'should not include the root' do
|
44
|
+
expect(subject).to eql({
|
45
|
+
'name' => object.name, 'description' => object.description
|
46
|
+
})
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
33
50
|
context 'when additional methods are supplied' do
|
34
51
|
before do
|
35
52
|
options.merge!(additional_methods: [:test])
|
@@ -65,7 +82,11 @@ describe CapsuleCRM::Serializer do
|
|
65
82
|
context 'when there are belongs to associations' do
|
66
83
|
before do
|
67
84
|
SerializableTest.send(
|
68
|
-
:belongs_to, :person, class_name:
|
85
|
+
:belongs_to, :person, class_name: 'SerializableTest'
|
86
|
+
)
|
87
|
+
SerializableTest.send(
|
88
|
+
:has_many, :things, class_name: 'SerializableTest',
|
89
|
+
source: :person
|
69
90
|
)
|
70
91
|
object.person = person
|
71
92
|
end
|
@@ -80,7 +101,7 @@ describe CapsuleCRM::Serializer do
|
|
80
101
|
context 'with a serializable key' do
|
81
102
|
before do
|
82
103
|
SerializableTest.send(
|
83
|
-
:belongs_to, :person, class_name: CapsuleCRM::Person,
|
104
|
+
:belongs_to, :person, class_name: 'CapsuleCRM::Person',
|
84
105
|
serializable_key: 'monkeys'
|
85
106
|
)
|
86
107
|
end
|
@@ -9,265 +9,40 @@ describe CapsuleCRM::Task do
|
|
9
9
|
to_return(body: File.read('spec/support/person.json'))
|
10
10
|
end
|
11
11
|
|
12
|
-
|
13
|
-
|
14
|
-
it { should validate_presence_of(:description) }
|
15
|
-
it { should validate_presence_of(:due_date) }
|
16
|
-
it { should validate_presence_of(:due_date_time) }
|
17
|
-
end
|
18
|
-
|
19
|
-
describe '.find' do
|
20
|
-
before do
|
21
|
-
stub_request(:get, /\/api\/task\/2$/).
|
22
|
-
to_return(body: File.read('spec/support/task.json'))
|
23
|
-
end
|
24
|
-
|
25
|
-
subject { CapsuleCRM::Task.find(2) }
|
26
|
-
|
27
|
-
it { should be_a(CapsuleCRM::Task) }
|
28
|
-
it { subject.due_date.should_not be_blank }
|
29
|
-
it { subject.category.should eql('Meeting') }
|
30
|
-
it { subject.description.should eql('Meet with customer') }
|
31
|
-
it { subject.detail.should eql('Meeting at Coffee shop') }
|
32
|
-
it { subject.owner.should be_a(CapsuleCRM::User) }
|
33
|
-
it { subject.party.should be_a(CapsuleCRM::Person) }
|
34
|
-
end
|
35
|
-
|
36
|
-
describe '.all' do
|
37
|
-
before do
|
38
|
-
stub_request(:get, /\/api\/tasks$/).
|
39
|
-
to_return(body: File.read('spec/support/all_tasks.json'))
|
40
|
-
end
|
41
|
-
|
42
|
-
subject { CapsuleCRM::Task.all }
|
43
|
-
|
44
|
-
it { should be_a(Array) }
|
45
|
-
|
46
|
-
it do
|
47
|
-
subject.all? { |item| item.is_a?(CapsuleCRM::Task) }.should be_true
|
48
|
-
end
|
49
|
-
|
50
|
-
it { subject.length.should eql(4) }
|
51
|
-
|
52
|
-
it { subject.first.description.should eql('Meet with customer') }
|
12
|
+
it_behaves_like 'persistable', 'https://sample.capsulecrm.com/api/task/91', 91 do
|
13
|
+
let(:attributes) { Fabricate.attributes_for(:task) }
|
53
14
|
end
|
54
15
|
|
55
|
-
|
56
|
-
let(:location) { 'https://sample.capsulecrm.com/api/task/59' }
|
57
|
-
|
58
|
-
context 'when it is valid' do
|
59
|
-
before do
|
60
|
-
stub_request(:post, /\/api\/task$/).
|
61
|
-
to_return(headers: { 'Location' => location })
|
62
|
-
end
|
63
|
-
|
64
|
-
subject { CapsuleCRM::Task.create Fabricate.attributes_for(:task) }
|
65
|
-
|
66
|
-
it { should be_a(CapsuleCRM::Task) }
|
67
|
-
|
68
|
-
it { should be_persisted }
|
69
|
-
end
|
70
|
-
|
71
|
-
context 'when it belongs to a party' do
|
72
|
-
before do
|
73
|
-
stub_request(:post, /\/api\/party\/#{party.id}\/task$/).
|
74
|
-
to_return(headers: { 'Location' => location })
|
75
|
-
end
|
76
|
-
|
77
|
-
let(:party) { Fabricate.build(:person, id: 1) }
|
78
|
-
|
79
|
-
subject do
|
80
|
-
CapsuleCRM::Task.create(
|
81
|
-
Fabricate.attributes_for(:task, party: party)
|
82
|
-
)
|
83
|
-
end
|
16
|
+
it_behaves_like 'deletable'
|
84
17
|
|
85
|
-
|
18
|
+
it_behaves_like 'listable', '/tasks', 'tasks', 4
|
86
19
|
|
87
|
-
|
20
|
+
it_behaves_like 'findable', '/api/task/2', 2, 'task' do
|
21
|
+
let(:attributes) do
|
22
|
+
{
|
23
|
+
category: 'Meeting', description: 'Meet with customer',
|
24
|
+
detail: 'Meeting at Coffee shop'
|
25
|
+
}
|
88
26
|
end
|
89
27
|
|
90
|
-
|
91
|
-
|
92
|
-
stub_request(:post, /\/api\/opportunity\/#{opportunity.id}\/task$/).
|
93
|
-
to_return(headers: { 'Location' => location })
|
94
|
-
end
|
95
|
-
let(:opportunity) { Fabricate.build(:opportunity, id: 2) }
|
96
|
-
let(:task_attributes) do
|
97
|
-
Fabricate.attributes_for(:task).merge(opportunity: opportunity)
|
98
|
-
end
|
99
|
-
subject { CapsuleCRM::Task.create task_attributes }
|
100
|
-
|
101
|
-
it { should be_a(CapsuleCRM::Task) }
|
102
|
-
it { should be_persisted }
|
28
|
+
it 'should populate the due date' do
|
29
|
+
expect(subject.due_date).not_to be_blank
|
103
30
|
end
|
104
31
|
|
105
|
-
|
106
|
-
|
107
|
-
stub_request(:post, /\/api\/kase\/#{kase.id}\/task$/).
|
108
|
-
to_return(headers: { 'Location' => location })
|
109
|
-
end
|
110
|
-
let(:kase) { Fabricate.build(:case, id: 5) }
|
111
|
-
let(:task_attributes) do
|
112
|
-
Fabricate.attributes_for(:task).merge(case: kase)
|
113
|
-
end
|
114
|
-
subject { CapsuleCRM::Task.create(task_attributes) }
|
115
|
-
|
116
|
-
it { should be_a(CapsuleCRM::Task) }
|
117
|
-
it { should be_persisted }
|
118
|
-
end
|
119
|
-
|
120
|
-
context 'when it is not valid' do
|
121
|
-
subject { CapsuleCRM::Task.create }
|
122
|
-
|
123
|
-
it { should_not be_persisted }
|
124
|
-
end
|
125
|
-
end
|
126
|
-
|
127
|
-
describe '.create!' do
|
128
|
-
context 'when it is valid' do
|
129
|
-
before do
|
130
|
-
location = 'https://sample.capsulecrm.com/api/task/59'
|
131
|
-
stub_request(:post, /\/api\/task$/).
|
132
|
-
to_return(headers: { 'Location' => location })
|
133
|
-
end
|
134
|
-
|
135
|
-
subject { CapsuleCRM::Task.create! Fabricate.attributes_for(:task) }
|
136
|
-
|
137
|
-
it { should be_a(CapsuleCRM::Task) }
|
138
|
-
|
139
|
-
it { should be_persisted }
|
32
|
+
it 'should populate the owner' do
|
33
|
+
expect(subject.owner).to be_a(CapsuleCRM::User)
|
140
34
|
end
|
141
35
|
|
142
|
-
|
143
|
-
subject
|
144
|
-
|
145
|
-
it do
|
146
|
-
expect { subject }.to raise_error(CapsuleCRM::Errors::RecordInvalid)
|
147
|
-
end
|
36
|
+
it 'should populate the party' do
|
37
|
+
expect(subject.party).to be_a(CapsuleCRM::Person)
|
148
38
|
end
|
149
39
|
end
|
150
40
|
|
151
|
-
describe '
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
location = 'https://sample.capsulecrm.com/api/task/59'
|
157
|
-
stub_request(:post, /\/api\/task$/).
|
158
|
-
to_return(headers: { 'Location' => location })
|
159
|
-
end
|
160
|
-
|
161
|
-
subject { task.save }
|
162
|
-
|
163
|
-
it { subject.id.should eql(59) }
|
164
|
-
|
165
|
-
it { should be_persisted }
|
166
|
-
end
|
167
|
-
|
168
|
-
context 'when it is an existing record' do
|
169
|
-
before do
|
170
|
-
task.id = 12
|
171
|
-
stub_request(:put, /\/api\/task\/12$/).to_return(status: 200)
|
172
|
-
end
|
173
|
-
|
174
|
-
subject { task.save }
|
175
|
-
|
176
|
-
it { should be_persisted }
|
177
|
-
end
|
178
|
-
|
179
|
-
context 'when it is invalid' do
|
180
|
-
it { subject.save.should be_false }
|
181
|
-
end
|
182
|
-
end
|
183
|
-
|
184
|
-
describe '#save!' do
|
185
|
-
let(:task) { Fabricate.build(:task) }
|
186
|
-
|
187
|
-
context 'when it is a new record' do
|
188
|
-
before do
|
189
|
-
location = 'https://sample.capsulecrm.com/api/task/59'
|
190
|
-
stub_request(:post, /\/api\/task$/).
|
191
|
-
to_return(headers: { 'Location' => location })
|
192
|
-
end
|
193
|
-
|
194
|
-
subject { task.save! }
|
195
|
-
|
196
|
-
it { subject.id.should eql(59) }
|
197
|
-
|
198
|
-
it { should be_persisted }
|
199
|
-
end
|
200
|
-
|
201
|
-
context 'when it is an existing record' do
|
202
|
-
before do
|
203
|
-
task.id = 12
|
204
|
-
stub_request(:put, /\/api\/task\/12$/).to_return(status: 200)
|
205
|
-
end
|
206
|
-
|
207
|
-
subject { task.save! }
|
208
|
-
|
209
|
-
it { should be_persisted }
|
210
|
-
end
|
211
|
-
|
212
|
-
context 'when it is invalid' do
|
213
|
-
it do
|
214
|
-
expect { subject.save! }.
|
215
|
-
to raise_error(CapsuleCRM::Errors::RecordInvalid)
|
216
|
-
end
|
217
|
-
end
|
218
|
-
end
|
219
|
-
|
220
|
-
describe '#update_attributes' do
|
221
|
-
context 'when it is valid' do
|
222
|
-
let(:task) { Fabricate.build(:task, id: 1) }
|
223
|
-
|
224
|
-
subject { task.update_attributes description: Faker::Lorem.sentence }
|
225
|
-
|
226
|
-
before { stub_request(:put, /\/api\/task\/1$/).to_return(status: 200) }
|
227
|
-
|
228
|
-
it { should be_persisted }
|
229
|
-
end
|
230
|
-
|
231
|
-
context 'when it is not valid' do
|
232
|
-
let(:task) { CapsuleCRM::Task.new(id: 1) }
|
233
|
-
|
234
|
-
subject { task.update_attributes }
|
235
|
-
|
236
|
-
it { should be_false }
|
237
|
-
end
|
238
|
-
end
|
239
|
-
|
240
|
-
describe '#update_attributes!' do
|
241
|
-
context 'when it is valid' do
|
242
|
-
let(:task) { Fabricate.build(:task, id: 1) }
|
243
|
-
|
244
|
-
subject { task.update_attributes! description: Faker::Lorem.sentence }
|
245
|
-
|
246
|
-
before { stub_request(:put, /\/api\/task\/1$/).to_return(status: 200) }
|
247
|
-
|
248
|
-
it { should be_persisted }
|
249
|
-
end
|
250
|
-
|
251
|
-
context 'when it is not valid' do
|
252
|
-
let(:task) { CapsuleCRM::Task.new(id: 1) }
|
253
|
-
|
254
|
-
subject { task.update_attributes! }
|
255
|
-
|
256
|
-
it do
|
257
|
-
expect { subject }.to raise_error(CapsuleCRM::Errors::RecordInvalid)
|
258
|
-
end
|
259
|
-
end
|
260
|
-
end
|
261
|
-
|
262
|
-
describe '#destroy' do
|
263
|
-
subject { Fabricate.build(:task, id: 1) }
|
264
|
-
|
265
|
-
before do
|
266
|
-
stub_request(:delete, /\/api\/task\/1$/).to_return(status: 200)
|
267
|
-
subject.destroy
|
268
|
-
end
|
269
|
-
|
270
|
-
it { should_not be_persisted }
|
41
|
+
describe 'validations' do
|
42
|
+
it { should validate_numericality_of(:id) }
|
43
|
+
it { should validate_presence_of(:description) }
|
44
|
+
it { should validate_presence_of(:due_date) }
|
45
|
+
it { should validate_presence_of(:due_date_time) }
|
271
46
|
end
|
272
47
|
|
273
48
|
# Not really sure what to test here. CapsuleCRM API doesn't actually tell you
|
@@ -301,7 +76,6 @@ describe CapsuleCRM::Task do
|
|
301
76
|
|
302
77
|
describe '.categories' do
|
303
78
|
subject { CapsuleCRM::Task.categories }
|
304
|
-
|
305
79
|
before do
|
306
80
|
stub_request(:get, /\/api\/task\/categories$/).
|
307
81
|
to_return(body: File.read('spec/support/task_categories.json'))
|
@@ -318,14 +92,11 @@ describe CapsuleCRM::Task do
|
|
318
92
|
subject { task.to_capsule_json }
|
319
93
|
|
320
94
|
it { expect(subject.keys).to include('task') }
|
321
|
-
|
322
95
|
it { expect(subject['task']['description']).to eql(task.description) }
|
323
|
-
|
324
96
|
it { expect(subject['task']['dueDate']).to eql(task.due_date.to_s) }
|
325
97
|
|
326
98
|
context 'when it has an owner' do
|
327
99
|
let(:owner) { CapsuleCRM::User.new(username: 'matt.beedle') }
|
328
|
-
|
329
100
|
before { task.owner = owner }
|
330
101
|
|
331
102
|
it { expect(subject['task']['owner']).to eql(task.owner.username) }
|