Skip to content

Commit

Permalink
Allowing summary for punched-in project.
Browse files Browse the repository at this point in the history
  • Loading branch information
ymendel committed Aug 17, 2009
1 parent d001957 commit ef4c7bd
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/punch.rb
Expand Up @@ -163,12 +163,14 @@ def summary(project, options = {})
msg = 'unspecified' if msg == 'punch in'
{ :msg => msg, :time => Time.parse(time) }
end

log << { :msg => 'punch out', :time => Time.now } unless log.last[:msg] == 'punch out'

log.each_cons(2) do |a, b|
summary[a[:msg]] += (b[:time] - a[:time]).to_i
end
else
summary['unspecified'] += (time_data['out'] - time_data['in']).to_i
summary['unspecified'] += ((time_data['out'] || Time.now) - time_data['in']).to_i
end
end

Expand Down
28 changes: 28 additions & 0 deletions spec/punch_spec.rb
Expand Up @@ -1600,6 +1600,34 @@ class << self
Punch.summary(@project, :format => true).should == { 'unspecified' => '03:20', @message => '01:40', @other_message => '05:00' }
end
end

describe 'when the project is currently punched in' do
before do
@data = { @project => [ {'in' => @now - 500} ] }
@time_data = @data[@project].last
@time_data['log'] = ["punch in @ #{@time_data['in'].strftime(@time_format)}", "#{@message} @ #{(@time_data['in'] + 200).strftime(@time_format)}"]
Punch.data = @data
end

it 'should summarize time up to now' do
Punch.summary(@project).should == { 'unspecified' => 200, @message => 300 }
end

it 'should handle time data with no specific log messages' do
@time_data['log'].pop
Punch.summary(@project).should == { 'unspecified' => 500 }
end

it 'should handle time data with no log messages' do
@time_data['log'] = []
Punch.summary(@project).should == { 'unspecified' => 500 }
end

it 'should handle time data with no log' do
@time_data.delete('log')
Punch.summary(@project).should == { 'unspecified' => 500 }
end
end
end

describe 'when the project does not exist' do
Expand Down

0 comments on commit ef4c7bd

Please sign in to comment.