[Rt-commit] rt branch, 4.4/serialize-json-initialdata, updated. rt-4.4.1-399-geff1ba9

Shawn Moore shawn at bestpractical.com
Wed Mar 22 13:31:10 EDT 2017


The branch, 4.4/serialize-json-initialdata has been updated
       via  eff1ba9470453bfc2348c07118c7a2c7c78c97d1 (commit)
       via  0f8ec38304710ded783402f6a0f6f1dd65694f89 (commit)
       via  1c486f0bdb35b30d4010ca02464377a60395d2bf (commit)
       via  0ac6c0e026527b9e0f1a5ec5434619d93d34f3e1 (commit)
      from  2d5fa70aa607dede9898e5548cf471fa78e3dd03 (commit)

Summary of changes:
 lib/RT/Migrate/Serializer.pm      | 14 +++++-
 lib/RT/Migrate/Serializer/JSON.pm |  1 -
 sbin/rt-serializer.in             | 16 +++++--
 t/api/initialdata-roundtrip.t     | 95 ++++++++++++++++++++++++++++++---------
 4 files changed, 98 insertions(+), 28 deletions(-)

- Log -----------------------------------------------------------------
commit 0ac6c0e026527b9e0f1a5ec5434619d93d34f3e1
Author: Shawn M Moore <shawn at bestpractical.com>
Date:   Wed Mar 22 17:21:55 2017 +0000

    Several improvements to test infrastructure
    
    Pass a flag indicating whether data was loaded from initialdata
    Factor out a slurp function
    Allow individual tests to pass additional export flags

diff --git a/t/api/initialdata-roundtrip.t b/t/api/initialdata-roundtrip.t
index ef4e889..28200dc 100644
--- a/t/api/initialdata-roundtrip.t
+++ b/t/api/initialdata-roundtrip.t
@@ -1,6 +1,7 @@
 use utf8;
 use strict;
 use warnings;
+use JSON;
 
 use RT::Test tests => undef, config => << 'CONFIG';
 Plugin('RT::Extension::Initialdata::JSON');
@@ -705,43 +706,37 @@ for my $test (@tests) {
         goto &$warn;
     };
 
-    my $name    = delete $test->{name};
-    my $create  = delete $test->{create};
-    my $absent  = delete $test->{absent};
-    my $present = delete $test->{present};
-    my $raw     = delete $test->{raw};
+    my $name        = delete $test->{name};
+    my $create      = delete $test->{create};
+    my $absent      = delete $test->{absent};
+    my $present     = delete $test->{present};
+    my $raw         = delete $test->{raw};
+    my $export_args = delete $test->{export_args};
     fail("Unexpected keys for test #$id ($name): " . join(', ', sort keys %$test)) if keys %$test;
 
     subtest "$name (ordinary creation)" => sub {
         autorollback(sub {
-            $absent->() if $absent;
+            $absent->(0) if $absent;
             $create->();
-            $present->() if $present;
-            export_initialdata($directory);
+            $present->(0) if $present;
+            export_initialdata($directory, %{ $export_args || {} });
         });
     };
 
     if ($raw) {
         subtest "$name (testing initialdata)" => sub {
             my $file = File::Spec->catfile($directory, "initialdata.json");
-            my $content = do {
-                local $/;
-                open (my $f, '<:encoding(UTF-8)', $file)
-                    or die "Cannot open initialdata file '$file' for read: $@";
-                <$f>;
-            };
-            require JSON;
+            my $content = slurp($file);
             my $json = JSON->new->decode($content);
-
             $raw->($json, $content);
         };
     }
 
     subtest "$name (from export-$id/initialdata.json)" => sub {
         autorollback(sub {
-            $absent->() if $absent;
+            $absent->(1) if $absent;
             import_initialdata($directory);
-            $present->() if $present;
+            $present->(1) if $present;
         });
     };
 }
