Skip to content

Commit

Permalink
Letting punch command listing accept options.
Browse files Browse the repository at this point in the history
  • Loading branch information
ymendel committed Oct 23, 2008
1 parent 2871694 commit fed7506
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 3 deletions.
2 changes: 1 addition & 1 deletion bin/punch
Expand Up @@ -99,7 +99,7 @@ commands = {
puts "Project required"
end
end,
'list' => lambda { |project| puts Punch.list(project).to_yaml },
'list' => lambda { |project| puts Punch.list(project, OPTIONS).to_yaml },
}

if command_code = commands[command]
Expand Down
34 changes: 32 additions & 2 deletions spec/punch_command_spec.rb
Expand Up @@ -531,12 +531,12 @@ def run_command(*args)
end

it 'should get the data for the requested project' do
Punch.expects(:list).with(@project)
Punch.expects(:list).with(@project, anything)
run_command('list', @project)
end

it 'should get the data for all projects if none given' do
Punch.expects(:list).with(nil)
Punch.expects(:list).with(nil, anything)
run_command('list')
end

Expand All @@ -547,6 +547,36 @@ def run_command(*args)
run_command('list')
end

describe 'when options specified' do
it "should pass on an 'after' time option given by --after" do
time_option = '2008-08-26 09:47'
time = Time.local(2008, 8, 26, 9, 47)
Punch.expects(:list).with(@project, has_entry(:after => time))
run_command('list', @project, '--after', time_option)
end

it "should pass on a 'before' time option given by --before" do
time_option = '2008-08-23 15:39'
time = Time.local(2008, 8, 23, 15, 39)
Punch.expects(:list).with(@project, has_entry(:before => time))
run_command('list', @project, '--before', time_option)
end

it 'should handle a time option given as a date' do
time_option = '2008-08-23'
time = Time.local(2008, 8, 23)
Punch.expects(:list).with(@project, has_entry(:before => time))
run_command('list', @project, '--before', time_option)
end

it 'should accept time options if no project given' do
time_option = '2008-08-26 09:47'
time = Time.local(2008, 8, 26, 9, 47)
Punch.expects(:list).with(nil, has_entry(:before => time))
run_command('list', '--before', time_option)
end
end

it 'should not write the data' do
@states['write'].become('test')
Punch.expects(:write).never.when(@states['write'].is('test'))
Expand Down

0 comments on commit fed7506

Please sign in to comment.