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

Shawn Moore shawn at bestpractical.com
Tue Mar 21 16:54:46 EDT 2017


The branch, 4.4/serialize-json-initialdata has been updated
       via  ae258629a93010f8f057185684878e01b76d605f (commit)
       via  e5cf813dbc627ec5a7041d045c0748bba4f5cc2e (commit)
      from  59515a18a0a35dce12fe638c958dd6fb06e4a67a (commit)

Summary of changes:
 lib/RT/Handle.pm              |  2 +-
 t/api/initialdata-roundtrip.t | 44 +++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 45 insertions(+), 1 deletion(-)

- Log -----------------------------------------------------------------
commit e5cf813dbc627ec5a7041d045c0748bba4f5cc2e
Author: Shawn M Moore <shawn at bestpractical.com>
Date:   Tue Mar 21 20:36:07 2017 +0000

    Tests for templates and their overrides

diff --git a/lib/RT/Migrate/Serializer/JSON.pm b/lib/RT/Migrate/Serializer/JSON.pm
index e921a9f..f7eee83 100644
--- a/lib/RT/Migrate/Serializer/JSON.pm
+++ b/lib/RT/Migrate/Serializer/JSON.pm
@@ -150,7 +150,7 @@ sub PushBasics {
 
 sub JSON {
     my $self = shift;
-    return $self->{JSON} ||= JSON->new->pretty->canonical;
+    return $self->{JSON} ||= JSON->new->pretty->canonical->utf8;
 }
 
 sub OpenFile {
diff --git a/t/api/initialdata-roundtrip.t b/t/api/initialdata-roundtrip.t
index 0c9ed5c..c305e45 100644
--- a/t/api/initialdata-roundtrip.t
+++ b/t/api/initialdata-roundtrip.t
@@ -1,5 +1,7 @@
+use utf8;
 use strict;
 use warnings;
+use Encode 'encode_utf8';
 
 use RT::Test tests => undef, config => << 'CONFIG';
 Plugin('RT::Extension::Initialdata::JSON');
@@ -548,6 +550,49 @@ my @tests = (
             ok(!$class->IsApplied($general->Id), 'not applied to General queue');
         },
     },
+    {
+        name => 'Templates',
+        create => sub {
+            my $global = RT::Template->new(RT->SystemUser);
+            my ($ok, $msg) = $global->Create(
+                Name => 'Initialdata test',
+                Queue => 0,
+                Description => 'foo',
+                Content => encode_utf8("Hello こんにちは"),
+                Type => "Simple",
+            );
+            ok($ok, $msg);
+
+            my $queue = RT::Template->new(RT->SystemUser);
+            ($ok, $msg) = $queue->Create(
+                Name => 'Initialdata test',
+                Queue => $general->Id,
+                Description => 'override for Swedes',
+                Content => encode_utf8("Hello Hallå"),
+                Type => "Simple",
+            );
+            ok($ok, $msg);
+        },
+        present => sub {
+            my $global = RT::Template->new(RT->SystemUser);
+            $global->LoadGlobalTemplate('Initialdata test');
+            ok($global->Id, 'loaded template');
+            is($global->Name, 'Initialdata test', 'Name');
+            is($global->Queue, 0, 'Queue');
+            is($global->Description, 'foo', 'Description');
+            is($global->Content, 'Hello こんにちは', 'Content');
+            is($global->Type, 'Simple', 'Type');
+
+            my $queue = RT::Template->new(RT->SystemUser);
+            $queue->LoadQueueTemplate(Name => 'Initialdata test', Queue => $general->Id);
+            ok($queue->Id, 'loaded template');
+            is($queue->Name, 'Initialdata test', 'Name');
+            is($queue->Queue, $general->Id, 'Queue');
+            is($queue->Description, 'override for Swedes', 'Description');
+            is($queue->Content, 'Hello Hallå', 'Content');
+            is($queue->Type, 'Simple', 'Type');
+        },
+    },
 );
 
 my $id = 0;

commit ae258629a93010f8f057185684878e01b76d605f
Author: Shawn M Moore <shawn at bestpractical.com>
Date:   Tue Mar 21 20:49:20 2017 +0000

    Clean up JSON encoding
    
    Loading the JSON file with :encoding(UTF-8) means we pass wide Unicode
    chars to the JSON.pm loader, which it doesn't like:
        "simple and fast interfaces (expect/generate UTF-8)"
    
    So, avoid decoding UTF8

diff --git a/lib/RT/Handle.pm b/lib/RT/Handle.pm
index 0ac4ef6..680409b 100644
--- a/lib/RT/Handle.pm
+++ b/lib/RT/Handle.pm
@@ -864,7 +864,7 @@ sub InsertData {
 
     my $datafile_content = do {
         local $/;
-        open (my $f, '<:encoding(UTF-8)', $datafile)
+        open (my $f, '<', $datafile)
             or die "Cannot open initialdata file '$datafile' for read: $@";
         <$f>;
     };
diff --git a/lib/RT/Migrate/Serializer/JSON.pm b/lib/RT/Migrate/Serializer/JSON.pm
index f7eee83..e921a9f 100644
--- a/lib/RT/Migrate/Serializer/JSON.pm
+++ b/lib/RT/Migrate/Serializer/JSON.pm
@@ -150,7 +150,7 @@ sub PushBasics {
 
 sub JSON {
     my $self = shift;
-    return $self->{JSON} ||= JSON->new->pretty->canonical->utf8;
+    return $self->{JSON} ||= JSON->new->pretty->canonical;
 }
 
 sub OpenFile {
diff --git a/t/api/initialdata-roundtrip.t b/t/api/initialdata-roundtrip.t
index c305e45..869fc22 100644
--- a/t/api/initialdata-roundtrip.t
+++ b/t/api/initialdata-roundtrip.t
@@ -1,7 +1,6 @@
 use utf8;
 use strict;
 use warnings;
-use Encode 'encode_utf8';
 
 use RT::Test tests => undef, config => << 'CONFIG';
 Plugin('RT::Extension::Initialdata::JSON');
@@ -558,7 +557,7 @@ my @tests = (
                 Name => 'Initialdata test',
                 Queue => 0,
                 Description => 'foo',
-                Content => encode_utf8("Hello こんにちは"),
+                Content => "Hello こんにちは",
                 Type => "Simple",
             );
             ok($ok, $msg);
@@ -568,7 +567,7 @@ my @tests = (
                 Name => 'Initialdata test',
                 Queue => $general->Id,
                 Description => 'override for Swedes',
-                Content => encode_utf8("Hello Hallå"),
+                Content => "Hello Hallå",
                 Type => "Simple",
             );
             ok($ok, $msg);

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


More information about the rt-commit mailing list