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.
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");

View file

@ -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 ();

View file

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

View file

@ -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.

View file

@ -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.

View file

@ -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;