[Rt-commit] r19302 - in rt/3.8/trunk: . t/api

alexmv at bestpractical.com alexmv at bestpractical.com
Mon Apr 20 13:11:24 EDT 2009


Author: alexmv
Date: Mon Apr 20 13:11:24 2009
New Revision: 19302

Modified:
   rt/3.8/trunk/   (props changed)
   rt/3.8/trunk/lib/RT/CustomField_Overlay.pm
   rt/3.8/trunk/t/api/cf.t

Log:
 r44409 at kohr-ah:  chmrr | 2009-04-20 12:55:09 -0400
 Prefer non-disabled CFs when loading by name


Modified: rt/3.8/trunk/lib/RT/CustomField_Overlay.pm
==============================================================================
--- rt/3.8/trunk/lib/RT/CustomField_Overlay.pm	(original)
+++ rt/3.8/trunk/lib/RT/CustomField_Overlay.pm	Mon Apr 20 13:11:24 2009
@@ -331,8 +331,12 @@
         $CFs->LimitToQueue( $args{'Queue'} );
     }
 
-    # When loading by name, it's ok if they're disabled. That's not a big deal.
+    # When loading by name, we _can_ load disabled fields, but prefer
+    # non-disabled fields.
     $CFs->{'find_disabled_rows'}=1;
+    $CFs->OrderByCols(
+        { FIELD => "Disabled", ORDER => 'ASC' },
+    );
 
     # We only want one entry.
     $CFs->RowsPerPage(1);

Modified: rt/3.8/trunk/t/api/cf.t
==============================================================================
--- rt/3.8/trunk/t/api/cf.t	(original)
+++ rt/3.8/trunk/t/api/cf.t	Mon Apr 20 13:11:24 2009
@@ -2,7 +2,7 @@
 
 use strict;
 use warnings FATAL => 'all';
-use Test::More tests => 133;
+use Test::More tests => 139;
 
 use RT::Test;
 
@@ -191,6 +191,29 @@
 is( $cfvs->Count, 0, "No custom field values for non-Queue cf" );
 is( $ticket->FirstCustomFieldValue( 'RecordCustomFields4' ), undef, "No first custom field value for non-Queue cf" );
 
+{
+    my $cfname = $global_cf3->Name;
+    ($status, $msg) = $global_cf3->SetDisabled(1);
+    ok($status, "Disabled CF named $cfname");
+
+    my $load = RT::CustomField->new( $RT::SystemUser );
+    $load->LoadByName( Name => $cfname);
+    ok($load->Id, "Loaded CF named $cfname");
+    is($load->Id, $global_cf3->Id, "Can load disabled CFs");
+
+    my $dup = RT::CustomField->new( $RT::SystemUser );
+    $dup->Create( Name => $cfname, Type => 'SelectSingle', Queue => 0 );
+    ok($dup->Id, "Created CF with duplicate name");
+
+    $load->LoadByName( Name => $cfname);
+    is($load->Id, $dup->Id, "Loading by name gets non-disabled first");
+
+    $dup->SetDisabled(1);
+    $global_cf3->SetDisabled(0);
+
+    $load->LoadByName( Name => $cfname);
+    is($load->Id, $global_cf3->Id, "Loading by name gets non-disabled first, even with order swapped");
+}
 
 #SKIP: {
 #	skip "TODO: should we add CF values to objects via CF Name?", 48;


More information about the Rt-commit mailing list