[Bps-public-commit] r17420 - in Net-Trac/trunk: . t

trs at bestpractical.com trs at bestpractical.com
Tue Dec 30 00:34:27 EST 2008


Author: trs
Date: Tue Dec 30 00:34:26 2008
New Revision: 17420

Added:
   Net-Trac/trunk/t/comments.t
Modified:
   Net-Trac/trunk/   (props changed)
   Net-Trac/trunk/lib/Net/Trac/Ticket.pm

Log:
 r43271 at zot:  tom | 2008-12-29 23:10:52 -0500
 Add the ability to comment on tickets


Modified: Net-Trac/trunk/lib/Net/Trac/Ticket.pm
==============================================================================
--- Net-Trac/trunk/lib/Net/Trac/Ticket.pm	(original)
+++ Net-Trac/trunk/lib/Net/Trac/Ticket.pm	Tue Dec 30 00:34:26 2008
@@ -126,12 +126,13 @@
     }
 }
 
-
 sub update {
     my $self = shift;
     my %args = validate(
         @_,
-        {   summary     => 0,
+        {
+            comment     => 0,
+            summary     => 0,
             reporter    => 0,
             description => 0,
             owner       => 0,
@@ -143,13 +144,12 @@
             keywords    => 0,
             cc          => 0,
             status      => 0
-
         }
     );
 
     my ($form,$form_num)= $self->_get_update_ticket_form();
 
-    my %form = map { 'field_' . $_ => $args{$_} } keys %args;
+    my %form = map { ($_ eq 'comment' ? $_ : 'field_' . $_) => $args{$_} } keys %args;
 
     $self->connection->mech->submit_form(
         form_number => $form_num,
@@ -158,7 +158,12 @@
 
     my $reply = $self->connection->mech->response;
     $self->load($self->id);
+}
 
+sub comment {
+    my $self = shift;
+    my ($comment) = validate_pos( @_, { type => SCALAR });
+    $self->update( comment => $comment );
 }
 
 sub history {

Added: Net-Trac/trunk/t/comments.t
==============================================================================
--- (empty file)
+++ Net-Trac/trunk/t/comments.t	Tue Dec 30 00:34:26 2008
@@ -0,0 +1,46 @@
+use warnings; 
+use strict;
+
+use Test::More qw/no_plan/;
+use_ok('Net::Trac::Connection');
+use_ok('Net::Trac::Ticket');
+require 't/setup_trac.pl';
+
+
+my $tr = Net::Trac::TestHarness->new();
+ok($tr->start_test_server(), "The server started!");
+
+my $trac = Net::Trac::Connection->new(
+    url      => $tr->url,
+    user     => 'hiro',
+    password => 'yatta'
+);
+
+isa_ok( $trac, "Net::Trac::Connection" );
+is($trac->url, $tr->url);
+my $ticket = Net::Trac::Ticket->new( connection => $trac);
+isa_ok($ticket, 'Net::Trac::Ticket');
+
+can_ok($ticket => '_fetch_new_ticket_metadata');
+ok($ticket->_fetch_new_ticket_metadata);
+can_ok($ticket => 'create');
+ok($ticket->create(summary => 'Summary #1'));
+
+can_ok($ticket, 'load');
+ok($ticket->load(1));
+like($ticket->state->{'summary'}, qr/Summary #1/);
+like($ticket->summary, qr/Summary #1/, "The summary looks correct");
+
+can_ok($ticket => 'update');
+ok($ticket->update( comment => 'I like moose.' ), "Creating comment about moose.");
+is(@{$ticket->history->entries}, 1, "Got one history entry.");
+like($ticket->history->entries->[0]->content, qr/I like moose./, "The comment looks correct.");
+
+can_ok($ticket => 'comment');
+ok($ticket->comment( 'I like fish.' ), "Creating comment about fish.");
+
+is(@{$ticket->history->entries}, 2, "Got two history entries.");
+like($ticket->history->entries->[1]->content, qr/fish/, "The comment looks correct.");
+like($ticket->history->entries->[0]->content, qr/moose/, "The previous comment looks correct.");
+
+



More information about the Bps-public-commit mailing list