capsule_crm 0.6.0 → 0.7.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/lib/capsule_crm/associations/belongs_to.rb +1 -1
- data/lib/capsule_crm/case.rb +3 -0
- data/lib/capsule_crm/opportunity.rb +3 -0
- data/lib/capsule_crm/party.rb +1 -0
- data/lib/capsule_crm/task.rb +37 -1
- data/lib/capsule_crm/version.rb +1 -1
- data/spec/lib/capsule_crm/case_spec.rb +22 -0
- data/spec/lib/capsule_crm/opportunity_spec.rb +20 -0
- data/spec/lib/capsule_crm/organization_spec.rb +18 -0
- data/spec/lib/capsule_crm/person_spec.rb +17 -0
- data/spec/lib/capsule_crm/task_spec.rb +60 -2
- data/spec/support/all_tasks.json +28 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3713b0ec80a9c807b2843e00a454a59e62f3985f
|
4
|
+
data.tar.gz: eba5f910134b574dea3d23d762c6b3d06f6effa3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0b59c35c19bfaa14d82bcb254bcad3bc11ddeb62beb17b399873e2517a8896321c44df4e58e4c0cb9ba6b3802019acfcea9ded653772bc73d5ee35765de5a5ce
|
7
|
+
data.tar.gz: 5d8dcbae2705a720e4177e4bc2ec124eb239e817eb5fd8e795574b25d29ef8a2649a2eed3f285aa66ef2555ced39945febb45788116c2670d83a23182a12e4ec
|
data/lib/capsule_crm/case.rb
CHANGED
@@ -6,6 +6,7 @@ module CapsuleCRM
|
|
6
6
|
include ActiveModel::Conversion
|
7
7
|
include ActiveModel::Validations
|
8
8
|
|
9
|
+
include CapsuleCRM::Associations::HasMany
|
9
10
|
include CapsuleCRM::Associations::BelongsTo
|
10
11
|
include CapsuleCRM::Taggable
|
11
12
|
|
@@ -21,6 +22,8 @@ module CapsuleCRM
|
|
21
22
|
|
22
23
|
belongs_to :party, class_name: 'CapsuleCRM::Party'
|
23
24
|
|
25
|
+
has_many :tasks, class_name: 'CapsuleCRM::Task', source: :case
|
26
|
+
|
24
27
|
# Public: Search and retrieve all cases in CapsuleCRM
|
25
28
|
#
|
26
29
|
# options - the Hash of query options (default: {}):
|
@@ -6,6 +6,7 @@ module CapsuleCRM
|
|
6
6
|
include ActiveModel::Conversion
|
7
7
|
include ActiveModel::Validations
|
8
8
|
|
9
|
+
include CapsuleCRM::Associations::HasMany
|
9
10
|
include CapsuleCRM::Associations::BelongsTo
|
10
11
|
|
11
12
|
attribute :id, Integer
|
@@ -26,6 +27,8 @@ module CapsuleCRM
|
|
26
27
|
validates :party_id, presence: true
|
27
28
|
validates :milestone, presence: true
|
28
29
|
|
30
|
+
has_many :tasks, class_name: 'CapsuleCRM::Task', source: :opportunity
|
31
|
+
|
29
32
|
belongs_to :party, class_name: 'CapsuleCRM::Party'
|
30
33
|
belongs_to :milestone, class_name: 'CapsuleCRM::Milestone'
|
31
34
|
|
data/lib/capsule_crm/party.rb
CHANGED
@@ -4,6 +4,7 @@ class CapsuleCRM::Party
|
|
4
4
|
include CapsuleCRM::Associations::HasMany
|
5
5
|
|
6
6
|
has_many :histories, class_name: 'CapsuleCRM::History', source: :party
|
7
|
+
has_many :tasks, class_name: 'CapsuleCRM::Task', source: :party
|
7
8
|
|
8
9
|
def self.all(options = {})
|
9
10
|
attributes = CapsuleCRM::Connection.get('/api/party', options)
|
data/lib/capsule_crm/task.rb
CHANGED
@@ -24,6 +24,30 @@ module CapsuleCRM
|
|
24
24
|
validates :due_date, presence: { unless: :due_date_time }
|
25
25
|
validates :due_date_time, presence: { unless: :due_date }
|
26
26
|
|
27
|
+
def self._for_party(party_id)
|
28
|
+
CapsuleCRM::ResultsProxy.new(
|
29
|
+
CapsuleCRM::Task.all.select { |task| task.party_id == party_id }
|
30
|
+
)
|
31
|
+
end
|
32
|
+
class << self
|
33
|
+
alias :_for_person :_for_party
|
34
|
+
alias :_for_organization :_for_party
|
35
|
+
end
|
36
|
+
|
37
|
+
def self._for_opportunity(opportunity_id)
|
38
|
+
CapsuleCRM::ResultsProxy.new(
|
39
|
+
CapsuleCRM::Task.all.select do |task|
|
40
|
+
task.opportunity_id == opportunity_id
|
41
|
+
end
|
42
|
+
)
|
43
|
+
end
|
44
|
+
|
45
|
+
def self._for_case(case_id)
|
46
|
+
CapsuleCRM::ResultsProxy.new(
|
47
|
+
CapsuleCRM::Task.all.select { |task| task.case_id == case_id }
|
48
|
+
)
|
49
|
+
end
|
50
|
+
|
27
51
|
def attributes=(attributes)
|
28
52
|
CapsuleCRM::HashHelper.underscore_keys!(attributes)
|
29
53
|
super(attributes)
|
@@ -129,11 +153,23 @@ module CapsuleCRM
|
|
129
153
|
|
130
154
|
def create_record
|
131
155
|
self.attributes = CapsuleCRM::Connection.post(
|
132
|
-
|
156
|
+
create_url, to_capsule_json
|
133
157
|
)
|
134
158
|
self
|
135
159
|
end
|
136
160
|
|
161
|
+
def create_url
|
162
|
+
if party_id
|
163
|
+
"/api/party/#{party_id}/task"
|
164
|
+
elsif opportunity_id
|
165
|
+
"/api/opportunity/#{opportunity_id}/task"
|
166
|
+
elsif case_id
|
167
|
+
"/api/kase/#{case_id}/task"
|
168
|
+
else
|
169
|
+
'/api/task'
|
170
|
+
end
|
171
|
+
end
|
172
|
+
|
137
173
|
def update_record
|
138
174
|
CapsuleCRM::Connection.put("/api/task/#{id}", to_capsule_json)
|
139
175
|
self
|
data/lib/capsule_crm/version.rb
CHANGED
@@ -3,10 +3,32 @@ require 'spec_helper'
|
|
3
3
|
describe CapsuleCRM::Case do
|
4
4
|
before { configure }
|
5
5
|
|
6
|
+
before do
|
7
|
+
stub_request(:get, /\/api\/users$/).
|
8
|
+
to_return(body: File.read('spec/support/all_users.json'))
|
9
|
+
end
|
10
|
+
|
6
11
|
it { should validate_presence_of(:name) }
|
7
12
|
|
8
13
|
it { should validate_presence_of(:party) }
|
9
14
|
|
15
|
+
describe '#tasks' do
|
16
|
+
let(:kase) { Fabricate.build(:case, id: 3) }
|
17
|
+
|
18
|
+
before do
|
19
|
+
stub_request(:get, /\/api\/tasks$/).
|
20
|
+
to_return(body: File.read('spec/support/all_tasks.json'))
|
21
|
+
end
|
22
|
+
|
23
|
+
subject { kase.tasks }
|
24
|
+
|
25
|
+
it { should be_an(Array) }
|
26
|
+
|
27
|
+
it { subject.length.should eql(1) }
|
28
|
+
|
29
|
+
it { subject.first.detail.should eql('Go and get drunk') }
|
30
|
+
end
|
31
|
+
|
10
32
|
describe '.all' do
|
11
33
|
before do
|
12
34
|
stub_request(:get, 'https://1234:@company.capsulecrm.com/api/kase').
|
@@ -8,6 +8,11 @@ describe CapsuleCRM::Opportunity do
|
|
8
8
|
to_return(body: File.read('spec/support/milestones.json'))
|
9
9
|
end
|
10
10
|
|
11
|
+
before do
|
12
|
+
stub_request(:get, /\/api\/users$/).
|
13
|
+
to_return(body: File.read('spec/support/all_users.json'))
|
14
|
+
end
|
15
|
+
|
11
16
|
it { should validate_presence_of(:name) }
|
12
17
|
|
13
18
|
it { should validate_presence_of(:milestone) }
|
@@ -30,6 +35,21 @@ describe CapsuleCRM::Opportunity do
|
|
30
35
|
it { should_not validate_presence_of(:milestone_id) }
|
31
36
|
end
|
32
37
|
|
38
|
+
describe '#tasks' do
|
39
|
+
let(:opportunity) { Fabricate.build(:opportunity, id: 5) }
|
40
|
+
|
41
|
+
before do
|
42
|
+
stub_request(:get, /\/api\/tasks$/).
|
43
|
+
to_return(body: File.read('spec/support/all_tasks.json'))
|
44
|
+
end
|
45
|
+
|
46
|
+
subject { opportunity.tasks }
|
47
|
+
|
48
|
+
it { should be_a(Array) }
|
49
|
+
|
50
|
+
it { subject.length.should eql(1) }
|
51
|
+
end
|
52
|
+
|
33
53
|
describe '#milestone=' do
|
34
54
|
context 'when it receives a milestone name' do
|
35
55
|
subject { CapsuleCRM::Opportunity.new(milestone: 'Bid') }
|
@@ -3,6 +3,11 @@ require 'spec_helper'
|
|
3
3
|
describe CapsuleCRM::Organization do
|
4
4
|
before { configure }
|
5
5
|
|
6
|
+
before do
|
7
|
+
stub_request(:get, /\/api\/users$/).
|
8
|
+
to_return(body: File.read('spec/support/all_users.json'))
|
9
|
+
end
|
10
|
+
|
6
11
|
describe '#people' do
|
7
12
|
let(:organization) { Fabricate.build(:organization, id: 1) }
|
8
13
|
|
@@ -21,4 +26,17 @@ describe CapsuleCRM::Organization do
|
|
21
26
|
subject.all? { |item| item.is_a?(CapsuleCRM::Person) }.should be_true
|
22
27
|
end
|
23
28
|
end
|
29
|
+
|
30
|
+
describe '#tasks' do
|
31
|
+
let(:organization) { Fabricate.build(:organization, id: 1) }
|
32
|
+
|
33
|
+
before do
|
34
|
+
stub_request(:get, /\/api\/tasks$/).
|
35
|
+
to_return(body: File.read('spec/support/all_tasks.json'))
|
36
|
+
end
|
37
|
+
|
38
|
+
subject { organization.tasks }
|
39
|
+
|
40
|
+
it { should be_a(Array) }
|
41
|
+
end
|
24
42
|
end
|
@@ -3,9 +3,26 @@
|
|
3
3
|
require 'spec_helper'
|
4
4
|
|
5
5
|
describe CapsuleCRM::Person do
|
6
|
+
before do
|
7
|
+
stub_request(:get, /\/api\/users$/).
|
8
|
+
to_return(body: File.read('spec/support/all_users.json'))
|
9
|
+
end
|
6
10
|
|
7
11
|
before { configure }
|
8
12
|
|
13
|
+
describe '#tasks' do
|
14
|
+
let(:person) { Fabricate.build(:person, id: 1) }
|
15
|
+
|
16
|
+
before do
|
17
|
+
stub_request(:get, /\/api\/tasks$/).
|
18
|
+
to_return(body: File.read('spec/support/all_tasks.json'))
|
19
|
+
end
|
20
|
+
|
21
|
+
subject { person.tasks }
|
22
|
+
|
23
|
+
it { should be_a(Array) }
|
24
|
+
end
|
25
|
+
|
9
26
|
describe '._for_organization' do
|
10
27
|
context 'when there are many people for the organization' do
|
11
28
|
pending
|
@@ -52,15 +52,16 @@ describe CapsuleCRM::Task do
|
|
52
52
|
subject.all? { |item| item.is_a?(CapsuleCRM::Task) }.should be_true
|
53
53
|
end
|
54
54
|
|
55
|
-
it { subject.length.should eql(
|
55
|
+
it { subject.length.should eql(4) }
|
56
56
|
|
57
57
|
it { subject.first.description.should eql('Meet with customer') }
|
58
58
|
end
|
59
59
|
|
60
60
|
describe '.create' do
|
61
|
+
let(:location) { 'https://sample.capsulecrm.com/api/task/59' }
|
62
|
+
|
61
63
|
context 'when it is valid' do
|
62
64
|
before do
|
63
|
-
location = 'https://sample.capsulecrm.com/api/task/59'
|
64
65
|
stub_request(:post, /\/api\/task$/).
|
65
66
|
to_return(headers: { 'Location' => location })
|
66
67
|
end
|
@@ -72,6 +73,63 @@ describe CapsuleCRM::Task do
|
|
72
73
|
it { should be_persisted }
|
73
74
|
end
|
74
75
|
|
76
|
+
context 'when it belongs to a party' do
|
77
|
+
before do
|
78
|
+
stub_request(:post, /\/api\/party\/#{party.id}\/task$/).
|
79
|
+
to_return(headers: { 'Location' => location })
|
80
|
+
end
|
81
|
+
|
82
|
+
let(:party) { Fabricate.build(:person, id: 1) }
|
83
|
+
|
84
|
+
subject do
|
85
|
+
CapsuleCRM::Task.create(
|
86
|
+
Fabricate.attributes_for(:task, party: party)
|
87
|
+
)
|
88
|
+
end
|
89
|
+
|
90
|
+
it { should be_a(CapsuleCRM::Task) }
|
91
|
+
|
92
|
+
it { should be_persisted }
|
93
|
+
end
|
94
|
+
|
95
|
+
context 'when it belongs to a opportunity' do
|
96
|
+
before do
|
97
|
+
stub_request(:post, /\/api\/opportunity\/#{opportunity.id}\/task$/).
|
98
|
+
to_return(headers: { 'Location' => location })
|
99
|
+
end
|
100
|
+
|
101
|
+
let(:opportunity) { Fabricate.build(:opportunity, id: 2) }
|
102
|
+
|
103
|
+
subject do
|
104
|
+
CapsuleCRM::Task.create(
|
105
|
+
Fabricate.attributes_for(:task, opportunity: opportunity)
|
106
|
+
)
|
107
|
+
end
|
108
|
+
|
109
|
+
it { should be_a(CapsuleCRM::Task) }
|
110
|
+
|
111
|
+
it { should be_persisted }
|
112
|
+
end
|
113
|
+
|
114
|
+
context 'when it belongs to a case' do
|
115
|
+
before do
|
116
|
+
stub_request(:post, /\/api\/kase\/#{kase.id}\/task$/).
|
117
|
+
to_return(headers: { 'Location' => location })
|
118
|
+
end
|
119
|
+
|
120
|
+
let(:kase) { Fabricate.build(:case, id: 5) }
|
121
|
+
|
122
|
+
subject do
|
123
|
+
CapsuleCRM::Task.create(
|
124
|
+
Fabricate.attributes_for(:task, case: kase)
|
125
|
+
)
|
126
|
+
end
|
127
|
+
|
128
|
+
it { should be_a(CapsuleCRM::Task) }
|
129
|
+
|
130
|
+
it { should be_persisted }
|
131
|
+
end
|
132
|
+
|
75
133
|
context 'when it is not valid' do
|
76
134
|
subject { CapsuleCRM::Task.create }
|
77
135
|
|
data/spec/support/all_tasks.json
CHANGED
@@ -10,6 +10,34 @@
|
|
10
10
|
"owner": "a.user",
|
11
11
|
"detail": "Meeting at Coffee shop",
|
12
12
|
"partyId": "1"
|
13
|
+
},
|
14
|
+
{
|
15
|
+
"id": "101",
|
16
|
+
"dueDate": "2012-02-24T00:00:00Z",
|
17
|
+
"category": "Meeting",
|
18
|
+
"description": "Waste some time",
|
19
|
+
"owner": "a.user",
|
20
|
+
"detail": "Writing an open source gem instead of working",
|
21
|
+
"opportunityId": "5",
|
22
|
+
"opportunityName": "meeting"
|
23
|
+
},
|
24
|
+
{
|
25
|
+
"id": "102",
|
26
|
+
"dueDate": "2012-02-24T00:00:00Z",
|
27
|
+
"category": "Meeting",
|
28
|
+
"description": "Innovation time",
|
29
|
+
"owner": "a.user",
|
30
|
+
"detail": "Go and get drunk",
|
31
|
+
"caseId": "3",
|
32
|
+
"caseName": "I can't think of a good name"
|
33
|
+
},
|
34
|
+
{
|
35
|
+
"id": "103",
|
36
|
+
"dueDate": "2012-02-24T00:00:00Z",
|
37
|
+
"category": "Meeting",
|
38
|
+
"description": "An orphan task",
|
39
|
+
"owner": "a.user",
|
40
|
+
"detail": "Do something interesting"
|
13
41
|
}
|
14
42
|
]
|
15
43
|
}
|
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.
|
4
|
+
version: 0.7.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: 2013-05-
|
11
|
+
date: 2013-05-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|