capsule_crm 0.5.7 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +1 -0
- data/README.md +247 -29
- data/lib/capsule_crm/history.rb +34 -0
- data/lib/capsule_crm/milestone.rb +34 -0
- data/lib/capsule_crm/opportunity.rb +11 -2
- data/lib/capsule_crm/party.rb +1 -1
- data/lib/capsule_crm/taggable.rb +8 -0
- data/lib/capsule_crm/version.rb +1 -1
- data/lib/capsule_crm.rb +1 -0
- data/spec/lib/capsule_crm/history_spec.rb +91 -0
- data/spec/lib/capsule_crm/milestone_spec.rb +29 -0
- data/spec/lib/capsule_crm/opportunity_spec.rb +35 -6
- data/spec/lib/capsule_crm/taggable_spec.rb +25 -0
- data/spec/support/milestones.json +32 -0
- data/spec/support/no_history.json +5 -0
- metadata +9 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3b03a8a029e80b9ea38a3769a8cd9ac51a36a2c8
|
4
|
+
data.tar.gz: e43d7db346766c213fc62c30ee08b30aa61a0888
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 737d7f366484bdea5916fc1cab2680577ca48c6c2a2f2aa2a056c9e0b1da65fcef07abe30636fddfd38bafca4146e38a4126e8e579686d52856e87d39c906fd4
|
7
|
+
data.tar.gz: 6229c13b72a40d24d83c53598688be4663cd3dc5c366e6036baf7e0fa24dda029c50e71800714cc64134f2fe45486ca7061abd4b14b42f2070620e33244fdc03
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -31,53 +31,271 @@ Or install it yourself as:
|
|
31
31
|
|
32
32
|
$ gem install capsule_crm
|
33
33
|
|
34
|
+
## Getting Started
|
35
|
+
|
36
|
+
You need to configure CapsuleCRM with your API Token and subdomain before you
|
37
|
+
can make any requests to it. If you are using rails then you can put this into
|
38
|
+
your config/initializers folder.
|
39
|
+
```ruby
|
40
|
+
CapsuleCRM.configure do |config|
|
41
|
+
config.api_token = 'API Token here'
|
42
|
+
config.subdomain = 'your capsule crm company subdomain here'
|
43
|
+
end
|
44
|
+
```
|
45
|
+
|
34
46
|
## Usage
|
35
47
|
|
48
|
+
### Parties
|
36
49
|
```ruby
|
37
|
-
|
38
|
-
|
39
|
-
emails: [CapsuleCRM::Email.new(email_address: 'mattbeedle@gmail.com')],
|
40
|
-
phones: [CapsuleCRM::Phone.new(phone_number: '123456789')],
|
41
|
-
webstes: [CapsuleCRM::Website.new(web_service: 'URL', web_address: 'http://github.com']
|
42
|
-
)
|
50
|
+
# List Parties
|
51
|
+
CapsuleCRM::Party.all
|
43
52
|
|
44
|
-
|
45
|
-
|
46
|
-
|
53
|
+
# With query parameters
|
54
|
+
CapsuleCRM::Party.all(
|
55
|
+
q: 'search term here', email: 'email to search for here',
|
56
|
+
lastmodified: 6.weeks.ago, tag: 'tag to search for here',
|
57
|
+
start: 10, limit: 55
|
47
58
|
)
|
59
|
+
|
60
|
+
# Find one
|
61
|
+
# When the party is an organization this returns a CapsuleCRM::Organization
|
62
|
+
# otherise it returns a CapsuleCRM::Person
|
63
|
+
party = CapsuleCRM::Party.find(ID)
|
64
|
+
```
|
65
|
+
|
66
|
+
### People
|
67
|
+
```ruby
|
68
|
+
# Find a person
|
69
|
+
person = CapsuleCRM::Person.find(ID)
|
70
|
+
|
71
|
+
# List People
|
72
|
+
CapsuleCRM::Person.all
|
73
|
+
|
74
|
+
# Initialize a new person
|
75
|
+
person = CapsuleCRM::Person.new(first_name: 'Matt', last_name: 'Beedle')
|
76
|
+
|
77
|
+
# Validate a person
|
78
|
+
person.valid?
|
79
|
+
|
80
|
+
# Save a person
|
48
81
|
person.save
|
49
82
|
|
50
|
-
|
51
|
-
person.
|
83
|
+
# Update a person
|
84
|
+
person.update_attributes first_name: 'John'
|
52
85
|
|
53
|
-
|
86
|
+
# Create a Person
|
87
|
+
person = CapsuleCRM::Person.create(first_name: 'Matt', last_name: 'Beedle')
|
54
88
|
|
55
|
-
|
89
|
+
# Get organization associated with a person
|
90
|
+
person.organization
|
56
91
|
|
57
|
-
|
58
|
-
|
59
|
-
addresses: CapsuleCRM::Address.new(street: 'Thurneysserstr')
|
60
|
-
)
|
92
|
+
# Delete a person
|
93
|
+
person.destroy
|
61
94
|
|
62
|
-
|
63
|
-
|
64
|
-
end
|
95
|
+
# List opportunities
|
96
|
+
person.opportunities
|
65
97
|
|
66
|
-
|
67
|
-
person.
|
68
|
-
person.valid? #=> false
|
98
|
+
# List tags
|
99
|
+
person.tags
|
69
100
|
|
70
|
-
|
71
|
-
person.
|
101
|
+
# Add a tag
|
102
|
+
person.add_tag 'a test tag'
|
72
103
|
|
73
|
-
|
104
|
+
# View history
|
105
|
+
person.histories
|
74
106
|
|
75
|
-
|
107
|
+
# Build a new history item
|
108
|
+
history_item = person.histories.build note: 'a note'
|
109
|
+
|
110
|
+
# Create a new history item
|
111
|
+
history_item = person.histories.create note: 'a note'
|
112
|
+
```
|
113
|
+
|
114
|
+
### Organizations
|
115
|
+
```ruby
|
116
|
+
# Find an organization
|
117
|
+
organization = CapsuleCRM::Organization.find(ID)
|
118
|
+
|
119
|
+
# List Organizations
|
120
|
+
CapsuleCRM::Organization.all
|
121
|
+
|
122
|
+
# Initialize a new organization
|
123
|
+
org = CapsuleCRM::Organization.new(name: 'Vegan.io')
|
124
|
+
|
125
|
+
# Validate an organization
|
126
|
+
org.valid?
|
127
|
+
|
128
|
+
# Save an organization
|
129
|
+
org.save
|
130
|
+
|
131
|
+
# Update an organization
|
132
|
+
org.update_attributes name: 'Apple Inc'
|
133
|
+
|
134
|
+
# Create an organization
|
135
|
+
org = CapsuleCRM::Organization.create(name: 'Vegan.io')
|
136
|
+
|
137
|
+
# Get people for an organization
|
138
|
+
org.people
|
139
|
+
|
140
|
+
# Delete an organization
|
141
|
+
org.destroy
|
142
|
+
|
143
|
+
# List opportunities
|
144
|
+
org.opportunities
|
145
|
+
|
146
|
+
# List tags
|
147
|
+
org.tags
|
148
|
+
|
149
|
+
# Add a tag
|
150
|
+
org.add_tag 'a test tag'
|
151
|
+
|
152
|
+
# View history
|
153
|
+
org.histories
|
154
|
+
|
155
|
+
# Build a new history item
|
156
|
+
history = org.histories.build note: 'some note text'
|
157
|
+
|
158
|
+
# Create a new history item
|
159
|
+
history = org.histories.create note: 'some note text'
|
160
|
+
```
|
161
|
+
|
162
|
+
### Opportunities
|
163
|
+
```ruby
|
164
|
+
# Find an opportunity
|
165
|
+
opportunity = CapsuleCRM::Opportunity.find(ID)
|
166
|
+
|
167
|
+
# List all opportunities
|
168
|
+
opportunities = CapsuleCRM::Opportunity.all
|
169
|
+
|
170
|
+
# List tags
|
171
|
+
opportunity.tags
|
172
|
+
|
173
|
+
# Add a tag
|
174
|
+
opportunity.add_tag 'tag here'
|
175
|
+
|
176
|
+
# View history
|
177
|
+
opportunity.histories
|
178
|
+
|
179
|
+
# Build a new history item
|
180
|
+
history = opportunity.histories.build note: 'some note text'
|
181
|
+
|
182
|
+
# Create a new history item
|
183
|
+
history_item = opportunity.histories.create note: 'some text here'
|
184
|
+
```
|
185
|
+
|
186
|
+
### Cases
|
187
|
+
```ruby
|
188
|
+
# Find a case
|
189
|
+
kase = CapsuleCRM::Case.find(ID)
|
190
|
+
|
191
|
+
# List Cases
|
192
|
+
kase = CapsuleCRM::Case.all
|
193
|
+
|
194
|
+
# Update a Case
|
195
|
+
kase.update_attributes status: 'CLOSED'
|
196
|
+
|
197
|
+
# Delete a Case
|
198
|
+
kase.destroy
|
199
|
+
|
200
|
+
# List tags
|
201
|
+
kase.tags
|
202
|
+
|
203
|
+
# Add a tag
|
204
|
+
kase.add_tag 'A test tag'
|
205
|
+
|
206
|
+
# View history
|
207
|
+
kase.histories
|
208
|
+
|
209
|
+
# Build a new history
|
210
|
+
history = kase.histories.build note: 'note text here'
|
211
|
+
|
212
|
+
# Create a new history item
|
213
|
+
history_item = kase.histories.create note: 'another note'
|
214
|
+
```
|
215
|
+
|
216
|
+
### History
|
217
|
+
```ruby
|
218
|
+
# Find a history item
|
219
|
+
history_item = CapsuleCRM::History.find(ID)
|
220
|
+
|
221
|
+
# Get the party
|
222
|
+
history_item.party
|
223
|
+
|
224
|
+
# Get the case
|
225
|
+
history_item.case
|
226
|
+
|
227
|
+
# Get the opportunity
|
228
|
+
history_item.opportunity
|
229
|
+
|
230
|
+
# Update a history item
|
231
|
+
history_item.update_attributes note: 'some new note text'
|
232
|
+
|
233
|
+
# Delete a history item
|
234
|
+
history_item.destroy
|
235
|
+
```
|
236
|
+
|
237
|
+
### Tasks
|
238
|
+
```ruby
|
239
|
+
# List open tasks
|
240
|
+
tasks = CapsuleCRM::Task.all
|
76
241
|
|
77
|
-
|
78
|
-
|
242
|
+
# Query open tasks
|
243
|
+
tasks = CapsuleCRM::Task.all(
|
244
|
+
category: 'category name', user: 'username', start: 6, limit: 25
|
245
|
+
)
|
246
|
+
|
247
|
+
# Add a task
|
248
|
+
CapsuleCRM::Task.create(
|
249
|
+
description: 'task description', due_date: Date.tomorrow
|
250
|
+
)
|
251
|
+
|
252
|
+
# Update task
|
253
|
+
task.update_attributes description: 'a new improved task description'
|
254
|
+
|
255
|
+
# Delete a task
|
256
|
+
task.destroy
|
257
|
+
|
258
|
+
# Complete a task
|
259
|
+
task.complete
|
260
|
+
|
261
|
+
# Reopen a task
|
262
|
+
task.reopen
|
263
|
+
|
264
|
+
# List available task categories
|
265
|
+
CapsuleCRM::Task.categories
|
266
|
+
```
|
267
|
+
|
268
|
+
### Users
|
269
|
+
```ruby
|
270
|
+
# List all users
|
271
|
+
CapsuleCRM::User.all
|
272
|
+
|
273
|
+
# Find a user by username
|
274
|
+
user = CapsuleCRM::User.find_by_username('username here')
|
275
|
+
```
|
276
|
+
|
277
|
+
### Countries
|
278
|
+
```ruby
|
279
|
+
# List all countries
|
280
|
+
CapsuleCRM::Country.all
|
79
281
|
```
|
80
282
|
|
283
|
+
### Currencies
|
284
|
+
```ruby
|
285
|
+
# List all currencies
|
286
|
+
CapsuleCRM::Currency.all
|
287
|
+
```
|
288
|
+
|
289
|
+
## Supported Rubies
|
290
|
+
|
291
|
+
1.9.2, 1.9.3, 2.0, jruby-19mode, rbx-19mode
|
292
|
+
|
293
|
+
## Feedback
|
294
|
+
|
295
|
+
Please use github issues to give feedback. If you have a bug to report then an
|
296
|
+
accompanying failing test would be great. Extra points for a full pull request
|
297
|
+
with fix.
|
298
|
+
|
81
299
|
## Contributing
|
82
300
|
|
83
301
|
1. Fork it
|
data/lib/capsule_crm/history.rb
CHANGED
@@ -27,6 +27,40 @@ module CapsuleCRM
|
|
27
27
|
validates :party, :kase, :opportunity,
|
28
28
|
presence: { if: :belongs_to_required? }
|
29
29
|
|
30
|
+
def self._for_party(party_id)
|
31
|
+
init_collection(
|
32
|
+
CapsuleCRM::Connection.
|
33
|
+
get("/api/party/#{party_id}/history")['history'].
|
34
|
+
fetch('historyItem', nil)
|
35
|
+
)
|
36
|
+
end
|
37
|
+
|
38
|
+
class << self
|
39
|
+
alias :_for_organization :_for_party
|
40
|
+
alias :_for_person :_for_party
|
41
|
+
end
|
42
|
+
|
43
|
+
def self._for_case(case_id)
|
44
|
+
init_collection(
|
45
|
+
CapsuleCRM::Connection.
|
46
|
+
get("/api/kase/#{case_id}/history")['history']['historyItem']
|
47
|
+
)
|
48
|
+
end
|
49
|
+
|
50
|
+
def self._for_opportunity(opportunity_id)
|
51
|
+
init_collection(
|
52
|
+
CapsuleCRM::Connection.
|
53
|
+
get("/api/opportunity/#{opportunity_id}/history")\
|
54
|
+
['history']['historyItem']
|
55
|
+
)
|
56
|
+
end
|
57
|
+
|
58
|
+
def self.init_collection(collection)
|
59
|
+
CapsuleCRM::ResultsProxy.new(
|
60
|
+
[collection].flatten.delete_if(&:blank?).map { |item| new(item) }
|
61
|
+
)
|
62
|
+
end
|
63
|
+
|
30
64
|
# Public: Underscore all of the attributes keys and set the attributes of
|
31
65
|
# this history item
|
32
66
|
#
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module CapsuleCRM
|
2
|
+
class Milestone
|
3
|
+
include Virtus
|
4
|
+
|
5
|
+
attribute :id, Integer
|
6
|
+
attribute :name, String
|
7
|
+
attribute :description, String
|
8
|
+
attribute :probability, Float
|
9
|
+
attribute :complete, Boolean
|
10
|
+
|
11
|
+
def self.all
|
12
|
+
init_collection(
|
13
|
+
CapsuleCRM::Connection.
|
14
|
+
get('/api/opportunity/milestones')['milestones']['milestone']
|
15
|
+
)
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.find(id)
|
19
|
+
all.select { |item| item.id == id }.first
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.find_by_name(name)
|
23
|
+
all.select { |item| item.name == name }.first
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def self.init_collection(collection)
|
29
|
+
CapsuleCRM::ResultsProxy.new(
|
30
|
+
collection.map { |attributes| new attributes }
|
31
|
+
)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -24,10 +24,19 @@ module CapsuleCRM
|
|
24
24
|
|
25
25
|
validates :name, presence: true
|
26
26
|
validates :party_id, presence: true
|
27
|
-
validates :
|
28
|
-
validates :milestone, presence: { unless: :milestone_id }
|
27
|
+
validates :milestone, presence: true
|
29
28
|
|
30
29
|
belongs_to :party, class_name: 'CapsuleCRM::Party'
|
30
|
+
belongs_to :milestone, class_name: 'CapsuleCRM::Milestone'
|
31
|
+
|
32
|
+
def milestone=(milestone)
|
33
|
+
if milestone.is_a?(String)
|
34
|
+
milestone = CapsuleCRM::Milestone.find_by_name(milestone)
|
35
|
+
end
|
36
|
+
@milestone = milestone
|
37
|
+
self.milestone_id = milestone.try(:id)
|
38
|
+
self
|
39
|
+
end
|
31
40
|
|
32
41
|
# Public: Set the attributes of a opportunity
|
33
42
|
#
|
data/lib/capsule_crm/party.rb
CHANGED
@@ -3,7 +3,7 @@ class CapsuleCRM::Party
|
|
3
3
|
|
4
4
|
include CapsuleCRM::Associations::HasMany
|
5
5
|
|
6
|
-
has_many :histories, class_name: 'CapsuleCRM::History'
|
6
|
+
has_many :histories, class_name: 'CapsuleCRM::History', source: :party
|
7
7
|
|
8
8
|
def self.all(options = {})
|
9
9
|
attributes = CapsuleCRM::Connection.get('/api/party', options)
|
data/lib/capsule_crm/taggable.rb
CHANGED
@@ -16,6 +16,14 @@ module CapsuleCRM
|
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
19
|
+
def remove_tag(tag_name)
|
20
|
+
if id
|
21
|
+
CapsuleCRM::Connection.delete(
|
22
|
+
"/api/#{api_singular_name}/#{id}/#{URI.encode(tag_name)}"
|
23
|
+
)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
19
27
|
def api_singular_name
|
20
28
|
self.class.to_s.demodulize.downcase.singularize
|
21
29
|
end
|
data/lib/capsule_crm/version.rb
CHANGED
data/lib/capsule_crm.rb
CHANGED
@@ -3,8 +3,99 @@ require 'spec_helper'
|
|
3
3
|
describe CapsuleCRM::History 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
|
+
stub_request(:get, /\/api\/opportunity\/milestones$/).
|
10
|
+
to_return(body: File.read('spec/support/milestones.json'))
|
11
|
+
end
|
12
|
+
|
6
13
|
it { should validate_presence_of(:note) }
|
7
14
|
|
15
|
+
describe '_.for_party' do
|
16
|
+
let(:party) { Fabricate.build(:person, id: 1) }
|
17
|
+
|
18
|
+
subject { CapsuleCRM::History._for_party(party.id) }
|
19
|
+
|
20
|
+
context 'when there are some history items' do
|
21
|
+
before do
|
22
|
+
stub_request(:get, /\/api\/party\/#{party.id}\/history$/).
|
23
|
+
to_return(body: File.read('spec/support/all_history.json'))
|
24
|
+
end
|
25
|
+
|
26
|
+
it { should be_a(Array) }
|
27
|
+
|
28
|
+
it do
|
29
|
+
subject.all? { |item| item.is_a?(CapsuleCRM::History) }.should be_true
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
context 'when there are no history items' do
|
34
|
+
before do
|
35
|
+
stub_request(:get, /\/api\/party\/#{party.id}\/history$/).
|
36
|
+
to_return(body: File.read('spec/support/no_history.json'))
|
37
|
+
end
|
38
|
+
|
39
|
+
it { should be_blank }
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
describe '._for_case' do
|
44
|
+
let(:kase) { Fabricate.build(:case, id: 1) }
|
45
|
+
|
46
|
+
subject { CapsuleCRM::History._for_case(kase.id) }
|
47
|
+
|
48
|
+
context 'when there are some history items' do
|
49
|
+
before do
|
50
|
+
stub_request(:get, /\/api\/kase\/#{kase.id}\/history$/).
|
51
|
+
to_return(body: File.read('spec/support/all_history.json'))
|
52
|
+
end
|
53
|
+
|
54
|
+
it { should be_a(Array) }
|
55
|
+
|
56
|
+
it do
|
57
|
+
subject.all? { |item| item.is_a?(CapsuleCRM::History) }.should be_true
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
context 'when there are no history items' do
|
62
|
+
before do
|
63
|
+
stub_request(:get, /\/api\/kase\/#{kase.id}\/history$/).
|
64
|
+
to_return(body: File.read('spec/support/no_history.json'))
|
65
|
+
end
|
66
|
+
|
67
|
+
it { should be_blank }
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
describe '._for_opportunity' do
|
72
|
+
let(:opportunity) { Fabricate.build(:opportunity, id: 1) }
|
73
|
+
|
74
|
+
subject { CapsuleCRM::History._for_opportunity(opportunity.id) }
|
75
|
+
|
76
|
+
context 'when there are some history items' do
|
77
|
+
before do
|
78
|
+
stub_request(:get, /\/api\/opportunity\/#{opportunity.id}\/history$/).
|
79
|
+
to_return(body: File.read('spec/support/all_history.json'))
|
80
|
+
end
|
81
|
+
|
82
|
+
it { should be_a(Array) }
|
83
|
+
|
84
|
+
it do
|
85
|
+
subject.all? { |item| item.is_a?(CapsuleCRM::History) }.should be_true
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
context 'when there are no history items' do
|
90
|
+
before do
|
91
|
+
stub_request(:get, /\/api\/opportunity\/#{opportunity.id}\/history$/).
|
92
|
+
to_return(body: File.read('spec/support/no_history.json'))
|
93
|
+
end
|
94
|
+
|
95
|
+
it { should be_blank }
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
8
99
|
describe 'find' do
|
9
100
|
before do
|
10
101
|
stub_request(:get, /\/api\/history\/100$/).
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe CapsuleCRM::Milestone do
|
4
|
+
before { configure }
|
5
|
+
|
6
|
+
describe '.all' do
|
7
|
+
before do
|
8
|
+
stub_request(:get, /\/api\/opportunity\/milestones$/).
|
9
|
+
to_return(body: File.read('spec/support/milestones.json'))
|
10
|
+
end
|
11
|
+
|
12
|
+
subject { CapsuleCRM::Milestone.all }
|
13
|
+
|
14
|
+
it { should be_a(Array) }
|
15
|
+
|
16
|
+
it do
|
17
|
+
subject.all? { |item| item.is_a?(CapsuleCRM::Milestone) }.should be_true
|
18
|
+
end
|
19
|
+
|
20
|
+
it do
|
21
|
+
expect(subject.first.description).
|
22
|
+
to eql('You have a potential buyer for your offering')
|
23
|
+
end
|
24
|
+
|
25
|
+
it { expect(subject.first.probability).to eql(10.0) }
|
26
|
+
|
27
|
+
it { expect(subject.first.complete).to be_false }
|
28
|
+
end
|
29
|
+
end
|
@@ -3,24 +3,53 @@ require 'spec_helper'
|
|
3
3
|
describe CapsuleCRM::Opportunity do
|
4
4
|
before { configure }
|
5
5
|
|
6
|
-
|
6
|
+
before do
|
7
|
+
stub_request(:get, /\/api\/opportunity\/milestones$/).
|
8
|
+
to_return(body: File.read('spec/support/milestones.json'))
|
9
|
+
end
|
7
10
|
|
8
|
-
it { should validate_presence_of(:
|
11
|
+
it { should validate_presence_of(:name) }
|
9
12
|
|
10
13
|
it { should validate_presence_of(:milestone) }
|
11
14
|
|
12
15
|
context 'when milestone_id is set' do
|
13
16
|
subject { CapsuleCRM::Opportunity.new(milestone_id: 1) }
|
14
17
|
|
15
|
-
|
18
|
+
before do
|
19
|
+
subject.valid?
|
20
|
+
end
|
21
|
+
|
22
|
+
it { subject.errors[:milestone].should be_blank }
|
16
23
|
end
|
17
24
|
|
18
25
|
context 'when milestone is set' do
|
19
|
-
|
26
|
+
let(:milestone) { CapsuleCRM::Milestone.new name: 'Bid' }
|
27
|
+
|
28
|
+
subject { CapsuleCRM::Opportunity.new(milestone: milestone) }
|
20
29
|
|
21
30
|
it { should_not validate_presence_of(:milestone_id) }
|
22
31
|
end
|
23
32
|
|
33
|
+
describe '#milestone=' do
|
34
|
+
context 'when it receives a milestone name' do
|
35
|
+
subject { CapsuleCRM::Opportunity.new(milestone: 'Bid') }
|
36
|
+
|
37
|
+
it { subject.milestone.should be_a(CapsuleCRM::Milestone) }
|
38
|
+
|
39
|
+
it { subject.milestone_id.should_not be_blank }
|
40
|
+
end
|
41
|
+
|
42
|
+
context 'when it receives a milestone object' do
|
43
|
+
let(:milestone) { CapsuleCRM::Milestone.all.first }
|
44
|
+
|
45
|
+
subject { CapsuleCRM::Opportunity.new(milestone: milestone) }
|
46
|
+
|
47
|
+
it { subject.milestone.should be_a(CapsuleCRM::Milestone) }
|
48
|
+
|
49
|
+
it { subject.milestone_id.should_not be_blank }
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
24
53
|
describe '#party=' do
|
25
54
|
let(:opportunity) { Fabricate.build(:opportunity, party: nil) }
|
26
55
|
|
@@ -110,7 +139,7 @@ describe CapsuleCRM::Opportunity do
|
|
110
139
|
|
111
140
|
describe '.find' do
|
112
141
|
before do
|
113
|
-
stub_request(:get,
|
142
|
+
stub_request(:get, /\/api\/opportunity\/1$/).
|
114
143
|
to_return(body: File.read('spec/support/opportunity.json'))
|
115
144
|
end
|
116
145
|
|
@@ -138,7 +167,7 @@ describe CapsuleCRM::Opportunity do
|
|
138
167
|
|
139
168
|
it { subject.owner.should eql('a.user') }
|
140
169
|
|
141
|
-
it { subject.milestone.should eql('Bid') }
|
170
|
+
it { subject.milestone.name.should eql('Bid') }
|
142
171
|
|
143
172
|
it { subject.probability.should eql(50.0) }
|
144
173
|
|
@@ -56,4 +56,29 @@ describe CapsuleCRM::Taggable do
|
|
56
56
|
it { subject.should be_nil }
|
57
57
|
end
|
58
58
|
end
|
59
|
+
|
60
|
+
describe '#remove_tag' do
|
61
|
+
|
62
|
+
subject { taggable_item.remove_tag 'A Test Tag' }
|
63
|
+
|
64
|
+
context 'when the taggable item has an id' do
|
65
|
+
let(:taggable_item) { TaggableItem.new(id: 1) }
|
66
|
+
|
67
|
+
before do
|
68
|
+
loc = 'https://sample.capsulecrm.com/api/party/1000/tag/A%20Test%20Tag'
|
69
|
+
stub_request(:delete, /\/api\/taggableitem\/1\/A%20Test%20Tag$/).
|
70
|
+
to_return(headers: { 'Location' => loc })
|
71
|
+
end
|
72
|
+
|
73
|
+
it { subject.should be_true }
|
74
|
+
end
|
75
|
+
|
76
|
+
context 'when the taggable item has no id' do
|
77
|
+
let(:taggable_item) { TaggableItem.new }
|
78
|
+
|
79
|
+
subject { taggable_item.remove_tag 'A Test Tag' }
|
80
|
+
|
81
|
+
it { subject.should be_nil }
|
82
|
+
end
|
83
|
+
end
|
59
84
|
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
{
|
2
|
+
"milestones": {
|
3
|
+
"milestone": [
|
4
|
+
{
|
5
|
+
"id": "1",
|
6
|
+
"name": "New",
|
7
|
+
"description": "You have a potential buyer for your offering",
|
8
|
+
"probability": "10",
|
9
|
+
"complete": "false"
|
10
|
+
},
|
11
|
+
{
|
12
|
+
"id": "2",
|
13
|
+
"name": "Bid",
|
14
|
+
"description": "You have put forward a bid for your offering",
|
15
|
+
"probability": "50",
|
16
|
+
"complete": "false"
|
17
|
+
},
|
18
|
+
{
|
19
|
+
"id": "3",
|
20
|
+
"name": "Won",
|
21
|
+
"probability": "100",
|
22
|
+
"complete": "true"
|
23
|
+
},
|
24
|
+
{
|
25
|
+
"id": "4",
|
26
|
+
"name": "Lost",
|
27
|
+
"probability": "0",
|
28
|
+
"complete": "true"
|
29
|
+
}
|
30
|
+
]
|
31
|
+
}
|
32
|
+
}
|
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.6.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-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|
@@ -257,6 +257,7 @@ files:
|
|
257
257
|
- lib/capsule_crm/errors/record_invalid.rb
|
258
258
|
- lib/capsule_crm/hash_helper.rb
|
259
259
|
- lib/capsule_crm/history.rb
|
260
|
+
- lib/capsule_crm/milestone.rb
|
260
261
|
- lib/capsule_crm/opportunity.rb
|
261
262
|
- lib/capsule_crm/organization.rb
|
262
263
|
- lib/capsule_crm/participant.rb
|
@@ -285,6 +286,7 @@ files:
|
|
285
286
|
- spec/lib/capsule_crm/currency_spec.rb
|
286
287
|
- spec/lib/capsule_crm/email_spec.rb
|
287
288
|
- spec/lib/capsule_crm/history_spec.rb
|
289
|
+
- spec/lib/capsule_crm/milestone_spec.rb
|
288
290
|
- spec/lib/capsule_crm/opportunity_spec.rb
|
289
291
|
- spec/lib/capsule_crm/organization_spec.rb
|
290
292
|
- spec/lib/capsule_crm/party_spec.rb
|
@@ -308,6 +310,8 @@ files:
|
|
308
310
|
- spec/support/deleted_opportunities.json
|
309
311
|
- spec/support/helpers.rb
|
310
312
|
- spec/support/history.json
|
313
|
+
- spec/support/milestones.json
|
314
|
+
- spec/support/no_history.json
|
311
315
|
- spec/support/opportunity.json
|
312
316
|
- spec/support/organisation.json
|
313
317
|
- spec/support/person.json
|
@@ -353,6 +357,7 @@ test_files:
|
|
353
357
|
- spec/lib/capsule_crm/currency_spec.rb
|
354
358
|
- spec/lib/capsule_crm/email_spec.rb
|
355
359
|
- spec/lib/capsule_crm/history_spec.rb
|
360
|
+
- spec/lib/capsule_crm/milestone_spec.rb
|
356
361
|
- spec/lib/capsule_crm/opportunity_spec.rb
|
357
362
|
- spec/lib/capsule_crm/organization_spec.rb
|
358
363
|
- spec/lib/capsule_crm/party_spec.rb
|
@@ -376,6 +381,8 @@ test_files:
|
|
376
381
|
- spec/support/deleted_opportunities.json
|
377
382
|
- spec/support/helpers.rb
|
378
383
|
- spec/support/history.json
|
384
|
+
- spec/support/milestones.json
|
385
|
+
- spec/support/no_history.json
|
379
386
|
- spec/support/opportunity.json
|
380
387
|
- spec/support/organisation.json
|
381
388
|
- spec/support/person.json
|