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

sunnavy at bestpractical.com sunnavy at bestpractical.com
Mon Sep 7 05:21:02 EDT 2009


The branch, master has been updated
       via  b3a750c795da28479b0a1bf6b2b9b8283f3e7007 (commit)
      from  a1f78e8ab7f46ecdb743f21903d72f0ea4f94fa7 (commit)

Summary of changes:
 lib/Net/Lighthouse.pm |   30 ++++++++++++++++++++++++++++++
 t/20-lighthouse.t     |   30 ++++++++++++++++++++++++++++++
 2 files changed, 60 insertions(+), 0 deletions(-)
 create mode 100644 t/20-lighthouse.t

- Log -----------------------------------------------------------------
commit b3a750c795da28479b0a1bf6b2b9b8283f3e7007
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Mon Sep 7 17:20:57 2009 +0800

    add projects,project,user and token method for Lighthouse.pm, also tests for that

diff --git a/lib/Net/Lighthouse.pm b/lib/Net/Lighthouse.pm
index 8f4b838..8c411f0 100644
--- a/lib/Net/Lighthouse.pm
+++ b/lib/Net/Lighthouse.pm
@@ -10,6 +10,36 @@ use base 'Net::Lighthouse::Base';
 
 our $VERSION = '0.01';
 
+sub project { return shift->_new( 'Project' ) }
+sub user { return shift->_new( 'User' ) }
+sub token { return shift->_new( 'Token' ) }
+
+sub _new {
+    my $self = shift;
+    validate_pos(
+        @_,
+        {
+            type  => SCALAR,
+            regex => qr/^(Project|Token|User)$/,
+        }
+    );
+    my $class  = 'Net::Lighthouse::' . shift;
+    my $object = $class->new(
+        map { $_ => $self->$_ }
+          grep { $self->$_ } qw/account auth/
+    );
+    return $object;
+}
+
+sub projects {
+    my $self   = shift;
+    my $object = Net::Lighthouse::Project->new(
+        map { $_ => $self->$_ }
+          grep { $self->$_ } qw/account auth/
+    );
+    return $object->list(@_);
+}
+
 1;
 
 __END__
diff --git a/t/20-lighthouse.t b/t/20-lighthouse.t
new file mode 100644
index 0000000..d7dd04f
--- /dev/null
+++ b/t/20-lighthouse.t
@@ -0,0 +1,30 @@
+use strict;
+use warnings;
+
+use Test::More tests => 13;
+use Test::Mock::LWP;
+
+use_ok('Net::Lighthouse');
+can_ok( 'Net::Lighthouse', 'new' );
+my $lh = Net::Lighthouse->new( account => 'sunnavy' );
+isa_ok( $lh, 'Net::Lighthouse::Base' );
+for my $method (qw/project token user/) {
+    can_ok( $lh, $method );
+    isa_ok( $lh->$method, 'Net::Lighthouse::' . ucfirst $method );
+}
+
+can_ok( $lh, 'projects' );
+$Mock_ua->mock( get            => sub { $Mock_response } );
+$Mock_ua->mock( default_header => sub { } );                  # to erase warning
+$Mock_response->mock(
+    content => sub {
+        local $/;
+        open my $fh, '<', 't/data/projects.xml' or die $!;
+        <$fh>;
+    }
+);
+
+my @projects = $lh->projects;
+is( scalar @projects, 2, 'found projects' );
+isa_ok( $projects[0], 'Net::Lighthouse::Project' );
+is( $projects[0]->id, 35918, 'project id' );

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



More information about the Bps-public-commit mailing list