Bug #932 (part 1)

- Fixed bug that caused only parent recurring tasks to have their attributes
  properly removed.
- When duplicating a parent recurring task, a new recurring parent task is
  created.  When a child recurring task is duplicated, a plain task is created.
- Added unit tests.
- Thanks to Jennifer Cormier.
This commit is contained in:
Paul Beckingham 2012-02-20 01:10:42 -05:00
parent 0a0e8f0d6b
commit 9f8165e3c6
4 changed files with 101 additions and 5 deletions

View file

@ -41,7 +41,8 @@
+ The duration 'm' is now interpreted as 'months', not 'minutes'.
+ Urgency now has an 'age' component.
+ Improved text wrapping of UTF8 text.
+ When duplicating a parent recurring task, a new recurring parent task is
created. When a child recurring task is duplicated, a plain task is created.
# Tracked Features, sorted by ID.
+ Added feature #52, which provides improved text-wrapping support for UTF-8

View file

@ -71,24 +71,34 @@ int CmdDuplicate::execute (std::string& output)
// Duplicate the specified task.
Task dup (*task);
dup.set ("uuid", uuid ()); // Needs a new UUID.
dup.setStatus (Task::pending); // Does not inherit status.
dup.remove ("start"); // Does not inherit start date.
dup.remove ("end"); // Does not inherit end date.
dup.remove ("entry"); // Does not inherit entry date.
// Recurring tasks are duplicated and downgraded to regular tasks.
// When duplicating a child task, downgrade it to a plain task.
if (dup.has ("parent"))
{
dup.remove ("parent");
dup.remove ("recur");
dup.remove ("until");
dup.remove ("mask");
dup.remove ("imask");
std::cout << format (STRING_CMD_DUPLICATE_NON_REC, task->id)
<< "\n";
}
// When duplicating a parent task, create a new parent task.
else if (dup.getStatus () == Task::recurring)
{
dup.remove ("mask");
std::cout << format (STRING_CMD_DUPLICATE_REC, task->id)
<< "\n";
}
dup.setStatus (Task::pending); // Does not inherit status.
// Must occur after Task::recurring check.
modify_task_annotate (dup, modifications);
if (permission (dup,

View file

@ -312,7 +312,8 @@
#define STRING_CMD_DELETE_N "Deleted {1} tasks."
#define STRING_CMD_DUPLICATE_USAGE "Duplicates the specified tasks"
#define STRING_CMD_DUPLICATE_NON_REC "Note: task {1} was a recurring task. The duplicate task is not."
#define STRING_CMD_DUPLICATE_REC "Note: task {1} was a parent recurring task. The duplicated task is too."
#define STRING_CMD_DUPLICATE_NON_REC "Note: task {1} was a recurring task. The duplicated task is not."
#define STRING_CMD_DUPLICATE_CONFIRM "Duplicate task {1} '{2}'?"
#define STRING_CMD_DUPLICATE_TASK "Duplicated task {1} '{2}'."
#define STRING_CMD_DUPLICATE_NO "Task not duplicated."

84
test/duplicate2.t Executable file
View file

@ -0,0 +1,84 @@
#! /usr/bin/perl
################################################################################
## taskwarrior - a command line task list manager.
##
## Copyright 2006-2012, Paul Beckingham, Federico Hernandez.
##
## Permission is hereby granted, free of charge, to any person obtaining a copy
## of this software and associated documentation files (the "Software"), to deal
## in the Software without restriction, including without limitation the rights
## to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
## copies of the Software, and to permit persons to whom the Software is
## furnished to do so, subject to the following conditions:
##
## The above copyright notice and this permission notice shall be included
## in all copies or substantial portions of the Software.
##
## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
## OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
## FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
## THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
## LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
## OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
## SOFTWARE.
##
## http://www.opensource.org/licenses/mit-license.php
##
################################################################################
use strict;
use warnings;
use Test::More tests => 14;
# Create the rc file.
if (open my $fh, '>', 'dup.rc')
{
print $fh "data.location=.\n";
close $fh;
ok (-r 'dup.rc', 'Created dup.rc');
}
# Add a recurring task. Duplicate both parent and child.
qx{../src/task rc:dup.rc add R due:tomorrow recur:weekly};
qx{../src/task rc:dup.rc list}; # To force handleRecurrence.
my $output = qx{../src/task rc:dup.rc 1 info};
like ($output, qr/Status\s+Recurring/, 'Found parent');
$output = qx{../src/task rc:dup.rc 2 info};
like ($output, qr/Status\s+Pending/, 'Found child');
$output = qx{../src/task rc:dup.rc 1 duplicate};
like ($output, qr/The duplicated task is too/, 'Duplicated parent is also a parent');
$output = qx{../src/task rc:dup.rc 2 duplicate};
like ($output, qr/The duplicated task is not/, 'Duplicated child is also a plain task');
qx{../src/task rc:dup.rc list}; # To force handleRecurrence.
$output = qx{../src/task rc:dup.rc 1 info};
like ($output, qr/Status\s+Recurring/, 'Found original parent task');
$output = qx{../src/task rc:dup.rc 2 info};
like ($output, qr/Status\s+Pending/, 'Found original child task - pending');
like ($output, qr/Parent/, 'Found original child task - with parent');
$output = qx{../src/task rc:dup.rc 3 info};
like ($output, qr/Status\s+Recurring/, 'Found duplicated parent task');
$output = qx{../src/task rc:dup.rc 4 info};
like ($output, qr/Status\s+Pending/, 'Found duplicated plain task');
unlike ($output, qr/Parent/, 'Found duplicated child task - no parent');
$output = qx{../src/task rc:dup.rc 5 info};
like ($output, qr/Status\s+Pending/, 'Found duplicated child task');
like ($output, qr/Parent/, 'Found duplicated child task - with parent');
# Cleanup.
unlink qw(pending.data completed.data undo.data backlog.data synch.key dup.rc);
ok (! -r 'pending.data' &&
! -r 'completed.data' &&
! -r 'undo.data' &&
! -r 'backlog.data' &&
! -r 'synch.key' &&
! -r 'dup.rc', 'Cleanup');
exit 0;