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

Shawn Moore shawn at bestpractical.com
Tue Mar 21 12:35:52 EDT 2017


The branch, 4.4/serialize-json-initialdata has been updated
       via  41a9ab1d99a10d392d7f340ca3e536bccad464c6 (commit)
       via  dddaded6bda66dee610febd1396edc1fe298eaeb (commit)
      from  dad2ed48853b91fdc47e9e32aa9a17349862a041 (commit)

Summary of changes:
 lib/RT/Migrate/Serializer/JSON.pm |  3 --
 t/api/initialdata-roundtrip.t     | 66 +++++++++++++++++++++++++++++++++++++++
 2 files changed, 66 insertions(+), 3 deletions(-)

- Log -----------------------------------------------------------------
commit dddaded6bda66dee610febd1396edc1fe298eaeb
Author: Shawn M Moore <shawn at bestpractical.com>
Date:   Tue Mar 21 16:35:15 2017 +0000

    Add a way to test the raw initialdata JSON object itself

diff --git a/t/api/initialdata-roundtrip.t b/t/api/initialdata-roundtrip.t
index a39d6c8..be62e46 100644
--- a/t/api/initialdata-roundtrip.t
+++ b/t/api/initialdata-roundtrip.t
@@ -482,6 +482,7 @@ for my $test (@tests) {
     my $create  = delete $test->{create};
     my $absent  = delete $test->{absent};
     my $present = delete $test->{present};
+    my $raw     = delete $test->{raw};
     fail("Unexpected keys for test #$id ($name): " . join(', ', sort keys %$test)) if keys %$test;
 
     subtest "$name (ordinary creation)" => sub {
@@ -493,6 +494,22 @@ for my $test (@tests) {
         });
     };
 
+    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 $json = JSON->new->decode($content);
+
+            $raw->($json, $content);
+        };
+    }
+
     subtest "$name (from export-$id/initialdata.json)" => sub {
         autorollback(sub {
             $absent->() if $absent;

commit 41a9ab1d99a10d392d7f340ca3e536bccad464c6
Author: Shawn M Moore <shawn at bestpractical.com>
Date:   Tue Mar 21 16:35:35 2017 +0000

    Prove we don't need to rewrite LargeContent as Content

diff --git a/lib/RT/Migrate/Serializer/JSON.pm b/lib/RT/Migrate/Serializer/JSON.pm
index 5619372..6720a49 100644
--- a/lib/RT/Migrate/Serializer/JSON.pm
+++ b/lib/RT/Migrate/Serializer/JSON.pm
@@ -337,9 +337,6 @@ sub CanonicalizeObjectCustomFieldValues {
 
         delete @$record{qw/id Created Creator LastUpdated LastUpdatedBy/};
 
-        $record->{Content} = $record->{LargeContent} if $record->{LargeContent};
-        delete $record->{LargeContent};
-
         push @{ $object->{CustomFields} }, $record;
     }
 
diff --git a/t/api/initialdata-roundtrip.t b/t/api/initialdata-roundtrip.t
index be62e46..a072834 100644
--- a/t/api/initialdata-roundtrip.t
+++ b/t/api/initialdata-roundtrip.t
@@ -230,6 +230,55 @@ my @tests = (
     },
 
     {
+        name => 'Custom field LargeContent',
+        create => sub {
+            my $cf = RT::CustomField->new(RT->SystemUser);
+            my ($ok, $msg) = $cf->Create(
+                Name => "Group CF",
+                Type => "FreeformSingle",
+                LookupType => RT::Group->CustomFieldLookupType,
+            );
+            ok($ok, $msg);
+
+            ($ok, $msg) = $cf->AddToObject(RT::Group->new(RT->SystemUser));
+            ok($ok, $msg);
+
+            my $group = RT::Group->new(RT->SystemUser);
+            ($ok, $msg) = $group->CreateUserDefinedGroup(Name => 'Group');
+            ok($ok, $msg);
+
+            ($ok, $msg) = $group->AddCustomFieldValue(
+                Field => $cf->Id,
+                Value => scalar("abc" x 256),
+            );
+            ok($ok, $msg);
+        },
+        present => sub {
+            my $group = RT::Group->new(RT->SystemUser);
+            $group->LoadUserDefinedGroup('Group');
+            ok($group->Id, 'loaded Group');
+            is($group->FirstCustomFieldValue('Group CF'), scalar("abc" x 256), "CF LargeContent");
+        },
+	# the following test peers into the initialdata only to make sure that
+	# we are roundtripping LargeContent as expected; if this starts
+	# failing it's not necessarily a problem, but it's worthy of
+	# investigating whether the "present" tests are still testing
+	# what they were meant to test
+        raw => sub {
+            my $json = shift;
+            my ($group) = grep { $_->{Name} eq 'Group' } @{ $json->{Groups} };
+            ok($group, 'found the group');
+            my ($ocfv) = @{ $group->{CustomFields} };
+            ok($ocfv, 'found the OCFV');
+
+            is($ocfv->{CustomField}, 'Group CF', 'CustomField');
+            is($ocfv->{Content}, undef, 'no Content');
+            is($ocfv->{LargeContent}, scalar("abc" x 256), 'LargeContent');
+            is($ocfv->{ContentType}, "text/plain", 'ContentType');
+        }
+    },
+
+    {
         name => 'Scrips',
         create => sub {
             my $bugs = RT::Queue->new(RT->SystemUser);

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


More information about the rt-commit mailing list