[Bps-public-commit] net-lighthouse branch, master, updated. d5541ecf5d4303324dfe6ee9b352c165fc2d90fb

sunnavy at bestpractical.com sunnavy at bestpractical.com
Thu Aug 27 04:57:55 EDT 2009


The branch, master has been updated
       via  d5541ecf5d4303324dfe6ee9b352c165fc2d90fb (commit)
      from  c99ec2a2af3e90c08b3c9f59d5bc954c69212b68 (commit)

Summary of changes:
 lib/Net/Lighthouse/Project.pm |   27 +++++++++++++++++++++++----
 t/02-project.t                |   33 ++++++++++++++++++++++++---------
 2 files changed, 47 insertions(+), 13 deletions(-)

- Log -----------------------------------------------------------------
commit d5541ecf5d4303324dfe6ee9b352c165fc2d90fb
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Thu Aug 27 16:57:51 2009 +0800

    implement and test project->ticket_bins,messages,changesets and milestones

diff --git a/lib/Net/Lighthouse/Project.pm b/lib/Net/Lighthouse/Project.pm
index d3d9e33..4694f3f 100644
--- a/lib/Net/Lighthouse/Project.pm
+++ b/lib/Net/Lighthouse/Project.pm
@@ -3,6 +3,12 @@ use Any::Moose;
 use XML::Simple;
 use Net::Lighthouse::Util;
 use Params::Validate ':all';
+use Net::Lighthouse::Project::Ticket;
+use Net::Lighthouse::Project::TicketBin;
+use Net::Lighthouse::Project::Milestone;
+use Net::Lighthouse::Project::Message;
+use Net::Lighthouse::Project::Changeset;
+
 extends 'Net::Lighthouse';
 # read only attr
 has [
@@ -196,15 +202,28 @@ sub initial_state {
     }
 }
 
-sub tickets {
+sub tickets { return shift->_list( 'Ticket' ) }
+sub ticket_bins { return shift->_list( 'TicketBin' ) }
+sub messages { return shift->_list( 'Message' ) }
+sub milestones { return shift->_list( 'Milestone' ) }
+sub changesets { return shift->_list( 'Changeset' ) }
+
+sub _list {
     my $self = shift;
-    require Net::Lighthouse::Project::Ticket;
-    my $ticket = Net::Lighthouse::Project::Ticket->new(
+    validate_pos(
+        @_,
+        {
+            type  => SCALAR,
+            regex => qr/^(TicketBin|Ticket|Message|Changeset|Milestone)$/,
+        }
+    );
+    my $class  = 'Net::Lighthouse::Project::' . shift;
+    my $object = $class->new(
         project_id => $self->id,
         map { $_ => $self->$_ }
           grep { $self->$_ } qw/account email password token/
     );
-    return $ticket->list( @_ );
+    return $object->list(@_);
 }
 
 1;
diff --git a/t/02-project.t b/t/02-project.t
index fb73821..0962cb0 100644
--- a/t/02-project.t
+++ b/t/02-project.t
@@ -1,7 +1,7 @@
 use strict;
 use warnings;
 
-use Test::More tests => 58;
+use Test::More tests => 70;
 use Test::Mock::LWP;
 
 use_ok( 'Net::Lighthouse::Project' );
@@ -19,8 +19,8 @@ for my $attr( qw/archived created_at default_assigned_user_id
 }
 
 for my $method (
-    qw/create update delete tickets load load_from_xml list
-    initial_state/
+    qw/create update delete load load_from_xml list
+    initial_state tickets ticket_bins messages milestones changesets/
   )
 {
     can_ok( $project, $method );
@@ -127,13 +127,28 @@ is_deeply( $initial_state, $expected_initial_state, 'initial state' );
 $Mock_response->mock(
     content => sub {
         local $/;
-        open my $fh, '<', 't/data/tickets.xml' or die $!;
+        open my $fh, '<', 't/data/bins.xml' or die $!;
         <$fh>
     }
 );
 
-my @tickets = $p->tickets;
-is( scalar @tickets, 2, 'found tickets' );
-isa_ok( $tickets[0], 'Net::Lighthouse::Project::Ticket', 'found tickets' );
-is( $tickets[0]->number, 2, 'ticket number' );
-
+my @bins = $p->ticket_bins;
+is( scalar @bins, 3, 'found tickets' );
+isa_ok( $bins[0], 'Net::Lighthouse::Project::TicketBin' );
+is( $bins[0]->id, 48889, 'bin id' );
+
+for my $method (qw/milestones messages changesets tickets/) {
+    $Mock_response->mock(
+        content => sub {
+            local $/;
+            open my $fh, '<', "t/data/$method.xml" or die $!;
+            <$fh>;
+        }
+    );
+    my @list = $p->$method;
+    ok( scalar @list, 'found list' );
+
+    my $class = ucfirst $method;
+    $class =~ s/s$//;
+    isa_ok( $list[0], "Net::Lighthouse::Project::$class" );
+}

-----------------------------------------------------------------------



More information about the Bps-public-commit mailing list