Fix and test failure to merge include paths
Alastair McGowan-Douglas [Fri, 26 Sep 2014 14:25:35 +0000 (15:25 +0100)]
(Sorry about the copypasta)

25 files changed:
lib/Catalyst/Plugin/Static/Simple.pm
t/13no_include_path.t [new file with mode: 0644]
t/14deprecated.t [new file with mode: 0644]
t/lib/IncTestApp.pm [new file with mode: 0644]
t/lib/IncTestApp/Controller/Root.pm [new file with mode: 0644]
t/lib/IncTestApp/root/always-static/test [new file with mode: 0644]
t/lib/IncTestApp/root/always-static/test.html [new file with mode: 0644]
t/lib/IncTestApp/root/css/static.css [new file with mode: 0644]
t/lib/IncTestApp/root/files/bad.gif [new file with mode: 0644]
t/lib/IncTestApp/root/files/empty.txt [new file with mode: 0644]
t/lib/IncTestApp/root/files/err.omg [new file with mode: 0644]
t/lib/IncTestApp/root/files/space file.txt [new file with mode: 0644]
t/lib/IncTestApp/root/files/static.css [new file with mode: 0644]
t/lib/IncTestApp/root/ignored/bad.gif [new file with mode: 0644]
t/lib/IncTestApp/root/ignored/index.html [new file with mode: 0644]
t/lib/IncTestApp/root/ignored/static.css [new file with mode: 0644]
t/lib/IncTestApp/root/ignored/tmpl.tt [new file with mode: 0644]
t/lib/IncTestApp/root/images/bad.gif [new file with mode: 0644]
t/lib/IncTestApp/root/images/catalyst.png [new file with mode: 0644]
t/lib/IncTestApp/root/incpath/incpath.css [new file with mode: 0644]
t/lib/IncTestApp/root/overlay/o-ignored/bad.gif [new file with mode: 0644]
t/lib/IncTestApp/root/overlay/o-ignored/index.html [new file with mode: 0644]
t/lib/IncTestApp/root/overlay/o-ignored/static.css [new file with mode: 0644]
t/lib/IncTestApp/root/overlay/o-ignored/tmpl.tt [new file with mode: 0644]
t/lib/IncTestApp/root/overlay/overlay.jpg [new file with mode: 0644]

