[Rt-commit] rt branch, 4.2/pluggable-cf-types, updated. rt-4.0.1rc1-31-gfb75c72

Chia-liang Kao clkao at bestpractical.com
Fri Jun 3 05:11:17 EDT 2011


The branch, 4.2/pluggable-cf-types has been updated
       via  fb75c72b458286e4d272325140d55377865c1dfb (commit)
       via  386edc02b54abd42f4a159071ebb5c0eb7af3630 (commit)
       via  ee6b3146df4b2d98f33d83df2563ce922e4c80d9 (commit)
       via  27d1f41da3fd3c414b9c9631b92674a97c522d04 (commit)
      from  02380cd80eb83cdf82c5c453794de8b2d868cb22 (commit)

Summary of changes:
 lib/RT/CustomField/Type/ImageWithCaption.pm |    2 +
 lib/RT/Interface/Web.pm                     |   87 +++++++++++++++++----------
 t/customfields/image_caption.t              |   51 +++++++++++++++-
 3 files changed, 106 insertions(+), 34 deletions(-)

- Log -----------------------------------------------------------------
commit 27d1f41da3fd3c414b9c9631b92674a97c522d04
Author: Chia-liang Kao <clkao at bestpractical.com>
Date:   Fri Jun 3 15:17:36 2011 +0800

    make sure empty cf works for create

