one_inch_punch 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt CHANGED
@@ -1,3 +1,10 @@
1
+ == 0.0.2 2008-08-22
2
+
3
+ * 3 tiny enhancements:
4
+ * Punching in will now create a project if necessary
5
+ * Can now delete a project
6
+ * Can now list project data
7
+
1
8
  == 0.0.1 2008-08-18
2
9
 
3
10
  * 1 major enhancement:
data/README.txt CHANGED
@@ -12,11 +12,12 @@ One-inch punch: Smaller, more effective
12
12
  == FEATURES/PROBLEMS:
13
13
 
14
14
  * Can load and write .punch.yml data compatibly with Ara's punch gem
15
- * Can punch in and out of projects
15
+ * Can punch in and out of projects (including creating a project by punching in)
16
16
  * Can query project status
17
+ * Can delete a project
18
+ * Can list project data
17
19
 
18
20
  * Cannot give a total time (yet)
19
- * Cannot list time entries (yet)
20
21
  * Cannot be used command-line (yet)
21
22
  * More, since this is unfinished
22
23
 
data/lib/punch/version.rb CHANGED
@@ -2,7 +2,7 @@ module Punch
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 0
4
4
  MINOR = 0
5
- TINY = 1
5
+ TINY = 2
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
data/lib/punch.rb CHANGED
@@ -53,6 +53,7 @@ module Punch
53
53
 
54
54
  def in(project)
55
55
  return false if in?(project)
56
+ data[project] ||= []
56
57
  data[project].push({'in' => Time.now})
57
58
  write
58
59
  true
@@ -64,5 +65,15 @@ module Punch
64
65
  write
65
66
  true
66
67
  end
68
+
69
+ def delete(project)
70
+ return nil unless data.delete(project)
71
+ write
72
+ true
73
+ end
74
+
75
+ def list(project)
76
+ data[project]
77
+ end
67
78
  end
68
79
  end
data/spec/punch_spec.rb CHANGED
@@ -337,6 +337,42 @@ describe Punch do
337
337
  Punch.in(@project).should == true
338
338
  end
339
339
  end
340
+
341
+ describe 'when the project does not yet exist' do
342
+ before :each do
343
+ @project = 'non-existent project'
344
+ end
345
+
346
+ it 'should create the project' do
347
+ Punch.in(@project)
348
+ Punch.data.should include(@project)
349
+ end
350
+
351
+ it 'should add a time entry to the project data' do
352
+ Punch.in(@project)
353
+ Punch.data[@project].length.should == 1
354
+ end
355
+
356
+ it 'should use now for the punch-in time' do
357
+ Punch.in(@project)
358
+ Punch.data[@project].last['in'].should == @now
359
+ end
360
+
361
+ it 'should use now for the punch-in time' do
362
+ Punch.in(@project)
363
+ Punch.data[@project].last['in'].should == @now
364
+ end
365
+
366
+ it 'should write the data' do
367
+ @test.become('test')
368
+ Punch.expects(:write).when(@test.is('test'))
369
+ Punch.in(@project)
370
+ end
371
+
372
+ it 'should return true' do
373
+ Punch.in(@project).should == true
374
+ end
375
+ end
340
376
  end
341
377
 
342
378
  it 'should punch a project out' do
@@ -421,4 +457,110 @@ describe Punch do
421
457
  end
422
458
  end
423
459
  end
460
+
461
+ it 'should delete a project' do
462
+ Punch.should respond_to(:delete)
463
+ end
464
+
465
+ describe 'deleting a project' do
466
+ before :each do
467
+ @now = Time.now
468
+ @project = 'test project'
469
+ @data = { @project => [ {'in' => @now - 50, 'out' => @now - 25} ] }
470
+
471
+ Punch.instance_eval do
472
+ class << self
473
+ public :data, :data=
474
+ end
475
+ end
476
+ Punch.data = @data
477
+
478
+ @test = states('test').starts_as('setup')
479
+ Punch.stubs(:write).when(@test.is('setup'))
480
+ end
481
+
482
+ it 'should accept a project name' do
483
+ lambda { Punch.delete('proj') }.should_not raise_error(ArgumentError)
484
+ end
485
+
486
+ it 'should require a project name' do
487
+ lambda { Punch.delete }.should raise_error(ArgumentError)
488
+ end
489
+
490
+ describe 'when the project exists' do
491
+ it 'should remove the project data' do
492
+ Punch.delete(@project)
493
+ Punch.data.should_not include(@project)
494
+ end
495
+
496
+ it 'should write the data' do
497
+ @test.become('test')
498
+ Punch.expects(:write).when(@test.is('test'))
499
+ Punch.delete(@project)
500
+ end
501
+
502
+ it 'should return true' do
503
+ Punch.delete(@project).should == true
504
+ end
505
+ end
506
+
507
+ describe 'when the project does not exist' do
508
+ before :each do
509
+ @project = 'non-existent project'
510
+ end
511
+
512
+ it 'should not write the data' do
513
+ @test.become('test')
514
+ Punch.expects(:write).never.when(@test.is('test'))
515
+ Punch.delete(@project)
516
+ end
517
+
518
+ it 'should return nil' do
519
+ Punch.delete(@project).should be_nil
520
+ end
521
+ end
522
+ end
523
+
524
+ it 'should list project data' do
525
+ Punch.should respond_to(:list)
526
+ end
527
+
528
+ describe 'listing project data' do
529
+ before :each do
530
+ @now = Time.now
531
+ @project = 'test project'
532
+ @data = { @project => [ {'in' => @now - 50, 'out' => @now - 25} ] }
533
+
534
+ Punch.instance_eval do
535
+ class << self
536
+ public :data, :data=
537
+ end
538
+ end
539
+ Punch.data = @data
540
+ end
541
+
542
+ it 'should accept a project name' do
543
+ lambda { Punch.list('proj') }.should_not raise_error(ArgumentError)
544
+ end
545
+
546
+ it 'should require a project name' do
547
+ lambda { Punch.list }.should raise_error(ArgumentError)
548
+ end
549
+
550
+ describe 'when the project exists' do
551
+ it 'should return the project data' do
552
+ Punch.list(@project).should == Punch.data[@project]
553
+ end
554
+ end
555
+
556
+ describe 'when the project does not exist' do
557
+ before :each do
558
+ @project = 'non-existent project'
559
+ end
560
+
561
+ it 'should return nil' do
562
+ Punch.list(@project).should be_nil
563
+ end
564
+ end
565
+ end
424
566
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: one_inch_punch
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yossef Mendelssohn
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-08-18 00:00:00 -05:00
12
+ date: 2008-08-22 00:00:00 -05:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency