[Rt-commit] rt branch, 4.0/allow-class-to-change-name-cases, created. rt-4.0.10-108-g61662a6

? sunnavy sunnavy at bestpractical.com
Sun Mar 17 10:51:34 EDT 2013


The branch, 4.0/allow-class-to-change-name-cases has been created
        at  61662a68e9bca84ef74c7a728368d8d35928e910 (commit)

- Log -----------------------------------------------------------------
commit 61662a68e9bca84ef74c7a728368d8d35928e910
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Sun Mar 17 22:32:59 2013 +0800

    allow class names to change their cases.
    
    we shall mark the new name valid if the duplicated class we found(which was
    loaded by name case-insensitively) is the same one that is going to change.
    
    an edge case to note: our old test used the same RT::Class object to try
    creating another duplicated class, which breaks new code. but this is very
    rare in real world and should be avoided.

diff --git a/lib/RT/Class.pm b/lib/RT/Class.pm
index 6e1db23..dfe8eb3 100644
--- a/lib/RT/Class.pm
+++ b/lib/RT/Class.pm
@@ -218,7 +218,7 @@ sub ValidateName {
     return undef unless ($newval);
     my $obj = RT::Class->new($RT::SystemUser);
     $obj->Load($newval);
-    return undef if ( $obj->Id );
+    return undef if $obj->id && ( !$self->id || $self->id != $obj->id );
     return $self->SUPER::ValidateName($newval);
 
 }
diff --git a/t/articles/class.t b/t/articles/class.t
index 39d5b56..7a7c015 100644
--- a/t/articles/class.t
+++ b/t/articles/class.t
@@ -2,7 +2,7 @@
 use strict;
 use warnings;
 
-use RT::Test tests => 24;
+use RT::Test tests => undef;
 
 use_ok 'RT::Articles';
 use_ok 'RT::Classes';
@@ -17,14 +17,21 @@ my ($id, $msg) = $cl->Create(Name => 'Test-'.$$, Description => 'A test class');
 
 ok ($id, $msg);
 
+ok( $cl->SetName( 'test-' . $$ ), 'rename to lower cased version' );
+ok( $cl->SetName( 'Test-' . $$ ), 'rename back' );
+
 # no duplicate class names should be allowed
-($id, $msg) = $cl->Create(Name => 'Test-'.$$, Description => 'A test class');
+($id, $msg) = RT::Class->new($root)->Create(Name => 'Test-'.$$, Description => 'A test class');
+
+ok (!$id, $msg);
+
+($id, $msg) = RT::Class->new($root)->Create(Name => 'test-'.$$, Description => 'A test class');
 
 ok (!$id, $msg);
 
 #class name should be required
 
-($id, $msg) = $cl->Create(Name => '', Description => 'A test class');
+($id, $msg) = RT::Class->new($root)->Create(Name => '', Description => 'A test class');
 
 ok (!$id, $msg);
 
@@ -73,3 +80,6 @@ $m->submit();
 $m->content_like(qr/Description changed from.*no value.*to .*Test Description/,'description changed');
 $m->form_number(3);
 is($m->current_form->find_input('Include-Name')->value,undef,'Disabled Including Names for this Class');
+
+undef $m;
+done_testing();

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


More information about the Rt-commit mailing list