[Rt-commit] rt branch, 4.0/plugin-overlays, created. rt-4.0.7-56-g8947f45

Thomas Sibley trs at bestpractical.com
Thu Aug 30 13:39:11 EDT 2012


The branch, 4.0/plugin-overlays has been created
        at  8947f45aad8918bb3be9ab72d063d01c632c2676 (commit)

- Log -----------------------------------------------------------------
commit 1d6c502bda49a93347084c03b6c79228f45eb91b
Author: Thomas Sibley <trs at bestpractical.com>
Date:   Thu Aug 30 10:08:45 2012 -0700

    Support testing-only plugins by looking under t/data/plugins
    
    Plugins written as part of the test suite can be enabled with:
    
        use RT::Test plugins => ["Foo"];
    
    provided t/data/plugins/Foo/ exists.

diff --git a/lib/RT/Test.pm b/lib/RT/Test.pm
index 3e7c910..c5ecf80 100644
--- a/lib/RT/Test.pm
+++ b/lib/RT/Test.pm
@@ -283,6 +283,7 @@ Set( \$RTAddressRegexp , qr/^bad_re_that_doesnt_match\$/i);
 
     if ( $args{'plugins'} ) {
         print $config "Set( \@Plugins, qw(". join( ' ', @{ $args{'plugins'} } ) .") );\n";
+        print $config qq[\$RT::PluginPath = "\$RT::BasePath/t/data/plugins";\n];
     }
 
     if ( $INC{'Devel/Cover.pm'} ) {

commit a030d7e38fb88242167f5a46d1840a4cbf3f4334
Author: Thomas Sibley <trs at bestpractical.com>
Date:   Thu Aug 30 10:20:56 2012 -0700

    Test plugin loading and lib overlays in plugins via rt-server
    
    Currently failing because RT::User is loaded too early.  Requires
    testing under apache because otherwise the RT init sequence in the test
    process (via RT::Test->import) interferes with rt-server in a way that
    causes it to pass.
    
    It is far too easy to break certain lib overlays when provided via
    plugins, so hopefully a simple test will help.

diff --git a/t/data/plugins/Overlays/html/overlay_loaded b/t/data/plugins/Overlays/html/overlay_loaded
new file mode 100644
index 0000000..eeeb032
--- /dev/null
+++ b/t/data/plugins/Overlays/html/overlay_loaded
@@ -0,0 +1,8 @@
+<%flags>
+inherit => undef    # avoid auth
+</%flags>
+<%init>
+$r->content_type("text/plain");
+$m->out( $RT::User::LOADED_OVERLAY ? "yes" : "no" );
+$m->abort(200);
+</%init>
diff --git a/t/data/plugins/Overlays/html/user_accessible b/t/data/plugins/Overlays/html/user_accessible
new file mode 100644
index 0000000..8eef2b4
--- /dev/null
+++ b/t/data/plugins/Overlays/html/user_accessible
@@ -0,0 +1,8 @@
+<%flags>
+inherit => undef    # avoid auth
+</%flags>
+<%init>
+$r->content_type("application/json");
+$m->out( JSON( RT::User->_ClassAccessible() ) );
+$m->abort(200);
+</%init>
diff --git a/t/data/plugins/Overlays/lib/Overlays.pm b/t/data/plugins/Overlays/lib/Overlays.pm
new file mode 100644
index 0000000..f18b458
--- /dev/null
+++ b/t/data/plugins/Overlays/lib/Overlays.pm
@@ -0,0 +1,2 @@
+package Overlays;
+1;
diff --git a/t/data/plugins/Overlays/lib/RT/User_Local.pm b/t/data/plugins/Overlays/lib/RT/User_Local.pm
new file mode 100644
index 0000000..312cc09
--- /dev/null
+++ b/t/data/plugins/Overlays/lib/RT/User_Local.pm
@@ -0,0 +1,11 @@
+package RT::User;
+use strict;
+use warnings;
+
+our $LOADED_OVERLAY = 1;
+
+sub _LocalAccessible {
+    { Comments => { public => 1 } }
+}
+
+1;
diff --git a/t/web/plugin-overlays.t b/t/web/plugin-overlays.t
new file mode 100644
index 0000000..fec4589
--- /dev/null
+++ b/t/web/plugin-overlays.t
@@ -0,0 +1,30 @@
+use strict;
+use warnings;
+
+BEGIN {
+    use Test::More;
+    plan skip_all => "Testing the rt-server init sequence in isolation requires Apache"
+        unless ($ENV{RT_TEST_WEB_HANDLER} || '') =~ /^apache/;
+}
+
+use JSON qw(from_json);
+
+use RT::Test
+    tests   => undef,
+    plugins => ["Overlays"];
+
+my ($base, $m) = RT::Test->started_ok;
+
+# Check that the overlay was actually loaded
+$m->get_ok("$base/overlay_loaded");
+is $m->content, "yes", "Plugin's RT/User_Local.pm was loaded";
+
+# Check accessible is correct and doesn't need to be rebuilt from overlay
+$m->get_ok("$base/user_accessible");
+ok $m->content, "Received some content";
+
+my $info = from_json($m->content) || {};
+ok $info->{Comments}{public}, "User.Comments is marked public via overlay";
+
+undef $m;
+done_testing;

commit 8947f45aad8918bb3be9ab72d063d01c632c2676
Author: Thomas Sibley <trs at bestpractical.com>
Date:   Wed Aug 29 17:05:54 2012 -0700

    Plugin paths MUST be in @INC before we do anything else when firing up the server
    
    Otherwise plugins can't reliably use lib overlay files (_Overlay,
    _Vendor, _Local) as the core classes won't be able to find those
    overlays at load time.
    
    Normally RT->Init() takes care of this early on, but we postpone calling
    Init() quite a bit, notably until after calling CheckIntegrity().  The
    CheckIntegrity() call ends up loading RT::User and other classes, which
    means they went looking for overlays before lib paths were setup.

diff --git a/sbin/rt-server.in b/sbin/rt-server.in
index f84f6c1..d72d16b 100755
--- a/sbin/rt-server.in
+++ b/sbin/rt-server.in
@@ -91,6 +91,7 @@ if (grep { m/help/ } @ARGV) {
 
 require RT;
 RT->LoadConfig();
+RT->InitPluginPaths();
 RT->InitLogging();
 require Module::Refresh if RT->Config->Get('DevelMode');
 

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


More information about the Rt-commit mailing list