[Rt-commit] rt branch, 4.4/rest-1-edit-links, created. rt-4.4.2-43-gc8bba01

Jim Brandt jbrandt at bestpractical.com
Tue Oct 3 16:50:33 EDT 2017


The branch, 4.4/rest-1-edit-links has been created
        at  c8bba01c55c2608cf566526c7f5bb2066135c9a0 (commit)

- Log -----------------------------------------------------------------
commit 48bf93f2e22c6cb8eb5577e1c28e3828159d3397
Author: Jim Brandt <jbrandt at bestpractical.com>
Date:   Tue Oct 3 11:24:15 2017 -0400

    Modify REST 1.0 tests to add multiple links in one request
    
    Modify link tests to test adding two links in one request.
    Also confirm that a previous link is removed if it isn't
    sent in the edit request.

diff --git a/t/web/rest.t b/t/web/rest.t
index 8b8cbcb..e8d98c0 100644
--- a/t/web/rest.t
+++ b/t/web/rest.t
@@ -2,7 +2,7 @@ use strict;
 use warnings;
 use RT::Interface::REST;
 
-use RT::Test tests => 34;
+use RT::Test tests => undef;
 
 my ($baseurl, $m) = RT::Test->started_ok;
 
@@ -79,7 +79,7 @@ for ("id: ticket/1",
 }
 
 # Create ticket 2 for testing ticket links
-for (2 .. 3) {
+for (2 .. 4) {
     $m->post("$baseurl/REST/1.0/ticket/edit", [
         user    => 'root',
         pass    => 'password',
@@ -94,23 +94,24 @@ for (2 .. 3) {
         ],
         Content_Type => 'form-data',
     );
+}
 
-    my $link_data = form_parse($m->content);
+diag "Add one link";
 
-    push @{$link_data->[0]->[1]}, 'DependsOn';
-    vpush($link_data->[0]->[2], 'DependsOn', $_);
+my $link_data = <<'END_LINKS';
+id: ticket/1/links
+DependsOn: 2
+END_LINKS
 
-    $m->post(
-        "$baseurl/REST/1.0/ticket/1/links",
-        [
-            user    => 'root',
-            pass    => 'password',
-            content => form_compose($link_data),
-        ],
-        Content_Type => 'form-data',
-    );
-
-}
+$m->post(
+    "$baseurl/REST/1.0/ticket/1/links",
+    [
+        user    => 'root',
+        pass    => 'password',
+        content => $link_data,
+    ],
+    Content_Type => 'form-data',
+);
 
 # See what links get reported for ticket 1.
 $m->post(
@@ -128,12 +129,48 @@ my $depends_on = vsplit($content->[0]->[2]->{DependsOn});
 @$depends_on = sort @$depends_on;
 like(
     $depends_on->[0], qr{/ticket/2$},
-    "Check ticket link.",
+    "Link to ticket 2 added.",
+) or diag("'content' obtained:\n", $m->content);
+
+diag "Add two links";
+
+$link_data = <<'END_LINKS';
+id: ticket/1/links
+DependsOn: 3,4
+END_LINKS
+
+$m->post(
+    "$baseurl/REST/1.0/ticket/1/links",
+    [
+        user    => 'root',
+        pass    => 'password',
+        content => $link_data,
+    ],
+    Content_Type => 'form-data',
+);
+
+# See what links get reported for ticket 1.
+$m->post(
+    "$baseurl/REST/1.0/ticket/1/links/show",
+    [
+        user    => 'root',
+        pass    => 'password',
+    ],
+    Content_Type => 'form-data',
+);
+
+$content = form_parse($m->content);
+$depends_on = vsplit($content->[0]->[2]->{DependsOn});
+@$depends_on = sort @$depends_on;
+
+like(
+    $depends_on->[0], qr{/ticket/3$},
+    "Link to ticket 3 found",
 ) or diag("'content' obtained:\n", $m->content);
 
 like(
-    $depends_on->[1], qr{/ticket/3$},
-    "Check ticket link.",
+    $depends_on->[1], qr{/ticket/4$},
+    "Link to ticket 4 found",
 ) or diag("'content' obtained:\n", $m->content);
 
 $m->post(
@@ -145,7 +182,7 @@ $m->post(
     Content_Type => 'form-data',
 );
 my ($link) = $m->content =~ m|DependedOnBy:.*ticket/(\d+)|;
-is($link, 1, "Check ticket link.") or diag("'content' obtained:\n", $m->content);
+is($link, undef, "Link removed from ticket 2") or diag("'content' obtained:\n", $m->content);
 
 $m->post(
     "$baseurl/REST/1.0/ticket/3/links/show",
@@ -156,9 +193,20 @@ $m->post(
     Content_Type => 'form-data',
 );
 ($link) = $m->content =~ m|DependedOnBy:.*ticket/(\d+)|;
-is($link, 1, "Check ticket link.") or diag("'content' obtained:\n", $m->content);
+is($link, 1, "Ticket 3 has link to 1.") or diag("'content' obtained:\n", $m->content);
 
+$m->post(
+    "$baseurl/REST/1.0/ticket/4/links/show",
+    [
+        user    => 'root',
+        pass    => 'password',
+    ],
+    Content_Type => 'form-data',
+);
+($link) = $m->content =~ m|DependedOnBy:.*ticket/(\d+)|;
+is($link, 1, "Ticket 4 has link to 1.") or diag("'content' obtained:\n", $m->content);
 
+diag "Test custom fields";
 {
     $m->post("$baseurl/REST/1.0/ticket/new", [
         user    => 'root',
@@ -325,3 +373,6 @@ is($link, 1, "Check ticket link.") or diag("'content' obtained:\n", $m->content)
         @{ $ticket->Transactions->ItemsArrayRef };
     is_deeply(\@txns, [['this', 'that']]);
 }
+
+undef $m;
+done_testing();

commit c8bba01c55c2608cf566526c7f5bb2066135c9a0
Author: Jim Brandt <jbrandt at bestpractical.com>
Date:   Tue Oct 3 11:27:43 2017 -0400

    Remove gotos that prevent processing multiple links
    
    The links code has loops to properly handle multiple provided
    links, but gotos at the end of the loops exit after processing
    just one. Remove the gotos to allow all provided links to be
    processed.

diff --git a/share/html/REST/1.0/Forms/ticket/links b/share/html/REST/1.0/Forms/ticket/links
index 548f641..bc637a7 100644
--- a/share/html/REST/1.0/Forms/ticket/links
+++ b/share/html/REST/1.0/Forms/ticket/links
@@ -123,14 +123,12 @@ if ($changes) {
                     my $type = $lfields{$key}->{Type};
                     my $mode = $lfields{$key}->{Mode};
                     ($n, $s) = $ticket->DeleteLink(Type => $type, $mode => $u);
-                    goto SET;
                 }
             }
             foreach my $u (keys %new) {
                 my $type = $lfields{$key}->{Type};
                 my $mode = $lfields{$key}->{Mode};
                 ($n, $s) = $ticket->AddLink(Type => $type, $mode => $u);
-                goto SET;
             }
         }
         elsif ($key ne 'id' && $key ne 'type') {

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


More information about the rt-commit mailing list