[Rt-commit] rt branch, 4.0/column-map-validation, created. rt-4.0.13-64-g24c0aeb

Todd Wade todd at bestpractical.com
Thu Aug 14 12:00:11 EDT 2014


The branch, 4.0/column-map-validation has been created
        at  24c0aeb968bdf7ab378985e1a9a2a4fdddc10542 (commit)

- Log -----------------------------------------------------------------
commit 8921e1d26d215064f2533d9b38818d7b1a460868
Author: Todd Wade <todd at bestpractical.com>
Date:   Thu Aug 14 11:51:12 2014 -0400

    A test to verify a database field has a corresponding ColumnMap entry
    
    Programmatically validate a table's ColumnMap entry is present. Also
    provides a blacklist for columns that do not need a ColumnMap entry.
    
    New database columns will either need to be blacklisted or get a
    ColumnMap entry before this test will pass.
    
    see [issues#22386]

diff --git a/t/web/column-map-validation.t b/t/web/column-map-validation.t
new file mode 100644
index 0000000..04e38ab
--- /dev/null
+++ b/t/web/column-map-validation.t
@@ -0,0 +1,143 @@
+use strict;
+use warnings;
+use utf8;
+
+use File::Find;
+
+use RT;
+use RT::Dashboard::Mailer;
+use Data::Dumper;
+
+RT->InitLogging;
+my $mason = RT::Dashboard::Mailer::_mason();
+
+use RT::Test tests => undef;
+
+my $blacklist = {
+    common   => [qw(
+        Creator
+        Created
+        LastUpdatedBy
+        LastUpdated
+    )],
+    Articles => [qw(
+        id
+        SortOrder
+        Parent
+    )],
+    Classes => [qw(
+        SortOrder
+        Disabled
+        HotList
+    )],
+    CustomFields => [qw(
+        Repeated
+        SortOrder
+    )],
+    Groups => [qw(
+        Domain
+        Type
+        Instance
+    )],
+    Queues => [qw(
+    )],
+    Scrips => [qw(
+        ScripCondition
+        ScripAction
+        ConditionRules
+        ActionRules
+        CustomIsApplicableCode
+        CustomPrepareCode
+        CustomCommitCode
+        Queue
+        Template
+    )],
+    Templates => [qw(
+        Queue
+        Type
+        Language
+        TranslationOf
+        Content
+    )],
+    Tickets => [qw(
+        id
+        IssueStatement
+        Resolution
+        Owner
+        Disabled
+    )],
+    Users => [qw(
+        Password
+        AuthToken
+        Comments
+        Signature
+        FreeformContactInfo
+        EmailEncoding
+        WebEncoding
+        ExternalContactInfoId
+        ContactInfoSystem
+        ExternalAuthId
+        AuthSystem
+        Timezone
+        PGPKey
+    )],
+};
+
+my ($base, $m) = RT::Test->started_ok;
+ok $m->login, 'logged in';
+
+my $docroot = join '/', qw(share html);
+
+# find endpoints to loop over
+my @endpoints;
+find({
+    wanted => sub {
+        if ( m|RT__| && m|ColumnMap$|  ) {
+            ( my $endpoint = $_ ) =~ s|^$docroot||;
+            push @endpoints, $endpoint;
+        }
+    },
+    no_chdir => 1,
+} => join '/', $docroot => 'Elements');
+
+foreach my $endpoint ( @endpoints ) {
+    # convert the file name in to a class name
+    (my $class = $endpoint) =~ s|.+/(RT__.+?)/.+|$1|;
+    $class =~ s|__|::|;
+    next unless $class->can('Table');
+
+    # get the name of the db table this class represents
+    my $table = $class->Table;
+
+    # get the columns for this table from the db
+    my $raw = $RT::Handle->dbh->selectall_arrayref("Describe $table;");
+    my @columns = map $_->[0], @$raw;
+
+    # columns for this table that don't get a ColumnMap entry
+    my %TableBlacklist = map { $_ => 1 }
+        @{ $blacklist->{$table} }, @{ $blacklist->{common} }
+    ;
+
+    foreach my $column ( @columns ) {
+        if ( ! $TableBlacklist{ $column } ) {
+            my $map = $mason->exec($endpoint, Name => $column, Attr => 'attribute');
+            ok( $map, sprintf "%s.%s has ColumnMap entry", $table, $column);
+        }
+    }
+}
+
+undef $m;
+done_testing;
+
+__DATA__
+
+#  print Data::Dumper::Dumper( \@columns ), "\n";
+  print $table, "\n";
+  foreach my $column ( @columns ) {
+    my $map = $mason->exec($endpoint, Name => $column, Attr => 'attribute');
+    if ($map) {
+      printf "\tColumn: %s\tAttribute: %s\n", $column, $map;
+    } else {
+      printf "\tColumn: %s\tMISSING ATTRIBUTE\n", $column;
+    }
+  }

commit 24c0aeb968bdf7ab378985e1a9a2a4fdddc10542
Author: Todd Wade <todd at bestpractical.com>
Date:   Thu Aug 14 11:58:01 2014 -0400

    Add ColumnMap entries for database columns that should have got them
    when the column was added to the database.
    
    see [issues#22386]

diff --git a/share/html/Elements/RT__Article/ColumnMap b/share/html/Elements/RT__Article/ColumnMap
index e900e19..118403d 100644
--- a/share/html/Elements/RT__Article/ColumnMap
+++ b/share/html/Elements/RT__Article/ColumnMap
@@ -70,6 +70,11 @@ $COLUMN_MAP = {
         title     => 'Class id',                   # loc
         value     => sub { $_[0]->Class },
     },
+    URI => {
+        attribute => 'URI',
+        title     => 'URI',                   # loc
+        value     => sub { $_[0]->URI },
+    },
     ClassName => {
         attribute => 'Class',
         title     => 'Class',                               # loc
diff --git a/share/html/Elements/RT__CustomField/ColumnMap b/share/html/Elements/RT__CustomField/ColumnMap
index 9df091d..2f4bb97 100644
--- a/share/html/Elements/RT__CustomField/ColumnMap
+++ b/share/html/Elements/RT__CustomField/ColumnMap
@@ -62,13 +62,17 @@ my $COLUMN_MAP = {
         attribute => 'Disabled',
         value     => sub { return $_[0]->Disabled? $_[0]->loc('Disabled'): $_[0]->loc('Enabled') },
     },
-
+    BasedOn => {
+        title     => 'Based On',
+        attribute => 'BasedOn',
+        value     => sub { return $_[0]->BasedOnObj->Name },
+    },
     map(
         { my $c = $_; $c => {
             title     => $c, attribute => $c,
 	    value     => sub { return $_[0]->$c() },
         } }
-        qw(Name Description Type LookupType Pattern)
+        qw(Name Description Type LookupType Pattern RenderType ValuesClass)
     ),
     map(
         { my $c = $_; my $short = $c; $short =~ s/^Friendly//;

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


More information about the rt-commit mailing list