freshtrack 0.4.2 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- 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,38 +1,38 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper.rb')
|
2
2
|
|
3
3
|
describe FreshBooks::TimeEntry do
|
4
|
-
before
|
4
|
+
before do
|
5
5
|
@time_entry = FreshBooks::TimeEntry.new
|
6
6
|
end
|
7
7
|
|
8
8
|
describe 'attributes' do
|
9
9
|
it 'should have a time_entry_id' do
|
10
|
-
@time_entry.should
|
10
|
+
@time_entry.should.respond_to(:time_entry_id)
|
11
11
|
end
|
12
12
|
|
13
13
|
it 'should have a project_id' do
|
14
|
-
@time_entry.should
|
14
|
+
@time_entry.should.respond_to(:project_id)
|
15
15
|
end
|
16
16
|
|
17
17
|
it 'should have a task_id' do
|
18
|
-
@time_entry.should
|
18
|
+
@time_entry.should.respond_to(:task_id)
|
19
19
|
end
|
20
20
|
|
21
21
|
it 'should have hours' do
|
22
|
-
@time_entry.should
|
22
|
+
@time_entry.should.respond_to(:hours)
|
23
23
|
end
|
24
24
|
|
25
25
|
it 'should have a date' do
|
26
|
-
@time_entry.should
|
26
|
+
@time_entry.should.respond_to(:date)
|
27
27
|
end
|
28
28
|
|
29
29
|
it 'should have notes' do
|
30
|
-
@time_entry.should
|
30
|
+
@time_entry.should.respond_to(:notes)
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
34
34
|
describe 'type mappings' do
|
35
|
-
before
|
35
|
+
before do
|
36
36
|
@mapping = FreshBooks::TimeEntry::TYPE_MAPPINGS
|
37
37
|
end
|
38
38
|
|
@@ -58,25 +58,25 @@ describe FreshBooks::TimeEntry do
|
|
58
58
|
end
|
59
59
|
|
60
60
|
describe 'creating an instance' do
|
61
|
-
before
|
62
|
-
@response =
|
63
|
-
FreshBooks.
|
61
|
+
before do
|
62
|
+
@response = mock('response', :success? => nil)
|
63
|
+
FreshBooks.stub!(:call_api).and_return(@response)
|
64
64
|
end
|
65
65
|
|
66
66
|
it 'should issue a request with the instance' do
|
67
|
-
FreshBooks.
|
67
|
+
FreshBooks.should.receive(:call_api).with('time_entry.create', 'time_entry' => @time_entry).and_return(@response)
|
68
68
|
@time_entry.create
|
69
69
|
end
|
70
70
|
|
71
71
|
describe 'with a successful request' do
|
72
|
-
before
|
72
|
+
before do
|
73
73
|
@time_entry_id = 5
|
74
|
-
@response.
|
75
|
-
@response.
|
74
|
+
@response.stub!(:elements).and_return([mock('pre element'), mock('element', :text => @time_entry_id.to_s), mock('post element')])
|
75
|
+
@response.stub!(:success?).and_return(true)
|
76
76
|
end
|
77
77
|
|
78
78
|
it 'should set the ID from the response' do
|
79
|
-
@time_entry.
|
79
|
+
@time_entry.should.receive(:time_entry_id=).with(@time_entry_id)
|
80
80
|
@time_entry.create
|
81
81
|
end
|
82
82
|
|
@@ -86,265 +86,265 @@ describe FreshBooks::TimeEntry do
|
|
86
86
|
end
|
87
87
|
|
88
88
|
describe 'with an unsuccessful request' do
|
89
|
-
before
|
90
|
-
@response.
|
89
|
+
before do
|
90
|
+
@response.stub!(:success?).and_return(false)
|
91
91
|
end
|
92
92
|
|
93
93
|
it 'should not set the ID' do
|
94
|
-
@time_entry.
|
94
|
+
@time_entry.should.receive(:time_entry_id=).never
|
95
95
|
@time_entry.create
|
96
96
|
end
|
97
97
|
|
98
98
|
it 'should return nil' do
|
99
|
-
@time_entry.create.should
|
99
|
+
@time_entry.create.should.be.nil
|
100
100
|
end
|
101
101
|
end
|
102
102
|
end
|
103
103
|
|
104
104
|
describe 'updating an instance' do
|
105
|
-
before
|
106
|
-
@response =
|
107
|
-
FreshBooks.
|
105
|
+
before do
|
106
|
+
@response = mock('response', :success? => nil)
|
107
|
+
FreshBooks.stub!(:call_api).and_return(@response)
|
108
108
|
end
|
109
109
|
|
110
110
|
it 'should issue a request with the instance' do
|
111
|
-
FreshBooks.
|
111
|
+
FreshBooks.should.receive(:call_api).with('time_entry.update', 'time_entry' => @time_entry).and_return(@response)
|
112
112
|
@time_entry.update
|
113
113
|
end
|
114
114
|
|
115
115
|
describe 'with a successful request' do
|
116
|
-
before
|
117
|
-
@response.
|
116
|
+
before do
|
117
|
+
@response.stub!(:success?).and_return(true)
|
118
118
|
end
|
119
119
|
|
120
120
|
it 'should return true' do
|
121
|
-
@time_entry.update.should
|
121
|
+
@time_entry.update.should == true
|
122
122
|
end
|
123
123
|
end
|
124
124
|
|
125
125
|
describe 'with an unsuccessful request' do
|
126
|
-
before
|
127
|
-
@response.
|
126
|
+
before do
|
127
|
+
@response.stub!(:success?).and_return(false)
|
128
128
|
end
|
129
129
|
|
130
130
|
it 'should return false' do
|
131
|
-
@time_entry.update.should
|
131
|
+
@time_entry.update.should == false
|
132
132
|
end
|
133
133
|
end
|
134
134
|
end
|
135
135
|
|
136
136
|
describe 'deleting an instance' do
|
137
|
-
before
|
137
|
+
before do
|
138
138
|
@time_entry_id = '5'
|
139
|
-
@response =
|
140
|
-
FreshBooks.
|
139
|
+
@response = mock('response', :success? => nil)
|
140
|
+
FreshBooks.stub!(:call_api).and_return(@response)
|
141
141
|
end
|
142
142
|
|
143
143
|
describe 'from the class' do
|
144
144
|
it 'should require an argument' do
|
145
|
-
lambda { FreshBooks::TimeEntry.delete }.should
|
145
|
+
lambda { FreshBooks::TimeEntry.delete }.should.raise(ArgumentError)
|
146
146
|
end
|
147
147
|
|
148
148
|
it 'should accept an argument' do
|
149
|
-
lambda { FreshBooks::TimeEntry.delete('arg') }.
|
149
|
+
lambda { FreshBooks::TimeEntry.delete('arg') }.should.not.raise(ArgumentError)
|
150
150
|
end
|
151
151
|
|
152
152
|
it 'should issue a request with the supplied ID' do
|
153
|
-
FreshBooks.
|
153
|
+
FreshBooks.should.receive(:call_api).with('time_entry.delete', 'time_entry_id' => @time_entry_id).and_return(@response)
|
154
154
|
FreshBooks::TimeEntry.delete(@time_entry_id)
|
155
155
|
end
|
156
156
|
|
157
157
|
describe 'with a successful request' do
|
158
|
-
before
|
159
|
-
@response.
|
158
|
+
before do
|
159
|
+
@response.stub!(:success?).and_return(true)
|
160
160
|
end
|
161
161
|
|
162
162
|
it 'should return true' do
|
163
|
-
FreshBooks::TimeEntry.delete(@time_entry_id).should
|
163
|
+
FreshBooks::TimeEntry.delete(@time_entry_id).should == true
|
164
164
|
end
|
165
165
|
end
|
166
166
|
|
167
167
|
describe 'with an unsuccessful request' do
|
168
|
-
before
|
169
|
-
@response.
|
168
|
+
before do
|
169
|
+
@response.stub!(:success?).and_return(false)
|
170
170
|
end
|
171
171
|
|
172
172
|
it 'should return false' do
|
173
|
-
FreshBooks::TimeEntry.delete(@time_entry_id).should
|
173
|
+
FreshBooks::TimeEntry.delete(@time_entry_id).should == false
|
174
174
|
end
|
175
175
|
end
|
176
176
|
end
|
177
177
|
|
178
178
|
describe 'from the instance' do
|
179
|
-
before
|
180
|
-
@time_entry.
|
181
|
-
FreshBooks::TimeEntry.
|
179
|
+
before do
|
180
|
+
@time_entry.stub!(:time_entry_id).and_return(@time_entry_id)
|
181
|
+
FreshBooks::TimeEntry.stub!(:delete)
|
182
182
|
end
|
183
183
|
|
184
184
|
it 'should delegate to the class' do
|
185
|
-
FreshBooks::TimeEntry.
|
185
|
+
FreshBooks::TimeEntry.should.receive(:delete)
|
186
186
|
@time_entry.delete
|
187
187
|
end
|
188
188
|
|
189
189
|
it 'should pass its ID to the class method' do
|
190
|
-
FreshBooks::TimeEntry.
|
190
|
+
FreshBooks::TimeEntry.should.receive(:delete).with(@time_entry_id)
|
191
191
|
@time_entry.delete
|
192
192
|
end
|
193
193
|
|
194
194
|
it 'should return the result from the class method' do
|
195
|
-
val =
|
196
|
-
FreshBooks::TimeEntry.
|
195
|
+
val = mock('return val')
|
196
|
+
FreshBooks::TimeEntry.stub!(:delete).and_return(val)
|
197
197
|
@time_entry.delete.should == val
|
198
198
|
end
|
199
199
|
end
|
200
200
|
end
|
201
201
|
|
202
202
|
describe 'getting an instance' do
|
203
|
-
before
|
203
|
+
before do
|
204
204
|
@time_entry_id = 1
|
205
|
-
@element =
|
206
|
-
@response =
|
207
|
-
FreshBooks.
|
205
|
+
@element = mock('element')
|
206
|
+
@response = mock('response', :elements => [mock('pre element'), @element, mock('post element')], :success? => nil)
|
207
|
+
FreshBooks.stub!(:call_api).and_return(@response)
|
208
208
|
end
|
209
209
|
|
210
210
|
it 'should require an argument' do
|
211
|
-
lambda { FreshBooks::TimeEntry.get }.should
|
211
|
+
lambda { FreshBooks::TimeEntry.get }.should.raise(ArgumentError)
|
212
212
|
end
|
213
213
|
|
214
214
|
it 'should accept an argument' do
|
215
|
-
lambda { FreshBooks::TimeEntry.get(@time_entry_id) }.
|
215
|
+
lambda { FreshBooks::TimeEntry.get(@time_entry_id) }.should.not.raise(ArgumentError)
|
216
216
|
end
|
217
217
|
|
218
218
|
it 'should issue a request for the supplied ID' do
|
219
|
-
FreshBooks.
|
219
|
+
FreshBooks.should.receive(:call_api).with('time_entry.get', 'time_entry_id' => @time_entry_id).and_return(@response)
|
220
220
|
FreshBooks::TimeEntry.get(@time_entry_id)
|
221
221
|
end
|
222
222
|
|
223
223
|
describe 'with a successful request' do
|
224
|
-
before
|
225
|
-
@response.
|
224
|
+
before do
|
225
|
+
@response.stub!(:success?).and_return(true)
|
226
226
|
end
|
227
227
|
|
228
228
|
it 'should instantiate a new time_entry instance from the request' do
|
229
|
-
FreshBooks::TimeEntry.
|
229
|
+
FreshBooks::TimeEntry.should.receive(:new_from_xml).with(@element)
|
230
230
|
FreshBooks::TimeEntry.get(@time_entry_id)
|
231
231
|
end
|
232
232
|
|
233
233
|
it 'should return the time_entry instance' do
|
234
|
-
val =
|
235
|
-
FreshBooks::TimeEntry.
|
234
|
+
val = mock('return val')
|
235
|
+
FreshBooks::TimeEntry.stub!(:new_from_xml).and_return(val)
|
236
236
|
FreshBooks::TimeEntry.get(@time_entry_id).should == val
|
237
237
|
end
|
238
238
|
end
|
239
239
|
|
240
240
|
describe 'with an unsuccessful request' do
|
241
|
-
before
|
242
|
-
@response.
|
241
|
+
before do
|
242
|
+
@response.stub!(:success?).and_return(false)
|
243
243
|
end
|
244
244
|
|
245
245
|
it 'should return nil' do
|
246
|
-
FreshBooks::TimeEntry.get(@time_entry_id).should
|
246
|
+
FreshBooks::TimeEntry.get(@time_entry_id).should.be.nil
|
247
247
|
end
|
248
248
|
end
|
249
249
|
end
|
250
250
|
|
251
251
|
describe 'getting a list' do
|
252
|
-
before
|
252
|
+
before do
|
253
253
|
@time_entry_id = 1
|
254
|
-
@elements = Array.new(3) {
|
255
|
-
@response =
|
256
|
-
FreshBooks.
|
254
|
+
@elements = Array.new(3) { mock('list element') }
|
255
|
+
@response = mock('response', :elements => [mock('pre element'), mock('element', :elements => @elements), mock('post element')], :success? => nil)
|
256
|
+
FreshBooks.stub!(:call_api).and_return(@response)
|
257
257
|
end
|
258
258
|
|
259
259
|
it 'should not require an argument' do
|
260
|
-
lambda { FreshBooks::TimeEntry.list }.
|
260
|
+
lambda { FreshBooks::TimeEntry.list }.should.not.raise(ArgumentError)
|
261
261
|
end
|
262
262
|
|
263
263
|
it 'should accept an argument' do
|
264
|
-
lambda { FreshBooks::TimeEntry.list('arg') }.
|
264
|
+
lambda { FreshBooks::TimeEntry.list('arg') }.should.not.raise(ArgumentError)
|
265
265
|
end
|
266
266
|
|
267
267
|
it 'should issue a request for the time_entry list' do
|
268
|
-
FreshBooks.
|
268
|
+
FreshBooks.should.receive(:call_api).with('time_entry.list', {}).and_return(@response)
|
269
269
|
FreshBooks::TimeEntry.list
|
270
270
|
end
|
271
271
|
|
272
272
|
it 'should pass the argument to the request' do
|
273
|
-
arg =
|
274
|
-
FreshBooks.
|
273
|
+
arg = mock('arg')
|
274
|
+
FreshBooks.should.receive(:call_api).with('time_entry.list', arg).and_return(@response)
|
275
275
|
FreshBooks::TimeEntry.list(arg)
|
276
276
|
end
|
277
277
|
|
278
278
|
describe 'with a successful request' do
|
279
|
-
before
|
280
|
-
@response.
|
279
|
+
before do
|
280
|
+
@response.stub!(:success?).and_return(true)
|
281
281
|
end
|
282
282
|
|
283
283
|
it 'should instantiate new time_entry instances from the request' do
|
284
284
|
@elements.each do |element|
|
285
|
-
FreshBooks::TimeEntry.
|
285
|
+
FreshBooks::TimeEntry.should.receive(:new_from_xml).with(element)
|
286
286
|
end
|
287
287
|
FreshBooks::TimeEntry.list
|
288
288
|
end
|
289
289
|
|
290
290
|
it 'should return the time_entry instances' do
|
291
|
-
vals = Array.new(@elements.length) {
|
291
|
+
vals = Array.new(@elements.length) { mock('return val') }
|
292
292
|
@elements.each_with_index do |element, i|
|
293
|
-
FreshBooks::TimeEntry.
|
293
|
+
FreshBooks::TimeEntry.stub!(:new_from_xml).with(element).and_return(vals[i])
|
294
294
|
end
|
295
295
|
FreshBooks::TimeEntry.list.should == vals
|
296
296
|
end
|
297
297
|
end
|
298
298
|
|
299
299
|
describe 'with an unsuccessful request' do
|
300
|
-
before
|
301
|
-
@response.
|
300
|
+
before do
|
301
|
+
@response.stub!(:success?).and_return(false)
|
302
302
|
end
|
303
303
|
|
304
304
|
it 'should return nil' do
|
305
|
-
FreshBooks::TimeEntry.list.should
|
305
|
+
FreshBooks::TimeEntry.list.should.be.nil
|
306
306
|
end
|
307
307
|
end
|
308
308
|
end
|
309
309
|
|
310
310
|
it 'should have a task' do
|
311
|
-
@time_entry.should
|
311
|
+
@time_entry.should.respond_to(:task)
|
312
312
|
end
|
313
313
|
|
314
314
|
describe 'task' do
|
315
315
|
it 'should find task based on task_id' do
|
316
|
-
task_id =
|
317
|
-
@time_entry.
|
318
|
-
FreshBooks::Task.
|
316
|
+
task_id = mock('task ID')
|
317
|
+
@time_entry.stub!(:task_id).and_return(task_id)
|
318
|
+
FreshBooks::Task.should.receive(:get).with(task_id)
|
319
319
|
@time_entry.task
|
320
320
|
end
|
321
321
|
|
322
322
|
it 'should return found task' do
|
323
|
-
task =
|
324
|
-
task_id =
|
325
|
-
@time_entry.
|
326
|
-
FreshBooks::Task.
|
323
|
+
task = mock('task')
|
324
|
+
task_id = mock('task ID')
|
325
|
+
@time_entry.stub!(:task_id).and_return(task_id)
|
326
|
+
FreshBooks::Task.should.receive(:get).with(task_id).and_return(task)
|
327
327
|
@time_entry.task.should == task
|
328
328
|
end
|
329
329
|
end
|
330
330
|
|
331
331
|
it 'should have a project' do
|
332
|
-
@time_entry.should
|
332
|
+
@time_entry.should.respond_to(:project)
|
333
333
|
end
|
334
334
|
|
335
335
|
describe 'project' do
|
336
336
|
it 'should find project based on project_id' do
|
337
|
-
project_id =
|
338
|
-
@time_entry.
|
339
|
-
FreshBooks::Project.
|
337
|
+
project_id = mock('project ID')
|
338
|
+
@time_entry.stub!(:project_id).and_return(project_id)
|
339
|
+
FreshBooks::Project.should.receive(:get).with(project_id)
|
340
340
|
@time_entry.project
|
341
341
|
end
|
342
342
|
|
343
343
|
it 'should return found project' do
|
344
|
-
project =
|
345
|
-
project_id =
|
346
|
-
@time_entry.
|
347
|
-
FreshBooks::Project.
|
344
|
+
project = mock('project')
|
345
|
+
project_id = mock('project ID')
|
346
|
+
@time_entry.stub!(:project_id).and_return(project_id)
|
347
|
+
FreshBooks::Project.should.receive(:get).with(project_id).and_return(project)
|
348
348
|
@time_entry.project.should == project
|
349
349
|
end
|
350
350
|
end
|
@@ -1,46 +1,53 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + '/spec_helper.rb')
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
rescue SystemExit
|
9
|
-
end
|
3
|
+
def run_command(*args)
|
4
|
+
Object.const_set(:ARGV, args)
|
5
|
+
begin
|
6
|
+
eval File.read(File.join(File.dirname(__FILE__), *%w[.. bin freshtrack]))
|
7
|
+
rescue SystemExit
|
10
8
|
end
|
11
|
-
|
12
|
-
|
9
|
+
end
|
10
|
+
|
11
|
+
def pending(*args, &block)
|
12
|
+
end
|
13
|
+
|
14
|
+
describe 'freshtrack command' do
|
15
|
+
before do
|
13
16
|
[:ARGV, :OPTIONS, :MANDATORY_OPTIONS].each do |const|
|
14
17
|
Object.send(:remove_const, const) if Object.const_defined?(const)
|
15
18
|
end
|
16
19
|
|
17
|
-
Freshtrack.
|
18
|
-
Freshtrack.
|
20
|
+
Freshtrack.stub!(:init)
|
21
|
+
Freshtrack.stub!(:track)
|
19
22
|
|
20
23
|
@project = 'myproj'
|
21
24
|
end
|
22
25
|
|
23
26
|
it 'should exist' do
|
24
|
-
lambda { run_command(@project) }.
|
27
|
+
lambda { run_command(@project) }.should.not.raise(Errno::ENOENT)
|
25
28
|
end
|
26
29
|
|
27
30
|
it 'should require a project' do
|
28
|
-
self.
|
31
|
+
self.should.receive(:puts) { |text| text.match(/usage.+project/i) }
|
29
32
|
run_command
|
30
33
|
end
|
31
34
|
|
32
|
-
it 'should init Freshtrack' do
|
33
|
-
Freshtrack.
|
35
|
+
it 'should init Freshtrack with the given project' do
|
36
|
+
Freshtrack.should.receive(:init) do |arg|
|
37
|
+
arg.should == @project
|
38
|
+
end
|
34
39
|
run_command(@project)
|
35
40
|
end
|
36
41
|
|
37
42
|
it 'should track time' do
|
38
|
-
Freshtrack.
|
43
|
+
Freshtrack.should.receive(:track)
|
39
44
|
run_command(@project)
|
40
45
|
end
|
41
46
|
|
42
47
|
it 'should track time for the given project' do
|
43
|
-
Freshtrack.
|
48
|
+
Freshtrack.should.receive(:track) do |project, _|
|
49
|
+
project.should == @project
|
50
|
+
end
|
44
51
|
run_command(@project)
|
45
52
|
end
|
46
53
|
|
@@ -48,116 +55,141 @@ describe 'freshtrack command' do
|
|
48
55
|
it "should pass on an 'after' time option given by --after" do
|
49
56
|
time_option = '2008-08-26 09:47'
|
50
57
|
time = Time.local(2008, 8, 26, 9, 47)
|
51
|
-
Freshtrack.
|
58
|
+
Freshtrack.should.receive(:track) do |project, opts|
|
59
|
+
project.should == @project
|
60
|
+
opts[:after].should == time
|
61
|
+
end
|
52
62
|
run_command(@project, '--after', time_option)
|
53
63
|
end
|
54
64
|
|
55
65
|
it "should pass on a 'before' time option given by --before" do
|
56
66
|
time_option = '2008-08-23 15:39'
|
57
67
|
time = Time.local(2008, 8, 23, 15, 39)
|
58
|
-
Freshtrack.
|
68
|
+
Freshtrack.should.receive(:track) do |project, opts|
|
69
|
+
project.should == @project
|
70
|
+
opts[:before].should == time
|
71
|
+
end
|
59
72
|
run_command(@project, '--before', time_option)
|
60
73
|
end
|
61
74
|
|
62
75
|
it 'should handle a time option given as a date' do
|
63
76
|
time_option = '2008-08-23'
|
64
77
|
time = Time.local(2008, 8, 23)
|
65
|
-
Freshtrack.
|
78
|
+
Freshtrack.should.receive(:track) do |project, opts|
|
79
|
+
project.should == @project
|
80
|
+
opts[:before].should == time
|
81
|
+
end
|
66
82
|
run_command(@project, '--before', time_option)
|
67
83
|
end
|
68
84
|
end
|
69
85
|
|
70
86
|
it 'should pass no options if none specified' do
|
71
|
-
Freshtrack.
|
87
|
+
Freshtrack.should.receive(:track).with(@project, {})
|
72
88
|
run_command(@project)
|
73
89
|
end
|
74
90
|
|
75
91
|
describe 'when --aging specified' do
|
76
|
-
before
|
92
|
+
before do
|
77
93
|
@aging_info = [
|
78
94
|
{ :id => 5, :number => '123', :age => 31, :client => 'blah', :status => 'viewed', :amount => 123.3, :owed => 5.67 },
|
79
95
|
{ :id => 53, :number => '234', :age => 43, :client => 'bang', :status => 'sent', :amount => 60.0, :owed => 60.0 },
|
80
96
|
{ :id => 20, :number => '938', :age => 3, :client => 'boom', :status => 'viewed', :amount => 100.0, :owed => 100.0 }
|
81
97
|
]
|
82
|
-
Freshtrack.
|
83
|
-
self.
|
98
|
+
Freshtrack.stub!(:invoice_aging).and_return(@aging_info)
|
99
|
+
self.stub!(:printf)
|
84
100
|
end
|
85
101
|
|
86
|
-
def aging_run
|
87
|
-
|
102
|
+
def aging_run(project=nil)
|
103
|
+
args = [project, '--aging'].compact
|
104
|
+
run_command(*args)
|
88
105
|
end
|
89
106
|
|
90
107
|
it 'should not require a project' do
|
91
|
-
self.
|
108
|
+
self.should.receive(:puts) { |text| text.match(/usage.+project/i) }.never
|
92
109
|
aging_run
|
93
110
|
end
|
94
111
|
|
95
|
-
it 'should init Freshtrack' do
|
96
|
-
Freshtrack.
|
112
|
+
it 'should init Freshtrack with a project if given' do
|
113
|
+
Freshtrack.should.receive(:init) do |arg|
|
114
|
+
arg.should == @project
|
115
|
+
end
|
116
|
+
aging_run(@project)
|
117
|
+
end
|
118
|
+
|
119
|
+
it 'should init Freshtrack for no project if none given' do
|
120
|
+
Freshtrack.should.receive(:init) do |arg|
|
121
|
+
arg.should.be.nil
|
122
|
+
end
|
97
123
|
aging_run
|
98
124
|
end
|
99
125
|
|
100
126
|
it 'should get the invoice aging information' do
|
101
|
-
Freshtrack.
|
127
|
+
Freshtrack.should.receive(:invoice_aging).and_return(@aging_info)
|
102
128
|
aging_run
|
103
129
|
end
|
104
130
|
|
105
131
|
it 'should print the number of each invoice' do
|
106
|
-
pending 'making this actually test what it purports to'
|
132
|
+
pending 'making this actually test what it purports to' do
|
107
133
|
@aging_info.each do |info|
|
108
|
-
self.
|
134
|
+
self.should.receive(:printf) { |*args| args.should.include(info[:number]) }
|
109
135
|
end
|
110
136
|
aging_run
|
137
|
+
end
|
111
138
|
end
|
112
139
|
|
113
140
|
it 'should print the client of each invoice' do
|
114
|
-
pending 'making this actually test what it purports to'
|
141
|
+
pending 'making this actually test what it purports to' do
|
115
142
|
@aging_info.each do |info|
|
116
|
-
self.
|
143
|
+
self.should.receive(:printf) { |*args| args.should.include(info[:client]) }
|
117
144
|
end
|
118
145
|
aging_run
|
146
|
+
end
|
119
147
|
end
|
120
148
|
|
121
149
|
it 'should print the age of each invoice' do
|
122
|
-
pending 'making this actually test what it purports to'
|
150
|
+
pending 'making this actually test what it purports to' do
|
123
151
|
@aging_info.each do |info|
|
124
|
-
self.
|
152
|
+
self.should.receive(:printf) { |*args| args.should.include(info[:age]) }
|
125
153
|
end
|
126
154
|
aging_run
|
155
|
+
end
|
127
156
|
end
|
128
157
|
|
129
158
|
it 'should print the status of each invoice' do
|
130
|
-
pending 'making this actually test what it purports to'
|
159
|
+
pending 'making this actually test what it purports to' do
|
131
160
|
@aging_info.each do |info|
|
132
|
-
self.
|
161
|
+
self.should.receive(:printf) { |*args| args.should.include(info[:status]) }
|
133
162
|
end
|
134
163
|
aging_run
|
164
|
+
end
|
135
165
|
end
|
136
166
|
|
137
167
|
it 'should print the amount of each invoice' do
|
138
|
-
pending 'making this actually test what it purports to'
|
168
|
+
pending 'making this actually test what it purports to' do
|
139
169
|
@aging_info.each do |info|
|
140
|
-
self.
|
170
|
+
self.should.receive(:printf) { |*args| args.should.include(info[:amount]) }
|
141
171
|
end
|
142
172
|
aging_run
|
173
|
+
end
|
143
174
|
end
|
144
175
|
|
145
176
|
it 'should print the owed of each invoice' do
|
146
|
-
pending 'making this actually test what it purports to'
|
177
|
+
pending 'making this actually test what it purports to' do
|
147
178
|
@aging_info.each do |info|
|
148
|
-
self.
|
179
|
+
self.should.receive(:printf) { |*args| args.should.include(info[:owed]) }
|
149
180
|
end
|
150
181
|
aging_run
|
182
|
+
end
|
151
183
|
end
|
152
184
|
|
153
185
|
it 'should not track time' do
|
154
|
-
Freshtrack.
|
186
|
+
Freshtrack.should.receive(:track).never
|
155
187
|
aging_run
|
156
188
|
end
|
157
189
|
|
158
190
|
it 'should not track time even when given a project' do
|
159
|
-
Freshtrack.
|
160
|
-
|
191
|
+
Freshtrack.should.receive(:track).never
|
192
|
+
aging_run(@project)
|
161
193
|
end
|
162
194
|
end
|
163
195
|
end
|