[Rt-commit] rt branch, 3.9-fts, updated. rt-3.9.4-50-gbfe54a9

Ruslan Zakirov ruz at bestpractical.com
Thu Oct 21 00:06:56 EDT 2010


The branch, 3.9-fts has been updated
       via  bfe54a96e908f00adce58fda0445cad811f76402 (commit)
       via  7edf068ccb74c33459ac8b1813fda74bc3ff2c07 (commit)
      from  c36bbd1e9fe0e03f2f3516995fad017502018abd (commit)

Summary of changes:
 etc/RT_Config.pm.in                       |    3 +-
 lib/RT/Test.pm                            |   41 ++++++++++++
 sbin/rt-fulltext-indexer.in               |   97 +++++++++++++++++++++++++----
 t/fts/indexed_oracle.t                    |   40 ++----------
 t/fts/indexed_pg.t                        |   43 +++----------
 t/ticket/cfsort-freeform-multiple.t       |    6 +-
 t/ticket/cfsort-freeform-single.t         |    4 +-
 t/ticket/search_by_cf_freeform_multiple.t |    4 +-
 t/ticket/search_by_cf_freeform_single.t   |    4 +-
 t/ticket/search_by_links.t                |   29 ++-------
 t/ticket/search_by_watcher.t              |   36 +++--------
 t/ticket/sort-by-queue.t                  |   20 +-----
 t/ticket/sort-by-user.t                   |    5 +-
 13 files changed, 172 insertions(+), 160 deletions(-)

- Log -----------------------------------------------------------------
commit 7edf068ccb74c33459ac8b1813fda74bc3ff2c07
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Thu Oct 21 05:14:18 2010 +0400

    documentation on FTS

diff --git a/etc/RT_Config.pm.in b/etc/RT_Config.pm.in
index b6d8153..2b7d6f0 100755
--- a/etc/RT_Config.pm.in
+++ b/etc/RT_Config.pm.in
@@ -1541,7 +1541,8 @@ default is disabled at all. To enable FTS set key 'Enable' to true value.
 Setup of indexes and filling them with data requires additional steps that
 vary from DB to DB. Use F<sbin/rt-setup-fulltext-index> helper
 for quick start. This script creates required structures in the DB and
-gives some ideas on next steps.
+gives some ideas on next steps. Use F<sbin/rt-fulltext-indexer> to keep
+the index in sync.
 
 =cut
 
diff --git a/sbin/rt-fulltext-indexer.in b/sbin/rt-fulltext-indexer.in
index 4606a86..5eba7f8 100644
--- a/sbin/rt-fulltext-indexer.in
+++ b/sbin/rt-fulltext-indexer.in
@@ -84,15 +84,38 @@ use RT::Interface::CLI ();
 my %OPT = (
     help        => 0,
 );
+my @OPT_LIST = qw(help|h!);
 
-use Getopt::Long qw(GetOptions);
-GetOptions(
-    'h|help!'        => \$OPT{'help'},
+my $db_type = RT->Config->Get('DatabaseType');
+if ( $db_type eq 'Pg' ) {
+    %OPT = (
+        %OPT,
+        limit  => 0,
+    );
+    push @OPT_LIST, 'limit=i';
+}
+elsif ( $db_type eq 'mysql' ) {
+    %OPT = (
+        %OPT,
+        limit  => 0,
+    );
+    push @OPT_LIST, 'limit=i';
+}
+elsif ( $db_type eq 'Oracle' ) {
+    %OPT = (
+        %OPT,
+        memory => '2M',
+    );
+    push @OPT_LIST, qw(memory=s);
+}
 
-);
+use Getopt::Long qw(GetOptions);
+GetOptions( \%OPT, @OPT_LIST );
 
 if ( $OPT{'help'} ) {
-    RT::Interface::CLI->ShowHelp;
+    RT::Interface::CLI->ShowHelp(
+        Sections => 'NAME|DESCRIPTION|'. uc($db_type),
+    );
 }
 
 my $fts_config = RT->Config->Get('FullTextSearch') || {};
