[Rt-commit] rt branch, 4.0/rest-dont-call-delete-on-ocfv-directly, created. rt-4.0.8-309-g32cbe53

Ruslan Zakirov ruz at bestpractical.com
Fri Dec 28 11:56:32 EST 2012


The branch, 4.0/rest-dont-call-delete-on-ocfv-directly has been created
        at  32cbe5378010716656e05effa38e226b22ccce4a (commit)

- Log -----------------------------------------------------------------
commit d684b5798ea5c72e61b45738fb65167d737ffaef
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Mon Jul 2 21:35:31 2012 +0300

    call DeleteCustomFieldValue instead of OCFV->Delete
    
    we were loosing history on the ticket because such direct
    call as transactions on ticket are not created

diff --git a/share/html/REST/1.0/Forms/ticket/default b/share/html/REST/1.0/Forms/ticket/default
index 58be6fb..e480219 100644
--- a/share/html/REST/1.0/Forms/ticket/default
+++ b/share/html/REST/1.0/Forms/ticket/default
@@ -442,7 +442,7 @@ else {
                             $new{$c}--;
                         }
                         else {
-                            $v->Delete();
+                            $ticket->DeleteCustomFieldValue( Field => $cf, ValueId => $v->id );
                         }
                     }
                     for ( @new ) {

commit 73137e74d64b7abf3a0bfb87eb975d21c57fdeae
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Thu Dec 27 21:00:52 2012 +0400

    drop OCFV->Delete, AddCustomFieldValue takes care
    
    This code branch is for CFs with one value only. We
    can just call AddCustomFieldValue and it will do the
    right thing.
    
    Without this change history is incorrect as transactions
    say that new value has been set instead of value change.

diff --git a/share/html/REST/1.0/Forms/ticket/default b/share/html/REST/1.0/Forms/ticket/default
index e480219..dc65fb4 100644
--- a/share/html/REST/1.0/Forms/ticket/default
+++ b/share/html/REST/1.0/Forms/ticket/default
@@ -388,7 +388,6 @@ else {
                     my $old = $vals->Next;
                     if ( $old ) {
                         if ( $val ne $old->Content ) {
-                            $old->Delete;
                             ($n, $s) = $ticket->AddCustomFieldValue(
                                  Field => $cf, Value => $val );
                             $s =~ s/^# // if defined $s;

commit 32cbe5378010716656e05effa38e226b22ccce4a
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Fri Dec 28 20:51:05 2012 +0400

    test CF changes via REST

diff --git a/t/web/rest.t b/t/web/rest.t
index beb24e8..3a84b2a 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 => 27;
+use RT::Test tests => 34;
 
 my ($baseurl, $m) = RT::Test->started_ok;
 
@@ -15,6 +15,14 @@ for my $name ("severity", "fu()n:k/") {
     ok($cf->Id, "created a CustomField");
     is($cf->Name, $name, "correct CF name");
 }
+{
+    my $cf = RT::Test->load_or_create_custom_field(
+        Name  => 'single',
+        Type  => 'FreeformSingle',
+        Queue => 'General',
+    );
+    ok($cf->Id, "created a CustomField");
+}
 
 my $queue = RT::Test->load_or_create_queue(Name => 'General');
 ok($queue->Id, "loaded the General queue");
@@ -194,6 +202,38 @@ is($link, 1, "Check ticket link.") or diag("'content' obtained:\n", $m->content)
         ]
     );
     $text = $m->content;
+    $text =~ s/.*?\n\n//;
+    $text =~ s/\n\n/\n/;
+    $text =~ s{CF\.{severity}:.*\n}{}img;
+    $text .= "CF.{severity}: explosive, a bit\n";
+    $m->post(
+        "$baseurl/REST/1.0/ticket/edit",
+        [
+            user => 'root',
+            pass => 'password',
+            content => $text,
+        ],
+        Content_Type => 'form-data'
+    );
+    $m->content =~ /Ticket ($id) updated/;
+
+    $ticket->Load($id);
+    is_deeply(
+        [sort map $_->Content, @{ $ticket->CustomFieldValues("severity")->ItemsArrayRef }],
+        ['a bit', 'explosive'],
+        "CF successfully set"
+    );
+
+    $m->post(
+        "$baseurl/REST/1.0/ticket/show",
+        [
+            user   => 'root',
+            pass   => 'password',
+            format => 'l',
+            id     => "ticket/$id",
+        ]
+    );
+    $text = $m->content;
     $text =~ s{CF\.{severity}:.*\n}{}img;
     $text .= "CF.{severity}:\n";
     $m->post(
@@ -216,5 +256,72 @@ is($link, 1, "Check ticket link.") or diag("'content' obtained:\n", $m->content)
 
     my @txns = map [$_->OldValue, $_->NewValue], grep $_->Type eq 'CustomField',
         @{ $ticket->Transactions->ItemsArrayRef };
-    is_deeply(\@txns, [['explosive', undef], ['very', undef]]);
+    is_deeply(\@txns, [['very', undef], [undef, 'a bit'], ['explosive', undef], ['a bit', undef]]);
+}
+
+{
+    $m->post("$baseurl/REST/1.0/ticket/new", [
+        user    => 'root',
+        pass    => 'password',
+        format  => 'l',
+    ]);
+
+    my $text = $m->content;
+    my @lines = $text =~ m{.*}g;
+    shift @lines; # header
+    push @lines, "CF.{single}: this";
+    $text = join "\n", @lines;
+
+    $m->post("$baseurl/REST/1.0/ticket/edit", [
+        user    => 'root',
+        pass    => 'password',
+
+        content => $text,
+    ], Content_Type => 'form-data');
+
+    my ($id) = $m->content =~ /Ticket (\d+) created/;
+    ok($id, "got ticket #$id");
+
+    my $ticket = RT::Ticket->new(RT->SystemUser);
+    $ticket->Load($id);
+    is($ticket->Id, $id, "loaded the REST-created ticket");
+    is_deeply(
+        [sort map $_->Content, @{ $ticket->CustomFieldValues("single")->ItemsArrayRef }],
+        ["this"],
+        "CF successfully set"
+    );
+
+    $m->post(
+        "$baseurl/REST/1.0/ticket/show",
+        [
+            user   => 'root',
+            pass   => 'password',
+            format => 'l',
+            id     => "ticket/$id",
+        ]
+    );
+    $text = $m->content;
+    $text =~ s{CF\.{single}:.*\n}{}img;
+    $text .= "CF.{single}: that\n";
+    $m->post(
+        "$baseurl/REST/1.0/ticket/edit",
+        [
+            user => 'root',
+            pass => 'password',
+            content => $text,
+        ],
+        Content_Type => 'form-data'
+    );
+    $m->content =~ /Ticket ($id) updated/;
+
+    $ticket->Load($id);
+    is_deeply(
+        [sort map $_->Content, @{ $ticket->CustomFieldValues("single")->ItemsArrayRef }],
+        ['that'],
+        "CF successfully set"
+    );
+
+    my @txns = map [$_->OldValue, $_->NewValue], grep $_->Type eq 'CustomField',
+        @{ $ticket->Transactions->ItemsArrayRef };
+    is_deeply(\@txns, [['this', 'that']]);
 }

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


More information about the Rt-commit mailing list