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.
This commit is contained in:
Paul Beckingham 2011-08-31 01:34:59 -04:00
parent 8e34a02811
commit b09351c517
6 changed files with 24 additions and 32 deletions

View file

@ -483,10 +483,13 @@ void TDB2::set_location (const std::string& location)
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// Add the new task to the appropriate file. // Add the new task to the appropriate file.
void TDB2::add (const Task& task) void TDB2::add (Task& task)
{ {
// std::cout << "# TDB2::add\n"; // 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 // If the tasks are loaded, then verify that this uuid is not already in
// the file. // the file.
if (!verifyUniqueUUID (task.get ("uuid"))) 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"; // std::cout << "# TDB2::modify\n";
// Ensure the task is consistent, and provide defaults if necessary.
task.validate ();
// Update task in either completed or deleted. // Update task in either completed or deleted.
// TODO Find task, overwrite it. // TODO Find task, overwrite it.
std::string status = task.get ("status"); std::string status = task.get ("status");

View file

@ -93,8 +93,8 @@ public:
~TDB2 (); ~TDB2 ();
void set_location (const std::string&); void set_location (const std::string&);
void add (const Task&); void add (Task&);
void modify (const Task&); void modify (Task&);
void commit (); void commit ();
void synch (); void synch ();
void revert (); void revert ();

View file

@ -996,8 +996,10 @@ void Task::validate ()
if (has ("due") && if (has ("due") &&
has ("recur")) has ("recur"))
{ {
if (has ("parent"))
setStatus (Task::pending);
else
setStatus (Task::recurring); setStatus (Task::recurring);
set ("mask", "");
} }
// Tasks with a wait: date get a special status. // Tasks with a wait: date get a special status.

View file

@ -51,16 +51,9 @@ int CmdAdd::execute (std::string& output)
{ {
int rc = 0; int rc = 0;
// Every task needs a UUID.
Task task;
task.set ("uuid", uuid ());
// Apply the command line modifications to the new task. // Apply the command line modifications to the new task.
Task task;
modify_task_description_replace (task, context.a3.extract_modifications ()); modify_task_description_replace (task, context.a3.extract_modifications ());
apply_defaults (task);
// Only valid tasks can be added.
task.validate ();
context.tdb2.add (task); context.tdb2.add (task);
// TODO This should be a call in to feedback.cpp. // TODO This should be a call in to feedback.cpp.

View file

@ -93,6 +93,7 @@ void handleRecurrence ()
changed = true; changed = true;
Task rec (*t); // Clone the parent. Task rec (*t); // Clone the parent.
rec.setStatus (Task::pending); // Change the status.
rec.set ("uuid", uuid ()); // New UUID. rec.set ("uuid", uuid ()); // New UUID.
rec.set ("parent", t->get ("uuid")); // Remember mom. rec.set ("parent", t->get ("uuid")); // Remember mom.
rec.setEntry (); // New entry date. rec.setEntry (); // New entry date.

View file

@ -28,7 +28,7 @@
use strict; use strict;
use warnings; use warnings;
use Test::More tests => 45; use Test::More tests => 40;
# Create the rc file. # Create the rc file.
if (open my $fh, '>', 'period.rc') if (open my $fh, '>', 'period.rc')
@ -154,23 +154,13 @@ like ($output, qr/\b2q\b/, 'verify 2q');
like ($output, qr/\b2y\b/, 'verify 2y'); like ($output, qr/\b2y\b/, 'verify 2y');
# Cleanup. # Cleanup.
unlink 'pending.data'; unlink qw(pending.data completed.data undo.data backlog.data synch.key period.rc);
ok (!-r 'pending.data', 'Removed pending.data'); ok (! -r 'pending.data' &&
! -r 'completed.data' &&
unlink 'completed.data'; ! -r 'undo.data' &&
ok (!-r 'completed.data', 'Removed completed.data'); ! -r 'backlog.data' &&
! -r 'synch_key.data' &&
unlink 'undo.data'; ! -r 'period.rc', 'Cleanup');
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');
exit 0; exit 0;