@@ -109,14 +132,11 @@ unless ( $fts_config->{'Indexed'} ) {
     exit 1;
 }
 
-my $db_type = RT->Config->Get('DatabaseType');
-
 if ( $db_type eq 'Oracle' ) {
     my $index = $fts_config->{'IndexName'} || 'rt_fts_index';
-    my $memory = '2M';
     $RT::Handle->dbh->do(
         "begin ctx_ddl.sync_index(?, ?); end;", undef,
-        $index, $memory
+        $index, $OPT{'memory'}
     );
     exit;
 }
@@ -382,13 +402,64 @@ sub warning  { $RT::Logger->warn(_(@_)); verbose(@_); 1 }
 
 rt-fulltext-indexer - Indexer for full text search
 
-=head1 SYNOPSIS
+=head1 DESCRIPTION
 
-    /opt/rt3/local/sbin/rt-fulltext-indexer --help
+This is a helper script to keep full text index in sync with data.
 
-    /opt/rt3/local/sbin/rt-fulltext-indexer --limit 100
+Start from F<sbin/rt-setup-fulltext-index>, adjust config and run
+this script via cron.
 
-=head1 DESCRIPTION
+=head1 ORACLE
+
+=head2 USAGE
+
+    rt-fulltext-indexer --help
+    rt-fulltext-indexer
+    rt-fulltext-indexer --memory 10M
+
+=head2 DESCRIPTION
+
+Basicly this script runs the following query:
+
+    begin
+    ctx_ddl.sync_index('rt_fts_index', '2M');
+    end;
+
+Ammount of memory used for the sync can be controlled with --memory option.
+
+There is way to do all of this on Oracle side by setting up a DBMS_JOB. Read
+"Managing DML Operations for a CONTEXT Index" chapter from "Text Application
+Developer's Guide" for more info on the topic and how to keep index optimized,
+collect garbage and other stuff.
+
+=head1 PG
+
+=head2 USAGE
+
+    rt-fulltext-indexer --help
+    rt-fulltext-indexer
+    rt-fulltext-indexer --limit 100
+
+=head2 DESCRIPTION
+
+This script find attachments that should be indexed and process content if required
+and stores in the index. Use --limit option to specify how many attachments to process.
+
+=head1 MYSQL
+
+=head2 USAGE
+
+    rt-fulltext-indexer --help
+    rt-fulltext-indexer
+    rt-fulltext-indexer --limit 100
+
+=head2 DESCRIPTION
+
+This script find attachments that should be indexed and process content if required
+and generates xmlpipe2 document stream that can processed by sphinx. Read more in
+sphinx reference manual.
+
+Use --limit option to specify how many attachments to process.
 
 =cut
 

commit bfe54a96e908f00adce58fda0445cad811f76402
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Thu Oct 21 08:06:25 2010 +0400

    create_tickets and create_ticket in RT::Test

diff --git a/lib/RT/Test.pm b/lib/RT/Test.pm
index 3d81bae..c22b85a 100644
--- a/lib/RT/Test.pm
+++ b/lib/RT/Test.pm
@@ -600,6 +600,47 @@ sub load_or_create_queue {
     return $obj;
 }
 
+sub create_tickets {
+    local $Test::Builder::Level = $Test::Builder::Level + 1;
+
+    my $self = shift;
+    my $defaults = shift;
+    my @data = @_;
+
+    @data = sort { rand(100) <=> rand(100) } @data
+        if delete $defaults->{'RandomOrder'};
+
+    my @res = ();
+    while ( @data ) {
+        my %args = %{ shift @data };
+        $args{$_} = $res[ $args{$_} ]->id foreach
+            grep $args{ $_ }, keys %RT::Ticket::LINKTYPEMAP;
+        push @res, $self->create_ticket( %$defaults, %args );
+    }
+    return @res;
+}
+
+sub create_ticket {
+    local $Test::Builder::Level = $Test::Builder::Level + 1;
+
+    my $self = shift;
+    my %args = @_;
+
+    if ( my $content = delete $args{'Content'} ) {
+        $args{'MIMEObj'} = MIME::Entity->build(
+            From    => $args{'Requestor'},
+            Subject => $args{'Subject'},
+            Data    => $content,
+        );
+    }
+
+    my $t = RT::Ticket->new( RT->SystemUser );
+    my ( $id, undef, $msg ) = $t->Create( %args );
+    Test::More::ok( $id, "ticket created" )
+        or Test::More::diag("error: $msg");
+    return $t;
+}
+
 =head2 load_or_create_custom_field
 
 =cut
