[Bps-public-commit] Net-Trac branch, master, updated. b061eca2f6525498c468aba2c539198b432745c1
? sunnavy
sunnavy at bestpractical.com
Mon Dec 13 04:44:26 EST 2010
The branch, master has been updated
via b061eca2f6525498c468aba2c539198b432745c1 (commit)
via f55d5aa8128ad005cbb938bf902a64e4157f243d (commit)
via 6af574273c6cd3b3b2c5f15da2d5a526bdf7a46c (commit)
from c3bd330ad29fcc0f6156aec0042dfeb06233e099 (commit)
Summary of changes:
lib/Net/Trac/Ticket.pm | 46 ++++++++++++++++++++++++++++---------
t/{02-create.t => 10-ticket-cf.t} | 34 ++++++++++++++++-----------
t/setup_trac.pl | 26 +++++++++++++++-----
3 files changed, 74 insertions(+), 32 deletions(-)
copy t/{02-create.t => 10-ticket-cf.t} (56%)
- Log -----------------------------------------------------------------
commit 6af574273c6cd3b3b2c5f15da2d5a526bdf7a46c
Author: sunnavy <sunnavy at bestpractical.com>
Date: Mon Dec 13 16:02:36 2010 +0800
initial cf fields support from Jacek Pasternak
diff --git a/lib/Net/Trac/Ticket.pm b/lib/Net/Trac/Ticket.pm
index 75263a9..d3286d3 100644
--- a/lib/Net/Trac/Ticket.pm
+++ b/lib/Net/Trac/Ticket.pm
@@ -79,17 +79,26 @@ sub valid_severities { shift; $_VALID_SEVERITIES = shift if (@_); return $_VALID
sub basic_statuses { qw( new accepted assigned reopened closed ) }
-sub valid_props { qw( id summary type status priority severity resolution owner reporter cc
- description keywords component milestone version time changetime ) }
+my @valid_props_arr = ();
-sub valid_create_props { grep { !/^(?:resolution|time|changetime)$/i } $_[0]->valid_props }
-sub valid_update_props { grep { !/^(?:time|changetime)$/i } $_[0]->valid_props }
+sub valid_props { return @valid_props_arr }
-for my $prop ( __PACKAGE__->valid_props ) {
- no strict 'refs';
- *{ "Net::Trac::Ticket::" . $prop } = sub { shift->state->{$prop} };
+sub add_custom_props {
+ my ($self, @props) = @_;
+ for my $prop (@props) {
+ next if grep { $_ eq $prop } @valid_props_arr;
+ push @valid_props_arr, $prop;
+ no strict 'refs';
+ *{ "Net::Trac::Ticket::" . $prop } = sub { shift->state->{$prop} };
+ }
}
+Net::Trac::Ticket->add_custom_props(qw( id summary type status priority severity resolution owner reporter cc
+ description keywords component milestone version time changetime ));
+
+sub valid_create_props { grep { !/^(?:resolution|time|changetime)$/i } $_[0]->valid_props }
+sub valid_update_props { grep { !/^(?:time|changetime)$/i } $_[0]->valid_props }
+
sub created { my $self= shift; $self->timestamp_to_datetime($self->time) }
sub last_modified { my $self= shift; $self->timestamp_to_datetime($self->changetime) }
@@ -204,6 +213,14 @@ sub _get_update_ticket_form {
return undef;
}
+sub _get_possible_values {
+ my $self = shift;
+ my ($form, $field) = @_;
+ my $res = $form->find_input($field);
+ return [] unless defined $res;
+ return [ $res->possible_values ];
+}
+
sub _fetch_new_ticket_metadata {
my $self = shift;
@@ -214,10 +231,13 @@ sub _fetch_new_ticket_metadata {
return undef;
}
- $self->valid_milestones([ $form->find_input("field_milestone")->possible_values ]);
- $self->valid_types ([ $form->find_input("field_type")->possible_values ]);
- $self->valid_components([ $form->find_input("field_component")->possible_values ]);
- $self->valid_priorities([ $form->find_input("field_priority")->possible_values ]);
+ $self->valid_milestones(
+ $self->_get_possible_values( $form, 'field_milestone' ) );
+ $self->valid_types( $self->_get_possible_values( $form, 'field_type' ) );
+ $self->valid_components(
+ $self->_get_possible_values( $form, 'field_component' ) );
+ $self->valid_priorities(
+ $self->_get_possible_values( $form, 'field_priority' ) );
my $severity = $form->find_input("field_severity");
$self->valid_severities([ $severity->possible_values ]) if $severity;
@@ -528,6 +548,10 @@ getting them.
Returns a list of the valid properties of a ticket.
+=head2 add_custom_props
+
+Adds custom properties to alid properties list
+
=head2 valid_create_props
Returns a list of the valid properties specifiable when creating a ticket.
commit f55d5aa8128ad005cbb938bf902a64e4157f243d
Author: sunnavy <sunnavy at bestpractical.com>
Date: Mon Dec 13 17:43:50 2010 +0800
hack Net::Trac::TestHarness to customize trac.ini
diff --git a/t/setup_trac.pl b/t/setup_trac.pl
index d770dd7..d7fbdba 100644
--- a/t/setup_trac.pl
+++ b/t/setup_trac.pl
@@ -17,14 +17,26 @@ sub new {
return $self;
}
-sub start_test_server {
-my $self = shift;
+sub init_test_server {
+ my $self = shift;
+ $self->port( int( 60000 + rand(2000) ) );
+ $self->dir( tempdir( CLEANUP => 1 ) );
+ $self->init;
+
+ if (@_) {
+ open my $fh, '>>',
+ File::Spec->catfile( $self->dir, 'trac', 'conf', 'trac.ini' )
+ or die $!;
+ print $fh @_;
+ }
+ return 1;
+}
-$self->port( int(60000 + rand(2000)));
-$self->dir(tempdir( CLEANUP => 1));
-$self->init;
-$self->daemonize;
-return $self->_did_server_start;
+sub start_test_server {
+ my $self = shift;
+ $self->init_test_server(@_);
+ $self->daemonize;
+ return $self->_did_server_start;
}
sub _did_server_start {
commit b061eca2f6525498c468aba2c539198b432745c1
Author: sunnavy <sunnavy at bestpractical.com>
Date: Mon Dec 13 17:44:07 2010 +0800
initial ticket cf test
diff --git a/t/10-ticket-cf.t b/t/10-ticket-cf.t
new file mode 100644
index 0000000..5b5fb21
--- /dev/null
+++ b/t/10-ticket-cf.t
@@ -0,0 +1,46 @@
+use warnings;
+use strict;
+
+use Test::More;
+use File::Spec;
+unless (`which trac-admin`) { plan skip_all => 'You need trac installed to run the tests'; }
+plan tests => 11;
+
+use_ok('Net::Trac::Connection');
+use_ok('Net::Trac::Ticket');
+Net::Trac::Ticket->add_custom_props( 'foo', 'bar' );
+require 't/setup_trac.pl';
+
+my $tr = Net::Trac::TestHarness->new();
+my $cf_conf = <<EOF;
+[ticket-custom]
+
+foo = text
+bar = text
+EOF
+
+ok($tr->start_test_server($cf_conf), "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);
+ok(
+ $ticket->create(
+ summary => 'test cf fields',
+ foo => 'foo_foo',
+ bar => 'bar_bar',
+ )
+);
+
+can_ok($ticket, 'load');
+ok($ticket->load(1));
+ok($ticket->history, "The ticket has some history");
+is($ticket->foo, 'foo_foo', "The ticket has cf foo");
+is($ticket->bar, 'bar_bar', "The ticket has cf bar");
+
-----------------------------------------------------------------------
More information about the Bps-public-commit
mailing list