[Rt-commit] r7498 - in rtir/branches/2.3-EXPERIMENTAL: . t
jesse at bestpractical.com
jesse at bestpractical.com
Thu Apr 12 20:31:16 EDT 2007
Author: jesse
Date: Thu Apr 12 20:31:13 2007
New Revision: 7498
Added:
rtir/branches/2.3-EXPERIMENTAL/t/017-locking.t
Modified:
rtir/branches/2.3-EXPERIMENTAL/ (props changed)
rtir/branches/2.3-EXPERIMENTAL/lib/RT/IR/Ticket.pm
Log:
r54808 at pinglin: jesse | 2007-04-12 20:30:06 -0400
* Locking API
Modified: rtir/branches/2.3-EXPERIMENTAL/lib/RT/IR/Ticket.pm
==============================================================================
--- rtir/branches/2.3-EXPERIMENTAL/lib/RT/IR/Ticket.pm (original)
+++ rtir/branches/2.3-EXPERIMENTAL/lib/RT/IR/Ticket.pm Thu Apr 12 20:31:13 2007
@@ -50,5 +50,32 @@
return $tickets->Count;
}
+sub Locked {
+ my $ticket =shift;
+ return $ticket->FirstAttribute('RTIR_Lock');
+}
+
+sub Lock {
+ my $ticket = shift;
+
+ if ( $ticket->RT::IR::Ticket::Locked ) {
+ return undef;
+ } else {
+ $ticket->SetAttribute(
+ Name => 'RTIR_Lock',
+ Content => {
+ User => $ticket->CurrentUser->id,
+ Timestamp => time()
+
+ }
+ );
+ }
+}
+
+
+sub Unlock {
+ my $ticket = shift;
+ $ticket->DeleteAttribute('RTIR_Lock');
+}
1;
Added: rtir/branches/2.3-EXPERIMENTAL/t/017-locking.t
==============================================================================
--- (empty file)
+++ rtir/branches/2.3-EXPERIMENTAL/t/017-locking.t Thu Apr 12 20:31:13 2007
@@ -0,0 +1,50 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+use Test::More tests => 16;
+require "t/rtir-test.pl";
+use RT::IR::Ticket;
+
+my $agent = default_agent();
+
+my $SUBJECT = "foo " . rand;
+
+# Create a report
+my $report = create_ir($agent, {Subject => $SUBJECT, Content => "bla" });
+
+{
+ my $ir_obj = RT::Ticket->new(RT::SystemUser());
+
+ $ir_obj->Load($report);
+ is($ir_obj->Id, $report, "report has right ID");
+ is($ir_obj->Subject, $SUBJECT, "subject is right");
+
+ ok(!RT::IR::Ticket::Locked($ir_obj), "Starts off unlocked");
+ ok(RT::IR::Ticket::Lock($ir_obj), "Then we lock it");
+ ok(RT::IR::Ticket::Locked($ir_obj), "Then it's locked");
+ ok(!RT::IR::Ticket::Lock($ir_obj), "Can't lock a locked ticket");
+ ok(RT::IR::Ticket::Unlock($ir_obj), "Then we unlock it");
+ ok(!RT::IR::Ticket::Locked($ir_obj), "Ends unlocked");
+
+}
+
+1;
+
+__DATA__
+
+TODO: think about testing locking on other object types
+
+# Create a new Incident from that report
+my $first_incident_id = create_incident_for_ir($agent, $report, {Subject => "first incident"},
+ {Function => "IncidentCoord"});
+
+# TODO: make sure subject and content come from Report
+
+# TODO: create Incident with new subject/content
+
+# TODO: make sure all fields are set properly in DB
+
+# create a new incident
+my $second_incident_id = create_incident( $agent, { Subject => "foo Incident", Content => "bar baz quux" } );
+
More information about the Rt-commit
mailing list