diff --git a/lib/RT/CustomField/Type/ImageWithCaption.pm b/lib/RT/CustomField/Type/ImageWithCaption.pm
index ca0e7f0..9898ccc 100644
--- a/lib/RT/CustomField/Type/ImageWithCaption.pm
+++ b/lib/RT/CustomField/Type/ImageWithCaption.pm
@@ -18,6 +18,8 @@ sub Stringify {
 sub CreateArgsFromWebArgs {
     my ($self, $cf, $web_args) = @_;
 
+    return unless $web_args->{Upload};
+
     my $args = HTML::Mason::Commands::_UploadedFileArgs($web_args->{Upload});
     # override value over filename from upload, if caption is provided
     $args->{Value} = $web_args->{Value} if length $web_args->{Value};
diff --git a/t/customfields/image_caption.t b/t/customfields/image_caption.t
index baaed19..9a7d765 100644
--- a/t/customfields/image_caption.t
+++ b/t/customfields/image_caption.t
@@ -3,7 +3,7 @@
 use strict;
 use warnings;
 
-use RT::Test test => 17;
+use RT::Test tests => 26;
 
 my ($baseurl, $agent) =RT::Test->started_ok;
 ok( $agent->login, 'log in' );
@@ -90,3 +90,25 @@ diag "create a ticket via web and set image with catpion" if $ENV{'TEST_VERBOSE'
 }
 
 
+
+
+diag "create a ticket via web and leave the image empty" if $ENV{'TEST_VERBOSE'};
+{
+    ok $agent->goto_create_ticket($q), "go to create ticket";
+    $agent->submit_form(
+        form_name => 'TicketCreate',
+        fields    => {
+            Subject   => 'test without img',
+        }
+    );
+
+    $agent->content_like( qr/test without img/, "created" );
+    my ($id) = $agent->content =~ /Ticket (\d+) created/;
+    ok( $id, "created ticket $id" );
+
+    my $ticket = RT::Ticket->new($RT::SystemUser);
+    $ticket->Load($id);
+    ok( $ticket->id, 'loaded ticket' );
+}
+
+

commit ee6b3146df4b2d98f33d83df2563ce922e4c80d9
Author: Chia-liang Kao <clkao at bestpractical.com>
Date:   Fri Jun 3 16:52:48 2011 +0800

    extract logic for cf value from webargs

diff --git a/lib/RT/Interface/Web.pm b/lib/RT/Interface/Web.pm
index 6b3ae81..18588d0 100644
--- a/lib/RT/Interface/Web.pm
+++ b/lib/RT/Interface/Web.pm
@@ -2218,6 +2218,24 @@ sub _ProcessObjectCustomFieldUpdates {
         delete $args{'ARGS'}->{'Values'};
     }
 
+    my $_arg_values = sub {
+        my @values = ();
+        my $args = shift;
+        if ( ref $args eq 'ARRAY' ) {
+            @values = @$args;
+        } elsif ( $cf_type =~ /text/i ) {    # Both Text and Wikitext
+            @values = $args;
+        } else {
+            @values = split /\r*\n/, $args if defined $args;
+        }
+        return grep length, map {
+            s/\r+\n/\n/g;
+            s/^\s+//;
+            s/\s+$//;
+            $_;
+        } grep defined, @values;
+    };
+
     my @results;
     foreach my $arg ( keys %{ $args{'ARGS'} } ) {
 
@@ -2239,23 +2257,7 @@ sub _ProcessObjectCustomFieldUpdates {
             $args{'ARGS'}->{'Values'} = undef;
         }
 
-        my @values = ();
-        if ( ref $args{'ARGS'}->{$arg} eq 'ARRAY' ) {
-            @values = @{ $args{'ARGS'}->{$arg} };
-        } elsif ( $cf_type =~ /text/i ) {    # Both Text and Wikitext
-            @values = ( $args{'ARGS'}->{$arg} );
-        } else {
-            @values = split /\r*\n/, $args{'ARGS'}->{$arg}
-                if defined $args{'ARGS'}->{$arg};
-        }
-        @values = grep length, map {
-            s/\r+\n/\n/g;
-            s/^\s+//;
-            s/\s+$//;
-            $_;
-            }
-            grep defined, @values;
-
+        my @values = $_arg_values->($args{'ARGS'}->{$arg});
         if ( $arg eq 'AddValue' || $arg eq 'Value' ) {
             foreach my $value (@values) {
                 my ( $val, $msg ) = $args{'Object'}->AddCustomFieldValue(

commit 386edc02b54abd42f4a159071ebb5c0eb7af3630
Author: Chia-liang Kao <clkao at bestpractical.com>
Date:   Fri Jun 3 16:53:41 2011 +0800

    lift delete action during update cf

diff --git a/lib/RT/Interface/Web.pm b/lib/RT/Interface/Web.pm
index 18588d0..cd88fb7 100644
--- a/lib/RT/Interface/Web.pm
+++ b/lib/RT/Interface/Web.pm
@@ -2237,6 +2237,26 @@ sub _ProcessObjectCustomFieldUpdates {
     };
 
     my @results;
+
+    if (my $arg = delete $args{'ARGS'}{'DeleteValues'}) {
+        foreach my $value ($_arg_values->($arg)) {
+            my ( $val, $msg ) = $args{'Object'}->DeleteCustomFieldValue(
+                Field => $cf,
+                Value => $value,
+            );
+            push( @results, $msg );
+        }
+    }
+    if (my $arg = delete $args{'ARGS'}{'DeleteValueIds'}) {
+        foreach my $value ($_arg_values->($arg)) {
+            my ( $val, $msg ) = $args{'Object'}->DeleteCustomFieldValue(
+                Field   => $cf,
+                ValueId => $value,
+            );
+            push( @results, $msg );
+        }
+    }
+
     foreach my $arg ( keys %{ $args{'ARGS'} } ) {
 
         # skip category argument
@@ -2270,22 +2290,6 @@ sub _ProcessObjectCustomFieldUpdates {
             my $value_hash = _UploadedFile( $args{'Prefix'} . $arg ) or next;
             my ( $val, $msg ) = $args{'Object'}->AddCustomFieldValue( %$value_hash, Field => $cf, );
             push( @results, $msg );
-        } elsif ( $arg eq 'DeleteValues' ) {
-            foreach my $value (@values) {
-                my ( $val, $msg ) = $args{'Object'}->DeleteCustomFieldValue(
-                    Field => $cf,
-                    Value => $value,
-                );
-                push( @results, $msg );
-            }
-        } elsif ( $arg eq 'DeleteValueIds' ) {
-            foreach my $value (@values) {
-                my ( $val, $msg ) = $args{'Object'}->DeleteCustomFieldValue(
-                    Field   => $cf,
-                    ValueId => $value,
-                );
-                push( @results, $msg );
-            }
         } elsif ( $arg eq 'Values' && !$cf->Repeated ) {
             my $cf_values = $args{'Object'}->CustomFieldValues( $cf->id );
 

commit fb75c72b458286e4d272325140d55377865c1dfb
Author: Chia-liang Kao <clkao at bestpractical.com>
Date:   Fri Jun 3 16:54:10 2011 +0800

    hook cf type class into cf update in Interface::Web.

diff --git a/lib/RT/Interface/Web.pm b/lib/RT/Interface/Web.pm
index cd88fb7..39e0031 100644
--- a/lib/RT/Interface/Web.pm
+++ b/lib/RT/Interface/Web.pm
@@ -2257,6 +2257,21 @@ sub _ProcessObjectCustomFieldUpdates {
         }
     }
 
+    my $class = $cf->GetTypeClass;
+
+    if ($class && $class->can('CreateArgsFromWebArgs')) {
+        my $args = $class->CreateArgsFromWebArgs($cf, $args{'ARGS'});
+        if ($args) {
+            my ( $val, $msg ) = $args{'Object'}->AddCustomFieldValue(
+                Field => $cf->id,
+                %$args,
+            );
+            push( @results, $msg );
+        }
+        return @results;
+    }
+
+
     foreach my $arg ( keys %{ $args{'ARGS'} } ) {
 
         # skip category argument
diff --git a/t/customfields/image_caption.t b/t/customfields/image_caption.t
index 9a7d765..3d01ac0 100644
--- a/t/customfields/image_caption.t
+++ b/t/customfields/image_caption.t
@@ -3,7 +3,7 @@
 use strict;
 use warnings;
 
-use RT::Test tests => 26;
+use RT::Test tests => 33;
 
 my ($baseurl, $agent) =RT::Test->started_ok;
 ok( $agent->login, 'log in' );
@@ -91,7 +91,7 @@ diag "create a ticket via web and set image with catpion" if $ENV{'TEST_VERBOSE'
 
 
 
-
+my $last_id;
 diag "create a ticket via web and leave the image empty" if $ENV{'TEST_VERBOSE'};
 {
     ok $agent->goto_create_ticket($q), "go to create ticket";
@@ -109,6 +109,33 @@ diag "create a ticket via web and leave the image empty" if $ENV{'TEST_VERBOSE'}
     my $ticket = RT::Ticket->new($RT::SystemUser);
     $ticket->Load($id);
     ok( $ticket->id, 'loaded ticket' );
+    $last_id = $id;
 }
 
 
+
+diag "go to last ticket and create the image with caption cf" if $ENV{'TEST_VERBOSE'};
+{
+    my $id = $last_id;
+    diag $id;
+    ok $agent->goto_ticket($id), "go to last ticket";
+    $agent->follow_link_ok( { text => 'Basics' });
+    $agent->content_like( qr/test without img/, "found ticket" );
+
+    my $cf_field = "Object-RT::Ticket-$id-CustomField-$cf_id";
+    $agent->submit_form_ok( {
+        form_name => 'TicketModify',
+        fields    => {
+            id => $id, # XXX: why is this needed? shouldn't mechanize keeps the value of the hidden fields?
+            "$cf_field-Upload" => 'share/html/NoAuth/images/bpslogo.png',
+            "$cf_field-Value" => 'Foo image',
+        } });
+
+    $agent->content_like( qr/Foo image/, "image caption on the page" );
+    my $ticket = RT::Ticket->new($RT::SystemUser);
+    $ticket->Load($id);
+    ok( $ticket->id, 'loaded ticket' );
+    is( $ticket->FirstCustomFieldValue('ImgOne'), 'Foo image',
+        'correct value' );
+
+}

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


More information about the Rt-commit mailing list