From b09351c517befe4fc9ca2ce8009bcb8b372b934c Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Wed, 31 Aug 2011 01:34:59 -0400 Subject: [PATCH] Task Validation - Fixed validation bug whereby recurring child tasks inherited the parent status ("recurring") instead of the expected "pending". - Modified 'add' command to code duplicated in Task::validate. - Cleaned up associated bug.period.t unit test. --- src/TDB2.cpp | 10 ++++++++-- src/TDB2.h | 4 ++-- src/Task.cpp | 6 ++++-- src/commands/CmdAdd.cpp | 9 +-------- src/recur.cpp | 1 + test/bug.period.t | 26 ++++++++------------------ 6 files changed, 24 insertions(+), 32 deletions(-) diff --git a/src/TDB2.cpp b/src/TDB2.cpp index 6a3f4570f..f421c5202 100644 --- a/src/TDB2.cpp +++ b/src/TDB2.cpp @@ -483,10 +483,13 @@ void TDB2::set_location (const std::string& location) //////////////////////////////////////////////////////////////////////////////// // Add the new task to the appropriate file. -void TDB2::add (const Task& task) +void TDB2::add (Task& task) { // std::cout << "# TDB2::add\n"; + // Ensure the task is consistent, and provide defaults if necessary. + task.validate (); + // If the tasks are loaded, then verify that this uuid is not already in // the file. if (!verifyUniqueUUID (task.get ("uuid"))) @@ -513,10 +516,13 @@ void TDB2::add (const Task& task) } //////////////////////////////////////////////////////////////////////////////// -void TDB2::modify (const Task& task) +void TDB2::modify (Task& task) { // std::cout << "# TDB2::modify\n"; + // Ensure the task is consistent, and provide defaults if necessary. + task.validate (); + // Update task in either completed or deleted. // TODO Find task, overwrite it. std::string status = task.get ("status"); diff --git a/src/TDB2.h b/src/TDB2.h index 8cf3cb25e..c849664bd 100644 --- a/src/TDB2.h +++ b/src/TDB2.h @@ -93,8 +93,8 @@ public: ~TDB2 (); void set_location (const std::string&); - void add (const Task&); - void modify (const Task&); + void add (Task&); + void modify (Task&); void commit (); void synch (); void revert (); diff --git a/src/Task.cpp b/src/Task.cpp index 5a285162f..0be2adabb 100644 --- a/src/Task.cpp +++ b/src/Task.cpp @@ -996,8 +996,10 @@ void Task::validate () if (has ("due") && has ("recur")) { - setStatus (Task::recurring); - set ("mask", ""); + if (has ("parent")) + setStatus (Task::pending); + else + setStatus (Task::recurring); } // Tasks with a wait: date get a special status. diff --git a/src/commands/CmdAdd.cpp b/src/commands/CmdAdd.cpp index fb05145aa..a98b008d0 100644 --- a/src/commands/CmdAdd.cpp +++ b/src/commands/CmdAdd.cpp @@ -51,16 +51,9 @@ int CmdAdd::execute (std::string& output) { int rc = 0; - // Every task needs a UUID. - Task task; - task.set ("uuid", uuid ()); - // Apply the command line modifications to the new task. + Task task; modify_task_description_replace (task, context.a3.extract_modifications ()); - apply_defaults (task); - - // Only valid tasks can be added. - task.validate (); context.tdb2.add (task); // TODO This should be a call in to feedback.cpp. diff --git a/src/recur.cpp b/src/recur.cpp index 2fc02f9ce..41e8d77d9 100644 --- a/src/recur.cpp +++ b/src/recur.cpp @@ -93,6 +93,7 @@ void handleRecurrence () changed = true; Task rec (*t); // Clone the parent. + rec.setStatus (Task::pending); // Change the status. rec.set ("uuid", uuid ()); // New UUID. rec.set ("parent", t->get ("uuid")); // Remember mom. rec.setEntry (); // New entry date. diff --git a/test/bug.period.t b/test/bug.period.t index caae74026..d95870556 100755 --- a/test/bug.period.t +++ b/test/bug.period.t @@ -28,7 +28,7 @@ use strict; use warnings; -use Test::More tests => 45; +use Test::More tests => 40; # Create the rc file. if (open my $fh, '>', 'period.rc') @@ -154,23 +154,13 @@ like ($output, qr/\b2q\b/, 'verify 2q'); like ($output, qr/\b2y\b/, 'verify 2y'); # Cleanup. -unlink 'pending.data'; -ok (!-r 'pending.data', 'Removed pending.data'); - -unlink 'completed.data'; -ok (!-r 'completed.data', 'Removed completed.data'); - -unlink 'undo.data'; -ok (!-r 'undo.data', 'Removed undo.data'); - -unlink 'backlog.data'; -ok (!-r 'backlog.data', 'Removed backlog.data'); - -unlink 'synch.key'; -ok (!-r 'synch.key', 'Removed synch.key'); - -unlink 'period.rc'; -ok (!-r 'period.rc', 'Removed period.rc'); +unlink qw(pending.data completed.data undo.data backlog.data synch.key period.rc); +ok (! -r 'pending.data' && + ! -r 'completed.data' && + ! -r 'undo.data' && + ! -r 'backlog.data' && + ! -r 'synch_key.data' && + ! -r 'period.rc', 'Cleanup'); exit 0;