[Rt-commit] rt branch, 4.0/apply-scrips-to-multiple-queues, updated. rt-4.0.4-237-gb47d459
Thomas Sibley
trs at bestpractical.com
Mon Nov 5 19:36:54 EST 2012
The branch, 4.0/apply-scrips-to-multiple-queues has been updated
via b47d45907946d689e81411b9f80c22182c82d104 (commit)
via c0ecb5de614381a9ce9dfc19c74f08f87c1771ec (commit)
via 93fcdf7de019d8669e4d43f372e0c535e0318352 (commit)
from 60369e97c58f7b8da27535a2640be87a3a9bce17 (commit)
Summary of changes:
lib/RT/Test.pm | 47 +++++++++++++++++++++++++++++++++++++++++++++++
t/api/scrip.t | 32 +++++---------------------------
t/web/scrips.t | 38 +++++++++++++++++++++++++++++++++++++-
3 files changed, 89 insertions(+), 28 deletions(-)
- Log -----------------------------------------------------------------
commit 93fcdf7de019d8669e4d43f372e0c535e0318352
Author: Thomas Sibley <trs at bestpractical.com>
Date: Mon Nov 5 16:19:48 2012 -0800
Tests: Add a helper method to check a scrip's ObjectScrips records
diff --git a/lib/RT/Test.pm b/lib/RT/Test.pm
index 6b270be..43c42f6 100644
--- a/lib/RT/Test.pm
+++ b/lib/RT/Test.pm
@@ -1063,6 +1063,44 @@ sub clean_caught_mails {
unlink $tmp{'mailbox'};
}
+=head2 object_scrips_are
+
+Takes an L<RT::Scrip> object as the first argument and an arrayref of
+L<RT::Queue> objects and/or Queue IDs as the second argument.
+
+The scrip's applications (L<RT::ObjectScrip> records) are tested to ensure they
+exactly match the arrayref.
+
+An optional third arrayref may be passed to enumerate and test the queues the
+scrip is B<not> added to. This is most useful for testing the API returns the
+correct results.
+
+=cut
+
+sub object_scrips_are {
+ local $Test::Builder::Level = $Test::Builder::Level + 1;
+ my $self = shift;
+ my $scrip = shift;
+ my $to = shift || [];
+ my $not_to = shift;
+
+ Test::More::ok($scrip->IsAdded(ref $_? $_->id : $_), 'added to queue' ) foreach @$to;
+ Test::More::is_deeply(
+ [sort map $_->id, @{ $scrip->AddedTo->ItemsArrayRef }],
+ [sort grep $_, map ref $_? $_->id : $_, @$to],
+ 'correct list of added to queues',
+ );
+
+ if ($not_to) {
+ Test::More::ok(!$scrip->IsAdded(ref $_? $_->id : $_), 'not added to queue' ) foreach @$not_to;
+ Test::More::is_deeply(
+ [sort map $_->id, @{ $scrip->NotAddedTo->ItemsArrayRef }],
+ [sort grep $_, map ref $_? $_->id : $_, @$not_to],
+ 'correct list of not added to queues',
+ );
+ }
+}
+
=head2 get_relocatable_dir
Takes a path relative to the location of the test file that is being
diff --git a/t/api/scrip.t b/t/api/scrip.t
index ddd0158..279be5d 100644
--- a/t/api/scrip.t
+++ b/t/api/scrip.t
@@ -138,11 +138,11 @@ note 'check applications vs. templates';
CustomCommitCode => "1;",
);
ok($status, 'created a scrip') or diag "error: $msg";
- main->check_applications($scrip, [$queue], [0, $queue_B]);
+ RT::Test->object_scrips_are($scrip, [$queue], [0, $queue_B]);
($status, $msg) = $scrip->AddToObject( $queue_B->id );
ok(!$status, $msg);
- main->check_applications($scrip, [$queue], [0, $queue_B]);
+ RT::Test->object_scrips_are($scrip, [$queue], [0, $queue_B]);
$template = RT::Template->new( RT->SystemUser );
($status, $msg) = $template->Create( Queue => $queue_B->id, Name => 'foo' );
@@ -150,7 +150,7 @@ note 'check applications vs. templates';
($status, $msg) = $scrip->AddToObject( $queue_B->id );
ok($status, 'added scrip to another queue');
- main->check_applications($scrip, [$queue, $queue_B], [0]);
+ RT::Test->object_scrips_are($scrip, [$queue, $queue_B], [0]);
($status, $msg) = $scrip->RemoveFromObject( $queue_B->id );
ok($status, 'removed scrip from queue');
@@ -160,14 +160,14 @@ note 'check applications vs. templates';
($status, $msg) = $scrip->AddToObject( $queue_B->id );
ok(!$status, $msg);
- main->check_applications($scrip, [$queue], [0, $queue_B]);
+ RT::Test->object_scrips_are($scrip, [$queue], [0, $queue_B]);
($status, $msg) = $template->Create( Queue => 0, Name => 'foo' );
ok $status, 'created a global template';
($status, $msg) = $scrip->AddToObject( $queue_B->id );
ok($status, 'added scrip');
- main->check_applications($scrip, [$queue, $queue_B], [0]);
+ RT::Test->object_scrips_are($scrip, [$queue, $queue_B], [0]);
}
note 'basic check for disabling scrips';
@@ -212,25 +212,3 @@ note 'basic check for disabling scrips';
ok(!$scrip->Disabled, "not applied");
}
-
-sub check_applications {
- local $Test::Builder::Level = $Test::Builder::Level + 1;
- my $self = shift;
- my $scrip = shift;
- my $to = shift || [];
- my $not_to = shift || [];
-
- ok($scrip->IsAdded(ref $_? $_->id : $_), 'added to queue' ) foreach @$to;
- ok(!$scrip->IsAdded(ref $_? $_->id : $_), 'not added' ) foreach @$not_to;
- is_deeply(
- [sort map $_->id, @{ $scrip->AddedTo->ItemsArrayRef }],
- [sort grep $_, map ref $_? $_->id : $_, @$to],
- 'correct list of queues',
- );
- is_deeply(
- [sort map $_->id, @{ $scrip->NotAddedTo->ItemsArrayRef }],
- [sort grep $_, map ref $_? $_->id : $_, @$not_to],
- 'correct list of queues',
- );
-}
-
commit c0ecb5de614381a9ce9dfc19c74f08f87c1771ec
Author: Thomas Sibley <trs at bestpractical.com>
Date: Mon Nov 5 16:33:39 2012 -0800
Tests: Improve convenience of object_scrips_are
Accepts a scrip ID instead of an object as the first argument.
The individual test descriptions include the queue ID for easier
debugging.
diff --git a/lib/RT/Test.pm b/lib/RT/Test.pm
index 43c42f6..72dbfc9 100644
--- a/lib/RT/Test.pm
+++ b/lib/RT/Test.pm
@@ -58,6 +58,7 @@ use Socket;
use File::Temp qw(tempfile);
use File::Path qw(mkpath);
use File::Spec;
+use Scalar::Util qw(blessed);
our @EXPORT = qw(is_empty diag parse_mail works fails);
@@ -1065,7 +1066,7 @@ sub clean_caught_mails {
=head2 object_scrips_are
-Takes an L<RT::Scrip> object as the first argument and an arrayref of
+Takes an L<RT::Scrip> object or ID as the first argument and an arrayref of
L<RT::Queue> objects and/or Queue IDs as the second argument.
The scrip's applications (L<RT::ObjectScrip> records) are tested to ensure they
@@ -1084,18 +1085,26 @@ sub object_scrips_are {
my $to = shift || [];
my $not_to = shift;
- Test::More::ok($scrip->IsAdded(ref $_? $_->id : $_), 'added to queue' ) foreach @$to;
+ unless (blessed($scrip)) {
+ my $id = $scrip;
+ $scrip = RT::Scrip->new( RT->SystemUser );
+ $scrip->Load($id);
+ }
+
+ $to = [ map { blessed($_) ? $_->id : $_ } @$to ];
+ Test::More::ok($scrip->IsAdded($_), "added to queue $_" ) foreach @$to;
Test::More::is_deeply(
[sort map $_->id, @{ $scrip->AddedTo->ItemsArrayRef }],
- [sort grep $_, map ref $_? $_->id : $_, @$to],
+ [sort grep $_, @$to ],
'correct list of added to queues',
);
if ($not_to) {
- Test::More::ok(!$scrip->IsAdded(ref $_? $_->id : $_), 'not added to queue' ) foreach @$not_to;
+ $not_to = [ map { blessed($_) ? $_->id : $_ } @$not_to ];
+ Test::More::ok(!$scrip->IsAdded($_), "not added to queue $_" ) foreach @$not_to;
Test::More::is_deeply(
[sort map $_->id, @{ $scrip->NotAddedTo->ItemsArrayRef }],
- [sort grep $_, map ref $_? $_->id : $_, @$not_to],
+ [sort grep $_, @$not_to ],
'correct list of not added to queues',
);
}
commit b47d45907946d689e81411b9f80c22182c82d104
Author: Thomas Sibley <trs at bestpractical.com>
Date: Mon Nov 5 16:35:37 2012 -0800
Tests: Ensure scrips can't be applied both globally and to individual queues from the UI
diff --git a/t/web/scrips.t b/t/web/scrips.t
index 7b386c5..95f35d6 100644
--- a/t/web/scrips.t
+++ b/t/web/scrips.t
@@ -3,7 +3,7 @@
use strict;
use warnings;
-use RT::Test tests => 54;
+use RT::Test tests => undef;
RT->Config->Set( UseTransactionBatch => 1 );
@@ -153,6 +153,40 @@ note "check basics in scrip's admin interface";
$m->content_contains("The new value has been set.");
}
+note "check application in admin interface";
+{
+ $m->follow_link_ok({ id => 'tools-config-global-scrips-create' });
+ $m->submit_form_ok({
+ with_fields => {
+ Description => "testing application",
+ ScripCondition => "On Create",
+ ScripAction => "Open Tickets",
+ Template => "Blank",
+ },
+ button => 'Create',
+ }, "created scrip");
+ $m->content_contains("Scrip Created", "found result message");
+
+ my ($sid) = ($m->content =~ /Modify scrip #(\d+)/);
+ ok $sid, "found scrip id on the page";
+ RT::Test->object_scrips_are($sid, [0]);
+
+ $m->follow_link_ok({ id => 'page-applies-to' });
+ ok $m->form_name("AddRemoveScrip"), "found form";
+ $m->tick("RemoveScrip-$sid", 0);
+ $m->click_ok("Update", "update scrip application");
+ RT::Test->object_scrips_are($sid, []);
+
+ my $queue = RT::Test->load_or_create_queue( Name => 'General' );
+ ok $queue && $queue->id, "loaded queue";
+
+ ok $m->form_name("AddRemoveScrip"), "found form";
+ $m->tick("AddScrip-$sid", 0);
+ $m->tick("AddScrip-$sid", $queue->id);
+ $m->click_ok("Update", "update scrip application");
+ RT::Test->object_scrips_are($sid, [0], [$queue->id]);
+}
+
note "apply scrip in different stage to different queues";
{
my $queue = RT::Test->load_or_create_queue( Name => 'Regression' );
@@ -188,3 +222,5 @@ note "apply scrip in different stage to different queues";
is scalar @matches, 1, 'scrip mentioned only once';
}
+undef $m;
+done_testing;
-----------------------------------------------------------------------
More information about the Rt-commit
mailing list