diff --git a/t/fts/indexed_oracle.t b/t/fts/indexed_oracle.t
index 5a843fd..5179d2a 100644
--- a/t/fts/indexed_oracle.t
+++ b/t/fts/indexed_oracle.t
@@ -4,7 +4,7 @@ use strict;
 use warnings;
 
 use RT::Test tests => undef;
-plan skip_all => 'Not Pg' unless RT->Config->Get('DatabaseType') eq 'Oracle';
+plan skip_all => 'Not Oracle' unless RT->Config->Get('DatabaseType') eq 'Oracle';
 plan tests => 9;
 
 RT->Config->Set( FullTextSearch => Enable => 1, Indexed => 1 );
@@ -15,8 +15,6 @@ my $q = RT::Test->load_or_create_queue( Name => 'General' );
 ok $q && $q->id, 'loaded or created queue';
 my $queue = $q->Name;
 
-my ($total, @data, @tickets, @test, @conditions) = (0, ());
-
 sub setup_indexing {
     my %args = (
         'no-ask'       => 1,
@@ -36,38 +34,14 @@ sub sync_index {
     ok(!$exit_code, "synced the index") or diag "output: $output";
 }
 
-sub add_tix_from_data {
-    my @res = ();
-    while (@data) {
-        my $t = RT::Ticket->new(RT->SystemUser);
-        my %args = %{ shift(@data) };
-
-        if ( my $content = delete $args{'Content'} ) {
-            $args{'MIMEObj'} = MIME::Entity->build(
-                From    => $args{'Requestor'},
-                To      => $q->CorrespondAddress,
-                Subject => $args{'Subject'},
-                Data    => $content,
-            );
-        }
-        my ( $id, undef, $msg ) = $t->Create(
-            Queue => $q->id,
-            %args,
-        );
-        ok( $id, "ticket created" ) or diag("error: $msg");
-        push @res, $t;
-        $total++;
-    }
-    sync_index();
-    return @res;
-}
-
 sub run_tests {
+    my @test = @_;
     while ( my ($query, $checks) = splice @test, 0, 2 ) {
         run_test( $query, %$checks );
     }
 }
 
+my @tickets;
 sub run_test {
     my ($query, %checks) = @_;
     my $query_prefix = join ' OR ', map 'id = '. $_->id, @tickets;
@@ -92,15 +66,15 @@ sub run_test {
     diag "Wrong SQL query for '$query':". $tix->BuildSelectQuery if $error;
 }
 
- at data = (
+ at tickets = RT::Test->create_tickets(
+    { Queue => $q->id },
     { Subject => 'book', Content => 'book' },
     { Subject => 'bar', Content => 'bar' },
 );
- at tickets = add_tix_from_data();
+sync_index();
 
- at test = (
+run_tests(
     "Content LIKE 'book'" => { book => 1, bar => 0 },
     "Content LIKE 'bar'" => { book => 0, bar => 1 },
 );
-run_tests();
 
diff --git a/t/fts/indexed_pg.t b/t/fts/indexed_pg.t
index 1bd9204..6606569 100644
--- a/t/fts/indexed_pg.t
+++ b/t/fts/indexed_pg.t
@@ -15,8 +15,6 @@ my $q = RT::Test->load_or_create_queue( Name => 'General' );
 ok $q && $q->id, 'loaded or created queue';
 my $queue = $q->Name;
 
-my ($total, @data, @tickets, @test, @conditions) = (0, ());
-
 sub setup_indexing {
     my %args = (
         'no-ask'       => 1,
@@ -34,37 +32,14 @@ sub setup_indexing {
     ok(!$exit_code, "setted up index") or diag "output: $output";
 }
 
-sub add_tix_from_data {
-    my @res = ();
-    while (@data) {
-        my $t = RT::Ticket->new(RT->SystemUser);
-        my %args = %{ shift(@data) };
-
-        if ( my $content = delete $args{'Content'} ) {
-            $args{'MIMEObj'} = MIME::Entity->build(
-                From    => $args{'Requestor'},
-                To      => $q->CorrespondAddress,
-                Subject => $args{'Subject'},
-                Data    => $content,
-            );
-        }
-        my ( $id, undef, $msg ) = $t->Create(
-            Queue => $q->id,
-            %args,
-        );
-        ok( $id, "ticket created" ) or diag("error: $msg");
-        push @res, $t;
-        $total++;
-    }
-    return @res;
-}
-
 sub run_tests {
+    my @test = @_;
     while ( my ($query, $checks) = splice @test, 0, 2 ) {
         run_test( $query, %$checks );
     }
 }
 
+my @tickets;
 sub run_test {
     my ($query, %checks) = @_;
     my $query_prefix = join ' OR ', map 'id = '. $_->id, @tickets;
@@ -89,15 +64,15 @@ sub run_test {
     diag "Wrong SQL query for '$query':". $tix->BuildSelectQuery if $error;
 }
 
- at data = (
-    { Subject => 'foo', Content => 'foo' },
+ at tickets = RT::Test->create_tickets(
+    { Queue => $q->id },
+    { Subject => 'book', Content => 'book' },
     { Subject => 'bar', Content => 'bar' },
 );
- at tickets = add_tix_from_data();
+sync_index();
 
- at test = (
-    "Content LIKE 'foo'" => { foo => 1, bar => 0 },
-    "Content LIKE 'bar'" => { foo => 0, bar => 1 },
+run_tests(
+    "Content LIKE 'book'" => { book => 1, bar => 0 },
+    "Content LIKE 'bar'" => { book => 0, bar => 1 },
 );
-run_tests();
 
diff --git a/t/ticket/cfsort-freeform-multiple.t b/t/ticket/cfsort-freeform-multiple.t
index 539ce91..97492ac 100644
--- a/t/ticket/cfsort-freeform-multiple.t
+++ b/t/ticket/cfsort-freeform-multiple.t
@@ -42,8 +42,8 @@ sub add_tix_from_data {
     my @res = ();
     @data = sort { rand(100) <=> rand(100) } @data;
     while (@data) {
-        my $t = RT::Ticket->new(RT->SystemUser);
         my %args = %{ shift(@data) };
+
         my @values = ();
         if ( exists $args{'CF'} && ref $args{'CF'} ) {
             @values = @{ delete $args{'CF'} };
@@ -52,13 +52,13 @@ sub add_tix_from_data {
         }
         $args{ 'CustomField-'. $cf->id } = \@values
             if @values;
+
         my $subject = join(",", sort @values) || '-';
-        my ( $id, undef $msg ) = $t->Create(
+        my $t = RT::Test->create_ticket(
             %args,
             Queue => $queue->id,
             Subject => $subject,
         );
-        ok( $id, "ticket created" ) or diag("error: $msg");
         push @res, $t;
         $total++;
     }
diff --git a/t/ticket/cfsort-freeform-single.t b/t/ticket/cfsort-freeform-single.t
index e29d64e..dc4da53 100644
--- a/t/ticket/cfsort-freeform-single.t
+++ b/t/ticket/cfsort-freeform-single.t
@@ -45,7 +45,6 @@ sub add_tix_from_data {
     my @res = ();
     @data = sort { rand(100) <=> rand(100) } @data;
     while (@data) {
-        my $t = RT::Ticket->new(RT->SystemUser);
         my %args = %{ shift(@data) };
 
         my $subject = '-';
@@ -62,12 +61,11 @@ sub add_tix_from_data {
                 if $e eq 'CF';
         }
 
-        my ( $id, undef $msg ) = $t->Create(
+        my $t = RT::Test->create_ticket(
             %args,
             Queue => $queue->id,
             Subject => $subject,
         );
-        ok( $id, "ticket created" ) or diag("error: $msg");
         push @res, $t;
         $total++;
     }
diff --git a/t/ticket/search_by_cf_freeform_multiple.t b/t/ticket/search_by_cf_freeform_multiple.t
index fd9eb67..41e4ecc 100644
--- a/t/ticket/search_by_cf_freeform_multiple.t
+++ b/t/ticket/search_by_cf_freeform_multiple.t
@@ -31,13 +31,11 @@ sub add_tix_from_data {
         my %args = %{ shift(@data) };
         my @cf_value = $args{'Subject'} ne '-'? (split /(?=.)/, $args{'Subject'}) : ();
         diag "vals: ". join ', ', @cf_value;
-        my $t = RT::Ticket->new(RT->SystemUser);
-        my ( $id, undef $msg ) = $t->Create(
+        my $t = RT::Test->create_ticket(
             Queue => $q->id,
             %args,
             "CustomField-$cf_id" => \@cf_value,
         );
-        ok( $id, "ticket created" ) or diag("error: $msg");
 
         my $got = join ',', sort do { 
             my $vals = $t->CustomFieldValues( $cf_name );
diff --git a/t/ticket/search_by_cf_freeform_single.t b/t/ticket/search_by_cf_freeform_single.t
index d0ff9af..38eab82 100644
--- a/t/ticket/search_by_cf_freeform_single.t
+++ b/t/ticket/search_by_cf_freeform_single.t
@@ -30,13 +30,11 @@ sub add_tix_from_data {
     while (@data) {
         my %args = %{ shift(@data) };
         my $cf_value = $args{'Subject'} ne '-'? $args{'Subject'} : undef;
-        my $t = RT::Ticket->new(RT->SystemUser);
-        my ( $id, undef $msg ) = $t->Create(
+        my $t = RT::Test->create_ticket(
             Queue => $q->id,
             %args,
             "CustomField-$cf_id" => $cf_value,
         );
-        ok( $id, "ticket created" ) or diag("error: $msg");
         is( $t->FirstCustomFieldValue( $cf_name ), $cf_value, 'correct value' );
         push @res, $t;
         $total++;
diff --git a/t/ticket/search_by_links.t b/t/ticket/search_by_links.t
index fc311d0..81b4cc6 100644
--- a/t/ticket/search_by_links.t
+++ b/t/ticket/search_by_links.t
@@ -9,24 +9,7 @@ use RT::Ticket;
 my $q = RT::Test->load_or_create_queue( Name => 'Regression' );
 ok $q && $q->id, 'loaded or created queue';
 
-my ($total, @data, @tickets, %test) = (0, ());
-
-sub add_tix_from_data {
-    my @res = ();
-    while (@data) {
-        my $t = RT::Ticket->new(RT->SystemUser);
-        my %args = %{ shift(@data) };
-        $args{$_} = $res[ $args{$_} ]->id foreach grep $args{$_}, keys %RT::Ticket::LINKTYPEMAP;
-        my ( $id, undef $msg ) = $t->Create(
-            Queue => $q->id,
-            %args,
-        );
-        ok( $id, "ticket created" ) or diag("error: $msg");
-        push @res, $t;
-        $total++;
-    }
-    return @res;
-}
+my ($total, @tickets, %test) = (0, ());
 
 sub run_tests {
     my $query_prefix = join ' OR ', map 'id = '. $_->id, @tickets;
@@ -53,12 +36,13 @@ sub run_tests {
 }
 
 # simple set with "no links", "parent and child"
- at data = (
+ at tickets = RT::Test->create_tickets(
+    { Queue => $q->id },
     { Subject => '-', },
     { Subject => 'p', },
     { Subject => 'c', MemberOf => -1 },
 );
- at tickets = add_tix_from_data();
+$total += @tickets;
 %test = (
     'Linked     IS NOT NULL'  => { '-' => 0, c => 1, p => 1 },
     'Linked     IS     NULL'  => { '-' => 1, c => 0, p => 0 },
@@ -89,7 +73,8 @@ sub run_tests {
 run_tests();
 
 # another set with tests of combinations searches
- at data = (
+ at tickets = RT::Test->create_tickets(
+    { Queue => $q->id },
     { Subject => '-', },
     { Subject => 'p', },
     { Subject => 'rp',  RefersTo => -1 },
@@ -97,7 +82,7 @@ run_tests();
     { Subject => 'rc1', RefersTo => -1 },
     { Subject => 'rc2', RefersTo => -2 },
 );
- at tickets = add_tix_from_data();
+$total += @tickets;
 my $pid = $tickets[1]->id;
 %test = (
     'RefersTo IS NOT NULL'  => { '-' => 0, c => 0, p => 0, rp => 1, rc1 => 1, rc2 => 1 },
diff --git a/t/ticket/search_by_watcher.t b/t/ticket/search_by_watcher.t
index c1ba254..612b128 100644
--- a/t/ticket/search_by_watcher.t
+++ b/t/ticket/search_by_watcher.t
@@ -10,22 +10,7 @@ my $q = RT::Test->load_or_create_queue( Name => 'Regression' );
 ok $q && $q->id, 'loaded or created queue';
 my $queue = $q->Name;
 
-my ($total, @data, @tickets, @test, @conditions) = (0, ());
-
-sub add_tix_from_data {
-    my @res = ();
-    while (@data) {
-        my $t = RT::Ticket->new(RT->SystemUser);
-        my ( $id, undef $msg ) = $t->Create(
-            Queue => $q->id,
-            %{ shift(@data) },
-        );
-        ok( $id, "ticket created" ) or diag("error: $msg");
-        push @res, $t;
-        $total++;
-    }
-    return @res;
-}
+my ($total, @tickets, @test, @conditions) = (0, ());
 
 sub generate_tix {
     my @list = (
@@ -36,7 +21,7 @@ sub generate_tix {
         ['x at foo.com', 'z at bar.com'],
         ['x at foo.com', 'y at bar.com', 'z at bar.com'],
     );
-    @data = ();
+    my @data = ();
     foreach my $r (@list) {
         foreach my $c (@list) {
             my $subject = 'r:'. (join( '', map substr($_, 0, 1), @$r ) || '-') .';';
@@ -49,7 +34,7 @@ sub generate_tix {
             };
         }
     }
-    return add_tix_from_data();
+    return RT::Test->create_tickets( { Queue => $q->id }, @data );
 }
 
 sub run_tests {
@@ -195,6 +180,7 @@ sub run_auto_tests {
 );
 
 @tickets = generate_tix();
+$total += @tickets;
 {
     my $tix = RT::Tickets->new(RT->SystemUser);
     $tix->FromSQL("Queue = '$queue'");
@@ -237,14 +223,12 @@ my $nobody = RT::Nobody();
     # create ticket and force type to not a 'ticket' value
     # bug #6898 at rt3.fsck.com
     # and http://marc.theaimsgroup.com/?l=rt-devel&m=112662934627236&w=2
-    @data = ( { Subject => 'not a ticket' } );
-    my($t) = add_tix_from_data();
+    my($t) = RT::Test->create_tickets( { Queue => $q->id }, { Subject => 'not a ticket' } );
     $t->_Set( Field             => 'Type',
               Value             => 'not a ticket',
               CheckACL          => 0,
               RecordTransaction => 0,
             );
-    $total--;
 
     my $tix = RT::Tickets->new(RT->SystemUser);
     $tix->FromSQL("Queue = '$queue' AND Owner = 'Nobody'");
@@ -263,16 +247,18 @@ my $nobody = RT::Nobody();
     my $u = RT::User->new( RT->SystemUser );
     $u->LoadOrCreateByEmail('alpha at e.com');
     ok($u->id, "loaded user");
-    @data = ( { Subject => '4', Owner => $u->id } );
-    my($t) = add_tix_from_data();
+    my($t) = RT::Test->create_tickets(
+        { Queue => $q->id }, { Subject => '4', Owner => $u->id },
+    );
     is( $t->Owner, $u->id, "created ticket with custom owner" );
     my $u_alpha_id = $u->id;
 
     $u = RT::User->new( RT->SystemUser );
     $u->LoadOrCreateByEmail('bravo at e.com');
     ok($u->id, "loaded user");
-    @data = ( { Subject => '5', Owner => $u->id } );
-    ($t) = add_tix_from_data();
+    ($t) = RT::Test->create_tickets(
+        { Queue => $q->id }, { Subject => '5', Owner => $u->id },
+    );
     is( $t->Owner, $u->id, "created ticket with custom owner" );
     my $u_bravo_id = $u->id;
 
diff --git a/t/ticket/sort-by-queue.t b/t/ticket/sort-by-queue.t
index 84a57a1..4aa7f47 100644
--- a/t/ticket/sort-by-queue.t
+++ b/t/ticket/sort-by-queue.t
@@ -29,21 +29,7 @@ foreach my $name ( qw(sort-by-queue-Z sort-by-queue-A) ) {
     push @qids, $queue->id;
 }
 
-my ($total, @data, @tickets, @test) = (0, ());
-
-sub add_tix_from_data {
-    my @res = ();
-    @data = sort { rand(100) <=> rand(100) } @data;
-    while (@data) {
-        my $t = RT::Ticket->new(RT->SystemUser);
-        my %args = %{ shift(@data) };
-        my ( $id, undef, $msg ) = $t->Create( %args );
-        ok( $id, "ticket created" ) or diag("error: $msg");
-        push @res, $t;
-        $total++;
-    }
-    return @res;
-}
+my ($total, @tickets, @test) = (0, ());
 
 sub run_tests {
     my $query_prefix = join ' OR ', map 'id = '. $_->id, @tickets;
@@ -88,11 +74,11 @@ sub run_tests {
     }
 }
 
- at data = (
+ at tickets = RT::Test->create_tickets(
+    { RandomOrder => 1 },
     { Queue => $qids[0], Subject => 'z' },
     { Queue => $qids[1], Subject => 'a' },
 );
- at tickets = add_tix_from_data();
 @test = (
     { Order => "Queue" },
 );
diff --git a/t/ticket/sort-by-user.t b/t/ticket/sort-by-user.t
index 17df0ba..d98098b 100644
--- a/t/ticket/sort-by-user.t
+++ b/t/ticket/sort-by-user.t
@@ -53,10 +53,10 @@ sub add_tix_from_data {
     my @res = ();
     @data = sort { rand(100) <=> rand(100) } @data;
     while (@data) {
-        my $t = RT::Ticket->new(RT->SystemUser);
         my %args = %{ shift(@data) };
 
-        my ( $id, undef, $msg ) = $t->Create( %args, Queue => $queue->id );
+        my $t = RT::Test->create_ticket( %args, Queue => $queue->id );
+
         if ( $args{'Owner'} ) {
             is $t->Owner, $args{'Owner'}, "owner is correct";
         }
@@ -67,7 +67,6 @@ sub add_tix_from_data {
         if ( $args{'LastUpdatedBy'} ) {
             $t->__Set( Field => 'LastUpdatedBy', Value => $args{'LastUpdatedBy'} );
         }
-        ok( $id, "ticket created" ) or diag("error: $msg");
         push @res, $t;
         $total++;
     }

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


More information about the Rt-commit mailing list