From 300ff2b3e1ccd190f361f47ef2eb640d7e141073 Mon Sep 17 00:00:00 2001 From: Zack Hobson Date: Sun, 26 Jan 2014 10:07:28 -0800 Subject: confirm timer cancel, closes #47 --- lib/hcl/commands.rb | 3 +++ test/command_test.rb | 8 ++++++++ 2 files changed, 11 insertions(+) diff --git a/lib/hcl/commands.rb b/lib/hcl/commands.rb index c753fbf..9bad615 100644 --- a/lib/hcl/commands.rb +++ b/lib/hcl/commands.rb @@ -45,6 +45,9 @@ module HCl def cancel entry = DayEntry.with_timer(http) || DayEntry.last(http) if entry + confirmed = /^y/.match(ask("#{entry}\nDelete this entry? (y/n): ").downcase) + return unless confirmed + if entry.cancel http "Deleted entry #{entry}." else diff --git a/test/command_test.rb b/test/command_test.rb index 2e2812f..e3f9806 100644 --- a/test/command_test.rb +++ b/test/command_test.rb @@ -100,6 +100,14 @@ class CommandTest < HCl::TestCase entry = stub HCl::DayEntry.expects(:with_timer).with(http).returns(entry) entry.expects(:cancel).with(http).returns(true) + expects(:ask).returns('y') + cancel + end + + def test_cancel_no + entry = stub + HCl::DayEntry.expects(:with_timer).with(http).returns(entry) + expects(:ask).returns('n') cancel end -- cgit v1.2.3