Permalink
Browse files

Don't freak out if sheet names are numeric

  • Loading branch information...
1 parent b44c654 commit f07967ddda17c8c023d6bf89f1b126df2d9dc913 @samg committed Jun 17, 2011
Showing with 37 additions and 2 deletions.
  1. +2 −2 lib/timetrap/cli.rb
  2. +6 −0 lib/timetrap/models.rb
  3. +29 −0 spec/timetrap_spec.rb
View
@@ -322,9 +322,9 @@ def now
puts "*#{Timer.current_sheet}: not running"
end
Timer.running_entries.each do |entry|
- current = entry[:sheet] == Timer.current_sheet
+ current = entry.sheet == Timer.current_sheet
out = current ? '*' : ' '
- out << "#{entry[:sheet]}: #{format_duration(entry.duration)}".gsub(/ /, ' ')
+ out << "#{entry.sheet}: #{format_duration(entry.duration)}".gsub(/ /, ' ')
out << " (#{entry.note})" if entry.note =~ /.+/
puts out
end
@@ -29,6 +29,12 @@ def end
round? ? rounded_end : self[:end]
end
+ # work around sequel's behavior of returning numeric values in string
+ # fields as integers
+ def sheet
+ self[:sheet].to_s
+ end
+
def duration
@duration ||= self.end_or_now.to_i - self.start.to_i
end
View
@@ -561,6 +561,22 @@ def output
invoke "kill --id #{entry.id} --yes"
end.should change(Timetrap::Entry, :count).by(-1)
end
+
+ describe "with a numeric sheet name" do
+ before do
+ Time.stub!(:now).and_return local_time("2008-10-05 18:00:00")
+ create_entry( :sheet => 1234, :start => local_time_cli('2008-10-03 12:00:00'),
+ :end => local_time_cli('2008-10-03 14:00:00'))
+ end
+
+ it "should list the sheet" do
+ STDERR.puts Timetrap::Entry.all
+ lambda do
+ invoke 'kill -y 1234'
+ end.should change(Timetrap::Entry, :count).by(-1)
+ STDERR.puts Timetrap::Entry.all
+ end
+ end
end
describe "list" do
@@ -571,6 +587,19 @@ def output
end
end
+ describe "with a numeric sheet name" do
+ before do
+ Time.stub!(:now).and_return local_time("2008-10-05 18:00:00")
+ create_entry( :sheet => '1234', :start => local_time_cli('2008-10-03 12:00:00'),
+ :end => local_time_cli('2008-10-03 14:00:00'))
+ end
+
+ it "should list the sheet" do
+ invoke 'list'
+ $stdout.string.should == " Timesheet Running Today Total Time\n 1234 0:00:00 0:00:00 2:00:00\n*default 0:00:00 0:00:00 0:00:00\n"
+ end
+ end
+
describe "with sheets defined" do
before do
Time.stub!(:now).and_return local_time("2008-10-05 18:00:00")

0 comments on commit f07967d

Please sign in to comment.