[Bps-public-commit] r12109 - in sd/trunk: . bin t
jesse at bestpractical.com
jesse at bestpractical.com
Tue May 6 14:33:41 EDT 2008
Author: jesse
Date: Tue May 6 14:33:41 2008
New Revision: 12109
Added:
sd/trunk/t/sd-attachments.t
Modified:
sd/trunk/ (props changed)
sd/trunk/bin/sd
sd/trunk/lib/App/SD/Model/Attachment.pm
Log:
r30547 at 120: jesse | 2008-05-06 14:33:19 -0400
* 'Attachment' support. next up...attachments with content
Modified: sd/trunk/bin/sd
==============================================================================
--- sd/trunk/bin/sd (original)
+++ sd/trunk/bin/sd Tue May 6 14:33:41 2008
@@ -28,6 +28,18 @@
}
+package App::SD::CLI::Command::Ticket::Attachment::Create;
+use base qw/App::SD::CLI::Command::Ticket::Attachment Prophet::CLI::Command::Create/;
+
+# override args to feed in that ticket's uuid as an argument to the comment
+sub args {
+ my $self = shift;
+ return { %{$self->SUPER::args}, ticket => $self->uuid};
+}
+
+
+
+
package App::SD::CLI::Command::Help;
use base qw/App::SD::CLI::Command/;
@@ -63,6 +75,8 @@
my $self = shift;
print "\n=head1 METADATA\n\n";
$self->App::SD::CLI::Command::Ticket::Show::run();
+ print "\n=head1 ATTACHMENTS\n\n";
+ $self->App::SD::CLI::Command::Ticket::Attachments::run();
print "\n=head1 COMMENTS\n\n";
$self->App::SD::CLI::Command::Ticket::Comments::run();
}
@@ -90,6 +104,25 @@
}
+package App::SD::CLI::Command::Ticket::Attachments;
+use base qw/App::SD::CLI::Command::Ticket/;
+
+sub run {
+ my $self = shift;
+ my $record = $self->_get_record();
+ $record->load( uuid => $self->cli->uuid );
+ unless (@{$record->attachments}) {
+ print "No attachments found\n";
+ }
+
+ for (@{$record->attachments}) {
+ print "attachment id: ".$_->uuid."\n";
+ print "name: ".$_->prop('name')."\n";
+ print "content_type: ".$_->prop('content_type')."\n";
+ }
+
+}
+
package App::SD::CLI::Command::Merge;
use base qw/App::SD::CLI::Command Prophet::CLI::Command::Merge/;
Modified: sd/trunk/lib/App/SD/Model/Attachment.pm
==============================================================================
--- sd/trunk/lib/App/SD/Model/Attachment.pm (original)
+++ sd/trunk/lib/App/SD/Model/Attachment.pm Tue May 6 14:33:41 2008
@@ -3,13 +3,26 @@
package App::SD::Model::Attachment;
use base qw/App::SD::Record/;
+use Params::Validate qw/validate/;
use constant collection_class => 'App::SD::Collection::Attachment';
use constant record_type => 'attachment';
use constant summary_format => '%u %s';
-use constant summary_props => qw(filename);
+use constant summary_props => qw(name content_type);
__PACKAGE__->register_reference( ticket => 'App::SD::Model::Ticket');
+sub create {
+ my $self = shift;
+ my %args = validate( @_, {props => 1});
+
+ $args{'props'}->{'content_type'} ||= 'text/plain'; # XXX TODO use real mime typing;
+
+
+ $self->SUPER::create(%args);
+}
+
+
+
1;
Added: sd/trunk/t/sd-attachments.t
==============================================================================
--- (empty file)
+++ sd/trunk/t/sd-attachments.t Tue May 6 14:33:41 2008
@@ -0,0 +1,74 @@
+#!/usr/bin/perl -w
+
+use strict;
+
+use Prophet::Test tests => 9;
+
+no warnings 'once';
+
+BEGIN {
+ require File::Temp;
+ $ENV{'PROPHET_REPO'} = $ENV{'SD_REPO'} = File::Temp::tempdir( CLEANUP => 0 ) . '/_svb';
+ warn "export SD_REPO=".$ENV{'PROPHET_REPO'} ."\n";
+}
+# create from sd and push
+my $yatta_uuid;
+run_output_matches( 'sd', [ 'ticket',
+ 'create', '--summary', 'YATTA', '--status', 'new' ],
+ [qr/Created ticket (.*)(?{ $yatta_uuid = $1 })/]
+);
+
+run_output_matches( 'sd', [ 'ticket',
+ 'list', '--regex', '.' ],
+ [ sort "$yatta_uuid YATTA new"]
+);
+
+my $attachment_uuid;
+run_output_matches('sd', [qw/ticket attachment create --uuid/, $yatta_uuid, '--name', "paper_order.doc"], [qr/Created attachment (.*?)(?{ $attachment_uuid = $1})$/], [], "Added a attachment");
+ok($attachment_uuid);
+
+run_output_matches('sd', [qw/ticket attachments --uuid/, $yatta_uuid], [qr/^attachment id: $attachment_uuid/,
+
+ 'name: paper_order.doc',
+
+ 'content_type: text/plain' ], [], "Found the attachment");
+
+run_output_matches(
+ 'sd',
+ [ qw/ticket attachment show --uuid/, $attachment_uuid ],
+ [ "id: $attachment_uuid",
+ "content_type: text/plain",
+ qr/paper_order.doc/,
+ "ticket: $yatta_uuid"
+ ],
+ [],
+ "Found the attachment"
+);
+run_output_matches(
+ 'sd',
+ [ qw/ticket attachment update --uuid/, $attachment_uuid,
+ qw/--name/, "plague_recipe.doc"
+ ],
+ [qr/attachment $attachment_uuid updated/],
+ [],
+ "updated the attachment"
+);
+run_output_matches(
+ 'sd',
+ [ qw/ticket attachment show --uuid/, $attachment_uuid ],
+ [ "id: $attachment_uuid",
+ "content_type: text/plain",
+ qr/plague_recipe.doc/,
+ "ticket: $yatta_uuid"
+ ],
+ [],
+ "Found the attachment new version"
+);
+
+run_output_matches(
+ 'sd',
+ [ qw/ticket attachment list --uuid/, $yatta_uuid ],
+ [qr/$attachment_uuid/],
+ [],
+ "Found the attachment when we tried to search for all attachments on a ticket by the ticket's uuid"
+);
More information about the Bps-public-commit
mailing list