[Rt-commit] rt branch 5.0/fix-clear-mason-cache updated. rt-5.0.2-28-ge771b59eb0

BPS Git Server git at git.bestpractical.com
Mon Dec 27 19:50:57 UTC 2021


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "rt".

The branch, 5.0/fix-clear-mason-cache has been updated
       via  e771b59eb009a3b94869e2e7cedf752633ba0d30 (commit)
      from  3daeae3dd3f1bce12d3c48b2589a6957b40b7cce (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit e771b59eb009a3b94869e2e7cedf752633ba0d30
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Tue Dec 28 03:26:17 2021 +0800

    Test "Clear Mason Cache" functionality

diff --git a/t/web/mason-cache.t b/t/web/mason-cache.t
new file mode 100644
index 0000000000..1a3ba10c48
--- /dev/null
+++ b/t/web/mason-cache.t
@@ -0,0 +1,98 @@
+use strict;
+use warnings;
+
+use RT::Test tests => undef, config => 'Set($DevelMode, 0);';
+use JSON;
+use File::Temp;
+use File::Path 'make_path';
+use File::Spec;
+my $dir            = File::Temp::tempdir( CLEANUP => 1 );
+my $column_map_dir = File::Spec->catdir( $dir, qw/Callbacks MasonCache Elements RT__Ticket ColumnMap/ );
+make_path($column_map_dir);
+
+my $once  = File::Spec->catfile( $column_map_dir, 'Once' );
+my $hello = File::Spec->catfile( $dir, 'Hello.html' );
+
+update_mason( $once, <<'EOF' );
+<%INIT>
+$ARGS{COLUMN_MAP}{IDAndSubject} = {
+    title => 'ID-Subject',
+    value => sub { join '-', $_[0]->id, $_[0]->Subject },
+};
+</%INIT>
+EOF
+
+update_mason( $hello, 'Hello world!' );
+
+$RT::MasonLocalComponentRoot = $dir;
+
+my ( $baseurl, $m ) = RT::Test->started_ok;
+my $ticket = RT::Test->create_ticket( Queue => 'General', Subject => 'test mason cache' );
+
+$m->login;
+
+sleep 1;    # Cache updates at most once per second.
+$m->post_ok('/Admin/Helpers/ClearMasonCache');
+is_deeply( from_json( $m->content ), { status => 1, message => 'Cache cleared' }, 'Cache cleared' );
+
+# Test multiple times to make sure once callback always takes effect.
+for ( 1 .. 3 ) {
+    $m->get_ok('/Search/Results.html?Query=id>0&Format=__IDAndSubject__');
+    $m->text_contains( 'ID-Subject',                               'Column title' );
+    $m->text_contains( join( '-', $ticket->id, $ticket->Subject ), 'Column value' );
+}
+
+$m->get_ok('/Hello.html');
+$m->text_contains('Hello world!', 'Mason content' );
+
+update_mason( $once, <<'EOF' );
+<%INIT>
+$ARGS{COLUMN_MAP}{SubjectAndID} = {
+    title => 'Subject-ID',
+    value => sub { join '-', $_[0]->Subject, $_[0]->id },
+};
+</%INIT>
+EOF
+
+update_mason( $hello, 'Howdy world!' );
+
+# Test multiple times to make sure once callback always takes effect.
+for ( 1 .. 3 ) {
+    $m->get_ok('/Search/Results.html?Query=id>0&Format=__IDAndSubject__');
+    $m->text_contains( 'ID-Subject',                               'Old Column title is still valid' );
+    $m->text_contains( join( '-', $ticket->id, $ticket->Subject ), 'Old Column value is still valid' );
+
+    $m->get_ok('/Search/Results.html?Query=id>0&Format=__SubjectAndID__');
+    $m->text_lacks( 'Subject-ID',                               'New Column title is not yet' );
+    $m->text_lacks( join( '-', $ticket->Subject, $ticket->id ), 'New Column value is not yet' );
+}
+$m->get_ok('/Hello.html');
+$m->text_contains('Hello world!', 'Old mason content' );
+
+sleep 1;    # Cache updates at most once per second.
+$m->post_ok('/Admin/Helpers/ClearMasonCache');
+is_deeply( from_json( $m->content ), { status => 1, message => 'Cache cleared' }, 'Cache cleared' );
+
+# Test multiple times to make sure once callback always takes effect.
+for ( 1 .. 3 ) {
+    $m->get_ok('/Search/Results.html?Query=id>0&Format=__IDAndSubject__');
+    $m->text_lacks( 'ID-Subject',                               'Old Column title is gone' );
+    $m->text_lacks( join( '-', $ticket->id, $ticket->Subject ), 'Old Column value is gone' );
+
+    $m->get_ok('/Search/Results.html?Query=id>0&Format=__SubjectAndID__');
+    $m->text_contains( 'Subject-ID',                               'New Column title is valid' );
+    $m->text_contains( join( '-', $ticket->Subject, $ticket->id ), 'New Column value is valid' );
+}
+
+$m->get_ok('/Hello.html');
+$m->text_contains('Howdy world!', 'New mason content' );
+
+done_testing();
+
+sub update_mason {
+    my $path    = shift;
+    my $content = shift;
+    open my $fh, '>', $path or die $!;
+    print $fh $content;
+    close $fh;
+}

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

Summary of changes:
 t/web/mason-cache.t | 98 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 98 insertions(+)
 create mode 100644 t/web/mason-cache.t


hooks/post-receive
-- 
rt


More information about the rt-commit mailing list