@@ -769,6 +764,7 @@ sub autorollback {
 
 sub export_initialdata {
     my $directory = shift;
+    my %args      = @_;
     local @RT::Record::ISA = qw( DBIx::SearchBuilder::Record RT::Base );
 
     use RT::Migrate::Serializer::JSON;
@@ -781,6 +777,8 @@ sub export_initialdata {
         FollowTransactions => 0,
         FollowTickets      => 0,
         FollowAssets       => 0,
+        FollowDisabled     => 0,
+        %args,
     );
 
     $migrator->Export;
@@ -797,3 +795,11 @@ sub import_initialdata {
         or diag "Error: $msg";
 }
 
+sub slurp {
+    my $file = shift;
+    local $/;
+    open (my $f, '<:encoding(UTF-8)', $file)
+        or die "Cannot open initialdata file '$file' for read: $@";
+    return scalar <$f>;
+}
+

commit 1c486f0bdb35b30d4010ca02464377a60395d2bf
Author: Shawn M Moore <shawn at bestpractical.com>
Date:   Wed Mar 22 17:22:48 2017 +0000

    Fix article tests

diff --git a/t/api/initialdata-roundtrip.t b/t/api/initialdata-roundtrip.t
index 28200dc..8627500 100644
--- a/t/api/initialdata-roundtrip.t
+++ b/t/api/initialdata-roundtrip.t
@@ -672,9 +672,9 @@ my @tests = (
             is($coffee->CustomFieldValuesAsString('Tags', Separator => '.'), 'drink.coffee.how the humans live', 'Tags CF');
 
             my $twd = RT::Article->new(RT->SystemUser);
-            $twd->LoadByCols(Name => 'Coffee time');
+            $twd->LoadByCols(Name => 'Total world domination plans');
             ok($twd->Id, 'loaded article');
-            is($twd->Name, 'Coffee time', 'Name');
+            is($twd->Name, 'Total world domination plans', 'Name');
             is($twd->Class, $class->Id, 'Class');
             is($twd->FirstCustomFieldValue('Content'), 'REDACTED', 'Content CF');
             is($twd->FirstCustomFieldValue('Clearance'), 'Top Secret', 'Clearance CF');

commit 0f8ec38304710ded783402f6a0f6f1dd65694f89
Author: Shawn M Moore <shawn at bestpractical.com>
Date:   Wed Mar 22 16:55:40 2017 +0000

    Add a --no-disabled flag to serializer

diff --git a/lib/RT/Migrate/Serializer.pm b/lib/RT/Migrate/Serializer.pm
index 6330b48..ecab02b 100644
--- a/lib/RT/Migrate/Serializer.pm
+++ b/lib/RT/Migrate/Serializer.pm
@@ -65,6 +65,7 @@ sub Init {
         AllUsers            => 1,
         AllGroups           => 1,
         FollowDeleted       => 1,
+        FollowDisabled      => 1,
 
         FollowScrips        => 0,
         FollowTickets       => 1,
@@ -86,6 +87,7 @@ sub Init {
                   AllUsers
                   AllGroups
                   FollowDeleted
+                  FollowDisabled
                   FollowScrips
                   FollowTickets
                   FollowTransactions
@@ -189,7 +191,7 @@ sub PushCollections {
 
         $class->require or next;
         my $collection = $class->new( RT->SystemUser );
-        $collection->FindAllRows;   # be explicit
+        $collection->FindAllRows if $self->{FollowDisabled};
         $collection->CleanSlate;    # some collections (like groups and users) join in _Init
         $collection->UnLimit;
         $collection->OrderBy( FIELD => 'id' );
@@ -374,6 +376,15 @@ sub Process {
         return $self->Visit(%args);
     }
 
+    if (!$self->{FollowDisabled}) {
+        return if ($obj->can('Disabled') || $obj->_Accessible('Disabled', 'read'))
+               && $obj->Disabled
+
+               # Disabled for OCFV means "old value" which we want to keep
+               # in the history
+               && !$obj->isa('RT::ObjectCustomFieldValue');
+    }
+
     return $self->SUPER::Process( @_ );
 }
 
@@ -398,6 +409,7 @@ sub Observe {
 
     my $obj = $args{object};
     my $from = $args{from};
+
     if ($obj->isa("RT::Ticket")) {
         return 0 if $obj->Status eq "deleted" and not $self->{FollowDeleted};
         return $self->{FollowTickets};
diff --git a/sbin/rt-serializer.in b/sbin/rt-serializer.in
index d130b45..2448c9d 100644
--- a/sbin/rt-serializer.in
+++ b/sbin/rt-serializer.in
@@ -100,6 +100,7 @@ GetOptions(
 
     "users!",
     "groups!",
+    "disabled!",
     "deleted!",
 
     "scrips!",
@@ -122,9 +123,10 @@ $args{Directory}   = $OPT{directory};
 $args{Force}       = $OPT{force};
 $args{MaxFileSize} = $OPT{size} if $OPT{size};
 
-$args{AllUsers}      = $OPT{users}    if defined $OPT{users};
-$args{AllGroups}     = $OPT{groups}   if defined $OPT{groups};
-$args{FollowDeleted} = $OPT{deleted}  if defined $OPT{deleted};
+$args{AllUsers}       = $OPT{users}    if defined $OPT{users};
+$args{AllGroups}      = $OPT{groups}   if defined $OPT{groups};
+$args{FollowDeleted}  = $OPT{deleted}  if defined $OPT{deleted};
+$args{FollowDisabled} = $OPT{disabled} if defined $OPT{disabled};
 
 $args{FollowScrips}       = $OPT{scrips}       if defined $OPT{scrips};
 $args{FollowTickets}      = $OPT{tickets}      if defined $OPT{tickets};
@@ -139,7 +141,7 @@ $args{GC}   = defined $OPT{gc}   ? $OPT{gc}   : 5000;
 $args{Page} = defined $OPT{page} ? $OPT{page} : 100;
 
 if (($OPT{clone} or $OPT{incremental})
-        and grep { /^(users|groups|deleted|scrips|tickets|transactions|acls|assets)$/ } keys %OPT) {
+        and grep { /^(users|groups|deleted|disabled|scrips|tickets|transactions|acls|assets)$/ } keys %OPT) {
     die "You cannot specify object types when cloning.\n\nPlease see $0 --help.\n";
 }
 
@@ -324,6 +326,12 @@ consistency.
 By default, all assets are serialized; passing C<--no-assets> skips
 assets during serialization.
 
+=item B<--no-disabled>
+
+By default, all queues, custom fields, etc, including disabled ones, are
+serialized; passing C<--no-disabled> skips such disabled records during
+serialization.
+
 =item B<--no-deleted>
 
 By default, all tickets and assets, including deleted ones, are
diff --git a/t/api/initialdata-roundtrip.t b/t/api/initialdata-roundtrip.t
index 8627500..4db90b7 100644
--- a/t/api/initialdata-roundtrip.t
+++ b/t/api/initialdata-roundtrip.t
@@ -327,7 +327,8 @@ my @tests = (
     },
 
     {
-        name => 'Scrips',
+        name => 'Scrips including Disabled',
+        export_args => { FollowDisabled => 1 },
         create => sub {
             my $bugs = RT::Queue->new(RT->SystemUser);
             my ($ok, $msg) = $bugs->Create(Name => 'Bugs');
@@ -349,7 +350,8 @@ my @tests = (
                 CustomCommitCode => 'return "commit"',
             );
             ok($ok, $msg);
-            $disabled->SetDisabled(1);
+            ($ok, $msg) = $disabled->SetDisabled(1);
+            ok($ok, $msg);
 
             my $stages = RT::Scrip->new(RT->SystemUser);
             ($ok, $msg) = $stages->Create(
@@ -423,6 +425,49 @@ my @tests = (
     },
 
     {
+        name => 'No disabled scrips',
+        create => sub {
+            my $disabled = RT::Scrip->new(RT->SystemUser);
+            my ($ok, $msg) = $disabled->Create(
+                Description => 'Disabled Scrip',
+                Template => 'Transaction',
+                ScripCondition => 'On Create',
+                ScripAction => 'Notify Owner',
+            );
+            ok($ok, $msg);
+            ($ok, $msg) = $disabled->SetDisabled(1);
+            ok($ok, $msg);
+
+            my $enabled = RT::Scrip->new(RT->SystemUser);
+            ($ok, $msg) = $enabled->Create(
+                Description => 'Enabled Scrip',
+                Template => 'Transaction',
+                ScripCondition => 'On Create',
+                ScripAction => 'Notify Owner',
+            );
+            ok($ok, $msg);
+        },
+        present => sub {
+            my $from_initialdata = shift;
+
+            my $disabled = RT::Scrip->new(RT->SystemUser);
+            $disabled->LoadByCols(Description => 'Disabled Scrip');
+
+            if ($from_initialdata) {
+                ok(!$disabled->Id, 'Disabled scrip absent in initialdata');
+            }
+            else {
+                ok($disabled->Id, 'Disabled scrip present because of the original creation');
+                ok($disabled->Disabled, 'Disabled scrip disabled');
+            }
+
+            my $enabled = RT::Scrip->new(RT->SystemUser);
+            $enabled->LoadByCols(Description => 'Enabled Scrip');
+            ok($enabled->Id, 'Enabled scrip present');
+        },
+    },
+
+    {
         name => 'Unapplied Objects',
         create => sub {
             my $scrip = RT::Scrip->new(RT->SystemUser);

commit eff1ba9470453bfc2348c07118c7a2c7c78c97d1
Author: Shawn M Moore <shawn at bestpractical.com>
Date:   Wed Mar 22 17:30:55 2017 +0000

    No need to push all assets
    
    We don't have this for tickets

diff --git a/lib/RT/Migrate/Serializer/JSON.pm b/lib/RT/Migrate/Serializer/JSON.pm
index 40468cc..6bf297b 100644
--- a/lib/RT/Migrate/Serializer/JSON.pm
+++ b/lib/RT/Migrate/Serializer/JSON.pm
@@ -145,7 +145,6 @@ sub PushBasics {
     # we want to include all CFs, scrips, etc, not just the reachable ones
     $self->PushCollections(qw(CustomFields CustomRoles));
     $self->PushCollections(qw(Scrips)) if $self->{FollowScrips};
-    $self->PushCollections(qw(Assets)) if $self->{FollowAssets};
 }
 
 sub JSON {

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


More information about the rt-commit mailing list