freshtrack 0.4.2 → 0.5.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.
- data/History.txt +5 -0
- data/Rakefile +51 -4
- data/VERSION +1 -0
- data/bin/freshtrack +4 -4
- data/config/hoe.rb +2 -2
- data/lib/freshtrack/version.rb +2 -2
- data/lib/freshtrack.rb +13 -4
- data/spec/.bacon +0 -0
- data/spec/core_ext/array_spec.rb +5 -5
- data/spec/core_ext/numeric_spec.rb +2 -2
- data/spec/core_ext/time_spec.rb +3 -3
- data/spec/freshbooks/base_object_spec.rb +7 -7
- data/spec/freshbooks/invoice_spec.rb +40 -40
- data/spec/freshbooks/payment_spec.rb +4 -4
- data/spec/freshbooks/project_spec.rb +119 -119
- data/spec/freshbooks/task_spec.rb +102 -102
- data/spec/freshbooks/time_entry_spec.rb +97 -97
- data/spec/freshtrack_command_spec.rb +77 -45
- data/spec/freshtrack_spec.rb +237 -130
- data/spec/spec_helper.rb +3 -21
- data/spec/time_collectors/one_inch_punch_spec.rb +55 -53
- data/spec/time_collectors/punch_spec.rb +74 -66
- metadata +83 -54
- data/spec/spec.opts +0 -3
@@ -1,34 +1,34 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper.rb')
|
2
2
|
|
3
3
|
describe FreshBooks::Task do
|
4
|
-
before
|
4
|
+
before do
|
5
5
|
@task = FreshBooks::Task.new
|
6
6
|
end
|
7
7
|
|
8
8
|
describe 'attributes' do
|
9
9
|
it 'should have a task_id' do
|
10
|
-
@task.should
|
10
|
+
@task.should.respond_to(:task_id)
|
11
11
|
end
|
12
12
|
|
13
13
|
it 'should have a name' do
|
14
|
-
@task.should
|
14
|
+
@task.should.respond_to(:name)
|
15
15
|
end
|
16
16
|
|
17
17
|
it 'should have billable' do
|
18
|
-
@task.should
|
18
|
+
@task.should.respond_to(:billable)
|
19
19
|
end
|
20
20
|
|
21
21
|
it 'should have a rate' do
|
22
|
-
@task.should
|
22
|
+
@task.should.respond_to(:rate)
|
23
23
|
end
|
24
24
|
|
25
25
|
it 'should have a description' do
|
26
|
-
@task.should
|
26
|
+
@task.should.respond_to(:description)
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
30
30
|
describe 'type mappings' do
|
31
|
-
before
|
31
|
+
before do
|
32
32
|
@mapping = FreshBooks::Task::TYPE_MAPPINGS
|
33
33
|
end
|
34
34
|
|
@@ -42,25 +42,25 @@ describe FreshBooks::Task do
|
|
42
42
|
end
|
43
43
|
|
44
44
|
describe 'creating an instance' do
|
45
|
-
before
|
46
|
-
@response =
|
47
|
-
FreshBooks.
|
45
|
+
before do
|
46
|
+
@response = mock('response', :success? => nil)
|
47
|
+
FreshBooks.stub!(:call_api).and_return(@response)
|
48
48
|
end
|
49
49
|
|
50
50
|
it 'should issue a request with the instance' do
|
51
|
-
FreshBooks.
|
51
|
+
FreshBooks.should.receive(:call_api).with('task.create', 'task' => @task).and_return(@response)
|
52
52
|
@task.create
|
53
53
|
end
|
54
54
|
|
55
55
|
describe 'with a successful request' do
|
56
|
-
before
|
56
|
+
before do
|
57
57
|
@task_id = 5
|
58
|
-
@response.
|
59
|
-
@response.
|
58
|
+
@response.stub!(:elements).and_return([mock('pre element'), mock('element', :text => @task_id.to_s), mock('post element')])
|
59
|
+
@response.stub!(:success?).and_return(true)
|
60
60
|
end
|
61
61
|
|
62
62
|
it 'should set the ID from the response' do
|
63
|
-
@task.
|
63
|
+
@task.should.receive(:task_id=).with(@task_id)
|
64
64
|
@task.create
|
65
65
|
end
|
66
66
|
|
@@ -70,280 +70,280 @@ describe FreshBooks::Task do
|
|
70
70
|
end
|
71
71
|
|
72
72
|
describe 'with an unsuccessful request' do
|
73
|
-
before
|
74
|
-
@response.
|
73
|
+
before do
|
74
|
+
@response.stub!(:success?).and_return(false)
|
75
75
|
end
|
76
76
|
|
77
77
|
it 'should not set the ID' do
|
78
|
-
@task.
|
78
|
+
@task.should.receive(:task_id=).never
|
79
79
|
@task.create
|
80
80
|
end
|
81
81
|
|
82
82
|
it 'should return nil' do
|
83
|
-
@task.create.should
|
83
|
+
@task.create.should.be.nil
|
84
84
|
end
|
85
85
|
end
|
86
86
|
end
|
87
87
|
|
88
88
|
describe 'updating an instance' do
|
89
|
-
before
|
90
|
-
@response =
|
91
|
-
FreshBooks.
|
89
|
+
before do
|
90
|
+
@response = mock('response', :success? => nil)
|
91
|
+
FreshBooks.stub!(:call_api).and_return(@response)
|
92
92
|
end
|
93
93
|
|
94
94
|
it 'should issue a request with the instance' do
|
95
|
-
FreshBooks.
|
95
|
+
FreshBooks.should.receive(:call_api).with('task.update', 'task' => @task).and_return(@response)
|
96
96
|
@task.update
|
97
97
|
end
|
98
98
|
|
99
99
|
describe 'with a successful request' do
|
100
|
-
before
|
101
|
-
@response.
|
100
|
+
before do
|
101
|
+
@response.stub!(:success?).and_return(true)
|
102
102
|
end
|
103
103
|
|
104
104
|
it 'should return true' do
|
105
|
-
@task.update.should
|
105
|
+
@task.update.should == true
|
106
106
|
end
|
107
107
|
end
|
108
108
|
|
109
109
|
describe 'with an unsuccessful request' do
|
110
|
-
before
|
111
|
-
@response.
|
110
|
+
before do
|
111
|
+
@response.stub!(:success?).and_return(false)
|
112
112
|
end
|
113
113
|
|
114
114
|
it 'should return false' do
|
115
|
-
@task.update.should
|
115
|
+
@task.update.should == false
|
116
116
|
end
|
117
117
|
end
|
118
118
|
end
|
119
119
|
|
120
120
|
describe 'deleting an instance' do
|
121
|
-
before
|
121
|
+
before do
|
122
122
|
@task_id = '5'
|
123
|
-
@response =
|
124
|
-
FreshBooks.
|
123
|
+
@response = mock('response', :success? => nil)
|
124
|
+
FreshBooks.stub!(:call_api).and_return(@response)
|
125
125
|
end
|
126
126
|
|
127
127
|
describe 'from the class' do
|
128
128
|
it 'should require an argument' do
|
129
|
-
lambda { FreshBooks::Task.delete }.should
|
129
|
+
lambda { FreshBooks::Task.delete }.should.raise(ArgumentError)
|
130
130
|
end
|
131
131
|
|
132
132
|
it 'should accept an argument' do
|
133
|
-
lambda { FreshBooks::Task.delete('arg') }.
|
133
|
+
lambda { FreshBooks::Task.delete('arg') }.should.not.raise(ArgumentError)
|
134
134
|
end
|
135
135
|
|
136
136
|
it 'should issue a request with the supplied ID' do
|
137
|
-
FreshBooks.
|
137
|
+
FreshBooks.should.receive(:call_api).with('task.delete', 'task_id' => @task_id).and_return(@response)
|
138
138
|
FreshBooks::Task.delete(@task_id)
|
139
139
|
end
|
140
140
|
|
141
141
|
describe 'with a successful request' do
|
142
|
-
before
|
143
|
-
@response.
|
142
|
+
before do
|
143
|
+
@response.stub!(:success?).and_return(true)
|
144
144
|
end
|
145
145
|
|
146
146
|
it 'should return true' do
|
147
|
-
FreshBooks::Task.delete(@task_id).should
|
147
|
+
FreshBooks::Task.delete(@task_id).should == true
|
148
148
|
end
|
149
149
|
end
|
150
150
|
|
151
151
|
describe 'with an unsuccessful request' do
|
152
|
-
before
|
153
|
-
@response.
|
152
|
+
before do
|
153
|
+
@response.stub!(:success?).and_return(false)
|
154
154
|
end
|
155
155
|
|
156
156
|
it 'should return false' do
|
157
|
-
FreshBooks::Task.delete(@task_id).should
|
157
|
+
FreshBooks::Task.delete(@task_id).should == false
|
158
158
|
end
|
159
159
|
end
|
160
160
|
end
|
161
161
|
|
162
162
|
describe 'from the instance' do
|
163
|
-
before
|
164
|
-
@task.
|
165
|
-
FreshBooks::Task.
|
163
|
+
before do
|
164
|
+
@task.stub!(:task_id).and_return(@task_id)
|
165
|
+
FreshBooks::Task.stub!(:delete)
|
166
166
|
end
|
167
167
|
|
168
168
|
it 'should delegate to the class' do
|
169
|
-
FreshBooks::Task.
|
169
|
+
FreshBooks::Task.should.receive(:delete)
|
170
170
|
@task.delete
|
171
171
|
end
|
172
172
|
|
173
173
|
it 'should pass its ID to the class method' do
|
174
|
-
FreshBooks::Task.
|
174
|
+
FreshBooks::Task.should.receive(:delete).with(@task_id)
|
175
175
|
@task.delete
|
176
176
|
end
|
177
177
|
|
178
178
|
it 'should return the result from the class method' do
|
179
|
-
val =
|
180
|
-
FreshBooks::Task.
|
179
|
+
val = mock('return val')
|
180
|
+
FreshBooks::Task.stub!(:delete).and_return(val)
|
181
181
|
@task.delete.should == val
|
182
182
|
end
|
183
183
|
end
|
184
184
|
end
|
185
185
|
|
186
186
|
describe 'getting an instance' do
|
187
|
-
before
|
187
|
+
before do
|
188
188
|
@task_id = 1
|
189
|
-
@element =
|
190
|
-
@response =
|
191
|
-
FreshBooks.
|
189
|
+
@element = mock('element')
|
190
|
+
@response = mock('response', :elements => [mock('pre element'), @element, mock('post element')], :success? => nil)
|
191
|
+
FreshBooks.stub!(:call_api).and_return(@response)
|
192
192
|
end
|
193
193
|
|
194
194
|
it 'should require an argument' do
|
195
|
-
lambda { FreshBooks::Task.get }.should
|
195
|
+
lambda { FreshBooks::Task.get }.should.raise(ArgumentError)
|
196
196
|
end
|
197
197
|
|
198
198
|
it 'should accept an argument' do
|
199
|
-
lambda { FreshBooks::Task.get(@task_id) }.
|
199
|
+
lambda { FreshBooks::Task.get(@task_id) }.should.not.raise(ArgumentError)
|
200
200
|
end
|
201
201
|
|
202
202
|
it 'should issue a request for the supplied ID' do
|
203
|
-
FreshBooks.
|
203
|
+
FreshBooks.should.receive(:call_api).with('task.get', 'task_id' => @task_id).and_return(@response)
|
204
204
|
FreshBooks::Task.get(@task_id)
|
205
205
|
end
|
206
206
|
|
207
207
|
describe 'with a successful request' do
|
208
|
-
before
|
209
|
-
@response.
|
208
|
+
before do
|
209
|
+
@response.stub!(:success?).and_return(true)
|
210
210
|
end
|
211
211
|
|
212
212
|
it 'should instantiate a new task instance from the request' do
|
213
|
-
FreshBooks::Task.
|
213
|
+
FreshBooks::Task.should.receive(:new_from_xml).with(@element)
|
214
214
|
FreshBooks::Task.get(@task_id)
|
215
215
|
end
|
216
216
|
|
217
217
|
it 'should return the task instance' do
|
218
|
-
val =
|
219
|
-
FreshBooks::Task.
|
218
|
+
val = mock('return val')
|
219
|
+
FreshBooks::Task.stub!(:new_from_xml).and_return(val)
|
220
220
|
FreshBooks::Task.get(@task_id).should == val
|
221
221
|
end
|
222
222
|
end
|
223
223
|
|
224
224
|
describe 'with an unsuccessful request' do
|
225
|
-
before
|
226
|
-
@response.
|
225
|
+
before do
|
226
|
+
@response.stub!(:success?).and_return(false)
|
227
227
|
end
|
228
228
|
|
229
229
|
it 'should return nil' do
|
230
|
-
FreshBooks::Task.get(@task_id).should
|
230
|
+
FreshBooks::Task.get(@task_id).should.be.nil
|
231
231
|
end
|
232
232
|
end
|
233
233
|
end
|
234
234
|
|
235
235
|
describe 'getting a list' do
|
236
|
-
before
|
236
|
+
before do
|
237
237
|
@task_id = 1
|
238
|
-
@elements = Array.new(3) {
|
239
|
-
@response =
|
240
|
-
FreshBooks.
|
238
|
+
@elements = Array.new(3) { mock('list element') }
|
239
|
+
@response = mock('response', :elements => [mock('pre element'), mock('element', :elements => @elements), mock('post element')], :success? => nil)
|
240
|
+
FreshBooks.stub!(:call_api).and_return(@response)
|
241
241
|
end
|
242
242
|
|
243
243
|
it 'should not require an argument' do
|
244
|
-
lambda { FreshBooks::Task.list }.
|
244
|
+
lambda { FreshBooks::Task.list }.should.not.raise(ArgumentError)
|
245
245
|
end
|
246
246
|
|
247
247
|
it 'should accept an argument' do
|
248
|
-
lambda { FreshBooks::Task.list('arg') }.
|
248
|
+
lambda { FreshBooks::Task.list('arg') }.should.not.raise(ArgumentError)
|
249
249
|
end
|
250
250
|
|
251
251
|
it 'should issue a request for the task list' do
|
252
|
-
FreshBooks.
|
252
|
+
FreshBooks.should.receive(:call_api).with('task.list', {}).and_return(@response)
|
253
253
|
FreshBooks::Task.list
|
254
254
|
end
|
255
255
|
|
256
256
|
it 'should pass the argument to the request' do
|
257
|
-
arg =
|
258
|
-
FreshBooks.
|
257
|
+
arg = mock('arg')
|
258
|
+
FreshBooks.should.receive(:call_api).with('task.list', arg).and_return(@response)
|
259
259
|
FreshBooks::Task.list(arg)
|
260
260
|
end
|
261
261
|
|
262
262
|
describe 'with a successful request' do
|
263
|
-
before
|
264
|
-
@response.
|
263
|
+
before do
|
264
|
+
@response.stub!(:success?).and_return(true)
|
265
265
|
end
|
266
266
|
|
267
267
|
it 'should instantiate new task instances from the request' do
|
268
268
|
@elements.each do |element|
|
269
|
-
FreshBooks::Task.
|
269
|
+
FreshBooks::Task.should.receive(:new_from_xml).with(element)
|
270
270
|
end
|
271
271
|
FreshBooks::Task.list
|
272
272
|
end
|
273
273
|
|
274
274
|
it 'should return the task instances' do
|
275
|
-
vals = Array.new(@elements.length) {
|
275
|
+
vals = Array.new(@elements.length) { mock('return val') }
|
276
276
|
@elements.each_with_index do |element, i|
|
277
|
-
FreshBooks::Task.
|
277
|
+
FreshBooks::Task.stub!(:new_from_xml).with(element).and_return(vals[i])
|
278
278
|
end
|
279
279
|
FreshBooks::Task.list.should == vals
|
280
280
|
end
|
281
281
|
end
|
282
282
|
|
283
283
|
describe 'with an unsuccessful request' do
|
284
|
-
before
|
285
|
-
@response.
|
284
|
+
before do
|
285
|
+
@response.stub!(:success?).and_return(false)
|
286
286
|
end
|
287
287
|
|
288
288
|
it 'should return nil' do
|
289
|
-
FreshBooks::Task.list.should
|
289
|
+
FreshBooks::Task.list.should.be.nil
|
290
290
|
end
|
291
291
|
end
|
292
292
|
end
|
293
293
|
|
294
294
|
describe 'getting by name' do
|
295
|
-
before
|
295
|
+
before do
|
296
296
|
@name = 'taskname'
|
297
|
-
FreshBooks::Task.
|
297
|
+
FreshBooks::Task.stub!(:list).and_return([])
|
298
298
|
end
|
299
299
|
|
300
300
|
it 'should require an argument' do
|
301
|
-
lambda { FreshBooks::Task.find_by_name }.should
|
301
|
+
lambda { FreshBooks::Task.find_by_name }.should.raise(ArgumentError)
|
302
302
|
end
|
303
303
|
|
304
304
|
it 'should accept an argument' do
|
305
|
-
lambda { FreshBooks::Task.find_by_name(@name) }.
|
305
|
+
lambda { FreshBooks::Task.find_by_name(@name) }.should.not.raise(ArgumentError)
|
306
306
|
end
|
307
307
|
|
308
308
|
it 'should return the task with a matching name' do
|
309
|
-
tasks = Array.new(3) { |i|
|
310
|
-
tasks[1,0] = expected =
|
311
|
-
FreshBooks::Task.
|
309
|
+
tasks = Array.new(3) { |i| mock('task', :name => "task #{i}" ) }
|
310
|
+
tasks[1,0] = expected = mock('task', :name => @name)
|
311
|
+
FreshBooks::Task.stub!(:list).and_return(tasks)
|
312
312
|
FreshBooks::Task.find_by_name(@name).should == expected
|
313
313
|
end
|
314
314
|
|
315
315
|
it 'should return the first task found whose name matches' do
|
316
|
-
tasks = Array.new(3) { |i|
|
317
|
-
tasks[1,0] = expected =
|
318
|
-
tasks[3,0] =
|
319
|
-
FreshBooks::Task.
|
316
|
+
tasks = Array.new(3) { |i| mock('task', :name => "task #{i}" ) }
|
317
|
+
tasks[1,0] = expected = mock('task', :name => @name)
|
318
|
+
tasks[3,0] = mock('task', :name => @name)
|
319
|
+
FreshBooks::Task.stub!(:list).and_return(tasks)
|
320
320
|
FreshBooks::Task.find_by_name(@name).should == expected
|
321
321
|
end
|
322
322
|
|
323
323
|
it 'should return nil if no task with matching name found' do
|
324
|
-
tasks = Array.new(3) { |i|
|
325
|
-
FreshBooks::Task.
|
326
|
-
FreshBooks::Task.find_by_name(@name).should
|
324
|
+
tasks = Array.new(3) { |i| mock('task', :name => "task #{i}" ) }
|
325
|
+
FreshBooks::Task.stub!(:list).and_return(tasks)
|
326
|
+
FreshBooks::Task.find_by_name(@name).should.be.nil
|
327
327
|
end
|
328
328
|
end
|
329
329
|
|
330
330
|
it 'should have time entries' do
|
331
|
-
@task.should
|
331
|
+
@task.should.respond_to(:time_entries)
|
332
332
|
end
|
333
333
|
|
334
334
|
describe 'time entries' do
|
335
335
|
it 'should list time entries based on task ID' do
|
336
|
-
task_id =
|
337
|
-
@task.
|
338
|
-
FreshBooks::TimeEntry.
|
336
|
+
task_id = mock('task ID')
|
337
|
+
@task.stub!(:task_id).and_return(task_id)
|
338
|
+
FreshBooks::TimeEntry.should.receive(:list).with('task_id' => task_id)
|
339
339
|
@task.time_entries
|
340
340
|
end
|
341
341
|
|
342
342
|
it 'should return found time entries' do
|
343
|
-
time_entries =
|
344
|
-
task_id =
|
345
|
-
@task.
|
346
|
-
FreshBooks::TimeEntry.
|
343
|
+
time_entries = mock('time entries')
|
344
|
+
task_id = mock('task ID')
|
345
|
+
@task.stub!(:task_id).and_return(task_id)
|
346
|
+
FreshBooks::TimeEntry.stub!(:list).with('task_id' => task_id).and_return(time_entries)
|
347
347
|
@task.time_entries.should == time_entries
|
348
348
|
end
|
349
349
|
end
|