Skip to content

Commit

Permalink
#21 Use open interval when no id given
Browse files Browse the repository at this point in the history
- Add test
- Special handling if database empty
  • Loading branch information
lauft committed May 13, 2018
1 parent 4afd14e commit c595132
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/commands/CmdTag.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,17 @@ int CmdTag (

if (ids.empty ())
{
throw std::string ("At least one ID must be specified. See 'timew help tag'.");
if (tracked.empty ())
{
throw std::string ("There is no active time tracking.");
}

if (!tracked.back ().range.is_open ())
{
throw std::string ("At least one ID must be specified. See 'timew help tag'.");
}

ids.insert (1);
}

// Apply tags to ids.
Expand Down
11 changes: 11 additions & 0 deletions test/tag.t
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,17 @@ class TestTag(TestCase):
code, out, err = self.t("tag @1 foo")
self.assertIn('Added foo to @1', out)

def test_should_use_default_on_missing_id_and_active_time_tracking(self):
"""Use open interval on missing id and active time tracking"""
self.t("track yesterday for 1hour foo")
self.t("start 30min ago bar")
code, out, err = self.t("tag baz")
self.assertIn("Added baz to @1", out)

def test_should_fail_on_missing_id_and_empty_database(self):
"""Missing id on empty database is an error"""
code, out, err = self.t.runError("tag foo")
self.assertIn("There is no active time tracking.", err)

def test_should_fail_on_missing_id_and_inactive_time_tracking(self):
"""Missing id on inactive time tracking is an error"""
Expand Down

0 comments on commit c595132

Please sign in to comment.