index 856b47c..d8ee9c3 100755 (executable)
@@ -101,6 +101,14 @@ before setup_finalize => sub {
 
     $c->log->warn("Deprecated 'static' config key used, please use the key 'Plugin::Static::Simple' instead")
         if exists $c->config->{static};
+
+    if (exists $c->config->{static}->{include_path}) {
+        $c->config->{'Plugin::Static::Simple'}->{include_path} = [
+            @{$c->config->{'Plugin::Static::Simple'}->{include_path} || []},
+            @{delete $c->config->{static}->{include_path} || []}
+        ];
+    }
+    
     my $config
         = $c->config->{'Plugin::Static::Simple'}
         = $c->config->{'static'}
@@ -586,6 +594,18 @@ messages.
 
 C<setup> initializes all default values.
 
+=head1 DEPRECATIONS
+
+The old style of configuration using the C<'static'> config key was deprecated
+in version 0.30. A warning will be issued if this is used, and the contents of
+the config at this key will be merged with the newer C<'Plugin::Static::Simple'>
+key.
+
+Be aware that if the C<'include_path'> key under C<'static'> exists at all, it
+will be merged with any content of the same key under
+C<'Plugin::Static::Simple'>. Be careful not to set this to a non-arrayref,
+therefore.
+
 =head1 SEE ALSO
 
 L<Catalyst>, L<Catalyst::Plugin::Static>,
diff --git a/t/13no_include_path.t b/t/13no_include_path.t
new file mode 100644 (file)
index 0000000..b3d2137
--- /dev/null
@@ -0,0 +1,17 @@
+#!perl
+
+use strict;
+use warnings;
+
+use FindBin;
+use lib "$FindBin::Bin/lib";
+
+use Test::More tests => 4;
+use Catalyst::Test 'TestApp';
+
+# test passthrough to root
+ok( my $res = request('http://localhost/images/bad.gif'), 'request ok' );
+is( $res->content_type, 'image/gif', 'root path ok' );
+
+is( scalar @{ TestApp->config->{'Plugin::Static::Simple'}->{include_path} }, 1, 'One include path used');
+is( TestApp->config->{'Plugin::Static::Simple'}->{include_path}->[0], TestApp->config->{root}, "It's the root path" );
diff --git a/t/14deprecated.t b/t/14deprecated.t
new file mode 100644 (file)
index 0000000..efe758e
--- /dev/null
@@ -0,0 +1,22 @@
+#!perl
+
+use strict;
+use warnings;
+
+use FindBin;
+use lib "$FindBin::Bin/lib";
+
+use Test::More tests => 5;
+use Catalyst::Test 'IncTestApp';
+
+is( $TestLog::logged, "Deprecated 'static' config key used, please use the key 'Plugin::Static::Simple' instead",
+    "Got warning" );
+
+# test overlay dir
+ok( my $res = request('http://localhost/overlay.jpg'), 'request ok' );
+is( $res->content_type, 'image/jpeg', 'overlay path ok' );
+
+# test passthrough to root
+ok( $res = request('http://localhost/images/bad.gif'), 'request ok' );
+is( $res->content_type, 'image/gif', 'root path ok' );
+
diff --git a/t/lib/IncTestApp.pm b/t/lib/IncTestApp.pm
new file mode 100644 (file)
index 0000000..a11b438
--- /dev/null
@@ -0,0 +1,46 @@
+package IncTestApp;\r
+# FIXME: I have to do this because TestApp runs setup at compile time\r
+# Perhaps it would be better to let the tests run setup?\r
+\r
+use strict;\r
+use Catalyst;\r
+use FindBin;\r
+use TestLog;\r
+\r
+our $VERSION = '0.01';\r
+\r
+IncTestApp->config(\r
+    name => 'TestApp',\r
+    debug => 1,\r
+    static => {\r
+        include_path => [\r
+            IncTestApp->config->{root},\r
+        ]\r
+    },\r
+    'Plugin::Static::Simple' => {\r
+        include_path => [\r
+            IncTestApp->config->{root} . '/overlay',\r
+        ]\r
+    },\r
+);\r
+\r
+IncTestApp->log( TestLog->new );\r
+my @plugins = qw/Static::Simple/;\r
+\r
+# load the SubRequest plugin if available\r
+eval { \r
+    require Catalyst::Plugin::SubRequest; \r
+    die unless Catalyst::Plugin::SubRequest->VERSION ge '0.08';\r
+};\r
+push @plugins, 'SubRequest' unless ($@);\r
+\r
+IncTestApp->setup( @plugins );\r
+\r
+sub incpath_generator {\r
+    my $c = shift;\r
+    \r
+    return [ $c->config->{root} . '/incpath' ];\r
+}\r
+\r
+\r
+1;\r
diff --git a/t/lib/IncTestApp/Controller/Root.pm b/t/lib/IncTestApp/Controller/Root.pm
new file mode 100644 (file)
index 0000000..21948c0
--- /dev/null
@@ -0,0 +1,45 @@
+package IncTestApp::Controller::Root;\r
+\r
+use strict;\r
+use warnings;\r
+use File::Spec::Functions;\r
+\r
+use base qw/Catalyst::Controller/;\r
+\r
+__PACKAGE__->config(namespace => '');\r
+\r
+sub default : Private {\r
+    my ( $self, $c ) = @_;\r
+    \r
+    $c->res->output( 'default' );\r
+}\r
+\r
+sub subtest : Local {\r
+    my ( $self, $c ) = @_;\r
+\r
+    $c->res->output( $c->subreq('/subtest2') );\r
+}\r
+\r
+sub subtest2 : Local {\r
+    my ( $self, $c ) = @_;\r
+    \r
+    $c->res->output( 'subtest2 ok' );\r
+}\r
+\r
+sub serve_static : Local {\r
+    my ( $self, $c ) = @_;\r
+    \r
+    my $file = catfile( $FindBin::Bin, 'lib', 'TestApp.pm' );\r
+    \r
+    $c->serve_static_file( $file );\r
+}\r
+\r
+sub serve_static_404 : Local {\r
+    my ( $self, $c ) = @_;\r
+    \r
+    my $file = catfile( $FindBin::Bin, 'lib', 'foo.pm' );\r
+    \r
+    $c->serve_static_file( $file );\r
+}\r
+\r
+1;\r
diff --git a/t/lib/IncTestApp/root/always-static/test b/t/lib/IncTestApp/root/always-static/test
new file mode 100644 (file)
index 0000000..9eb0ae4
--- /dev/null
@@ -0,0 +1 @@
+I am a text file!
diff --git a/t/lib/IncTestApp/root/always-static/test.html b/t/lib/IncTestApp/root/always-static/test.html
new file mode 100644 (file)
index 0000000..18ed998
--- /dev/null
@@ -0,0 +1,8 @@
+<html>
+  <head>
+    <title>test</title>
+  </head>
+  <body>
+    <div>test</div>
+  </body>
+</html>
diff --git a/t/lib/IncTestApp/root/css/static.css b/t/lib/IncTestApp/root/css/static.css
new file mode 100644 (file)
index 0000000..de57cdb
--- /dev/null
@@ -0,0 +1,3 @@
+body {
+    background: #fff;
+}
diff --git a/t/lib/IncTestApp/root/files/bad.gif b/t/lib/IncTestApp/root/files/bad.gif
new file mode 100644 (file)
index 0000000..de57cdb
--- /dev/null
@@ -0,0 +1,3 @@
+body {
+    background: #fff;
+}
diff --git a/t/lib/IncTestApp/root/files/empty.txt b/t/lib/IncTestApp/root/files/empty.txt
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/t/lib/IncTestApp/root/files/err.omg b/t/lib/IncTestApp/root/files/err.omg
new file mode 100644 (file)
index 0000000..de57cdb
--- /dev/null
@@ -0,0 +1,3 @@
+body {
+    background: #fff;
+}
diff --git a/t/lib/IncTestApp/root/files/space file.txt b/t/lib/IncTestApp/root/files/space file.txt
new file mode 100644 (file)
index 0000000..de57cdb
--- /dev/null
@@ -0,0 +1,3 @@
+body {
+    background: #fff;
+}
diff --git a/t/lib/IncTestApp/root/files/static.css b/t/lib/IncTestApp/root/files/static.css
new file mode 100644 (file)
index 0000000..de57cdb
--- /dev/null
@@ -0,0 +1,3 @@
+body {
+    background: #fff;
+}
diff --git a/t/lib/IncTestApp/root/ignored/bad.gif b/t/lib/IncTestApp/root/ignored/bad.gif
new file mode 100644 (file)
index 0000000..de57cdb
--- /dev/null
@@ -0,0 +1,3 @@
+body {
+    background: #fff;
+}
diff --git a/t/lib/IncTestApp/root/ignored/index.html b/t/lib/IncTestApp/root/ignored/index.html
new file mode 100644 (file)
index 0000000..de57cdb
--- /dev/null
@@ -0,0 +1,3 @@
+body {
+    background: #fff;
+}
diff --git a/t/lib/IncTestApp/root/ignored/static.css b/t/lib/IncTestApp/root/ignored/static.css
new file mode 100644 (file)
index 0000000..de57cdb
--- /dev/null
@@ -0,0 +1,3 @@
+body {
+    background: #fff;
+}
diff --git a/t/lib/IncTestApp/root/ignored/tmpl.tt b/t/lib/IncTestApp/root/ignored/tmpl.tt
new file mode 100644 (file)
index 0000000..de57cdb
--- /dev/null
@@ -0,0 +1,3 @@
+body {
+    background: #fff;
+}
diff --git a/t/lib/IncTestApp/root/images/bad.gif b/t/lib/IncTestApp/root/images/bad.gif
new file mode 100644 (file)
index 0000000..de57cdb
--- /dev/null
@@ -0,0 +1,3 @@
+body {
+    background: #fff;
+}
diff --git a/t/lib/IncTestApp/root/images/catalyst.png b/t/lib/IncTestApp/root/images/catalyst.png
new file mode 100644 (file)
index 0000000..464e512
Binary files /dev/null and b/t/lib/IncTestApp/root/images/catalyst.png differ
diff --git a/t/lib/IncTestApp/root/incpath/incpath.css b/t/lib/IncTestApp/root/incpath/incpath.css
new file mode 100644 (file)
index 0000000..de57cdb
--- /dev/null
@@ -0,0 +1,3 @@
+body {
+    background: #fff;
+}
diff --git a/t/lib/IncTestApp/root/overlay/o-ignored/bad.gif b/t/lib/IncTestApp/root/overlay/o-ignored/bad.gif
new file mode 100644 (file)
index 0000000..de57cdb
--- /dev/null
@@ -0,0 +1,3 @@
+body {
+    background: #fff;
+}
diff --git a/t/lib/IncTestApp/root/overlay/o-ignored/index.html b/t/lib/IncTestApp/root/overlay/o-ignored/index.html
new file mode 100644 (file)
index 0000000..de57cdb
--- /dev/null
@@ -0,0 +1,3 @@
+body {
+    background: #fff;
+}
diff --git a/t/lib/IncTestApp/root/overlay/o-ignored/static.css b/t/lib/IncTestApp/root/overlay/o-ignored/static.css
new file mode 100644 (file)
index 0000000..de57cdb
--- /dev/null
@@ -0,0 +1,3 @@
+body {
+    background: #fff;
+}
diff --git a/t/lib/IncTestApp/root/overlay/o-ignored/tmpl.tt b/t/lib/IncTestApp/root/overlay/o-ignored/tmpl.tt
new file mode 100644 (file)
index 0000000..de57cdb
--- /dev/null
@@ -0,0 +1,3 @@
+body {
+    background: #fff;
+}
diff --git a/t/lib/IncTestApp/root/overlay/overlay.jpg b/t/lib/IncTestApp/root/overlay/overlay.jpg
new file mode 100644 (file)
index 0000000..de57cdb
--- /dev/null
@@ -0,0 +1,3 @@
+body {
+    background: #fff;
+}