From: Alastair McGowan-Douglas Date: Fri, 26 Sep 2014 14:25:35 +0000 (+0100) Subject: Fix and test failure to merge include paths X-Git-Tag: v0.33~5^2~2 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Plugin-Static-Simple.git;a=commitdiff_plain;h=5ce67b0bac5e50b600b68ec341866822a7472b07 Fix and test failure to merge include paths (Sorry about the copypasta) --- diff --git a/lib/Catalyst/Plugin/Static/Simple.pm b/lib/Catalyst/Plugin/Static/Simple.pm index 856b47c..d8ee9c3 100755 --- a/lib/Catalyst/Plugin/Static/Simple.pm +++ b/lib/Catalyst/Plugin/Static/Simple.pm @@ -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 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, L, diff --git a/t/13no_include_path.t b/t/13no_include_path.t new file mode 100644 index 0000000..b3d2137 --- /dev/null +++ b/t/13no_include_path.t @@ -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 index 0000000..efe758e --- /dev/null +++ b/t/14deprecated.t @@ -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 index 0000000..a11b438 --- /dev/null +++ b/t/lib/IncTestApp.pm @@ -0,0 +1,46 @@ +package IncTestApp; +# FIXME: I have to do this because TestApp runs setup at compile time +# Perhaps it would be better to let the tests run setup? + +use strict; +use Catalyst; +use FindBin; +use TestLog; + +our $VERSION = '0.01'; + +IncTestApp->config( + name => 'TestApp', + debug => 1, + static => { + include_path => [ + IncTestApp->config->{root}, + ] + }, + 'Plugin::Static::Simple' => { + include_path => [ + IncTestApp->config->{root} . '/overlay', + ] + }, +); + +IncTestApp->log( TestLog->new ); +my @plugins = qw/Static::Simple/; + +# load the SubRequest plugin if available +eval { + require Catalyst::Plugin::SubRequest; + die unless Catalyst::Plugin::SubRequest->VERSION ge '0.08'; +}; +push @plugins, 'SubRequest' unless ($@); + +IncTestApp->setup( @plugins ); + +sub incpath_generator { + my $c = shift; + + return [ $c->config->{root} . '/incpath' ]; +} + + +1; diff --git a/t/lib/IncTestApp/Controller/Root.pm b/t/lib/IncTestApp/Controller/Root.pm new file mode 100644 index 0000000..21948c0 --- /dev/null +++ b/t/lib/IncTestApp/Controller/Root.pm @@ -0,0 +1,45 @@ +package IncTestApp::Controller::Root; + +use strict; +use warnings; +use File::Spec::Functions; + +use base qw/Catalyst::Controller/; + +__PACKAGE__->config(namespace => ''); + +sub default : Private { + my ( $self, $c ) = @_; + + $c->res->output( 'default' ); +} + +sub subtest : Local { + my ( $self, $c ) = @_; + + $c->res->output( $c->subreq('/subtest2') ); +} + +sub subtest2 : Local { + my ( $self, $c ) = @_; + + $c->res->output( 'subtest2 ok' ); +} + +sub serve_static : Local { + my ( $self, $c ) = @_; + + my $file = catfile( $FindBin::Bin, 'lib', 'TestApp.pm' ); + + $c->serve_static_file( $file ); +} + +sub serve_static_404 : Local { + my ( $self, $c ) = @_; + + my $file = catfile( $FindBin::Bin, 'lib', 'foo.pm' ); + + $c->serve_static_file( $file ); +} + +1; diff --git a/t/lib/IncTestApp/root/always-static/test b/t/lib/IncTestApp/root/always-static/test new file mode 100644 index 0000000..9eb0ae4 --- /dev/null +++ b/t/lib/IncTestApp/root/always-static/test @@ -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 index 0000000..18ed998 --- /dev/null +++ b/t/lib/IncTestApp/root/always-static/test.html @@ -0,0 +1,8 @@ + + + test + + +
test
+ + diff --git a/t/lib/IncTestApp/root/css/static.css b/t/lib/IncTestApp/root/css/static.css new file mode 100644 index 0000000..de57cdb --- /dev/null +++ b/t/lib/IncTestApp/root/css/static.css @@ -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 index 0000000..de57cdb --- /dev/null +++ b/t/lib/IncTestApp/root/files/bad.gif @@ -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 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 index 0000000..de57cdb --- /dev/null +++ b/t/lib/IncTestApp/root/files/err.omg @@ -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 index 0000000..de57cdb --- /dev/null +++ b/t/lib/IncTestApp/root/files/space file.txt @@ -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 index 0000000..de57cdb --- /dev/null +++ b/t/lib/IncTestApp/root/files/static.css @@ -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 index 0000000..de57cdb --- /dev/null +++ b/t/lib/IncTestApp/root/ignored/bad.gif @@ -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 index 0000000..de57cdb --- /dev/null +++ b/t/lib/IncTestApp/root/ignored/index.html @@ -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 index 0000000..de57cdb --- /dev/null +++ b/t/lib/IncTestApp/root/ignored/static.css @@ -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 index 0000000..de57cdb --- /dev/null +++ b/t/lib/IncTestApp/root/ignored/tmpl.tt @@ -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 index 0000000..de57cdb --- /dev/null +++ b/t/lib/IncTestApp/root/images/bad.gif @@ -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 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 index 0000000..de57cdb --- /dev/null +++ b/t/lib/IncTestApp/root/incpath/incpath.css @@ -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 index 0000000..de57cdb --- /dev/null +++ b/t/lib/IncTestApp/root/overlay/o-ignored/bad.gif @@ -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 index 0000000..de57cdb --- /dev/null +++ b/t/lib/IncTestApp/root/overlay/o-ignored/index.html @@ -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 index 0000000..de57cdb --- /dev/null +++ b/t/lib/IncTestApp/root/overlay/o-ignored/static.css @@ -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 index 0000000..de57cdb --- /dev/null +++ b/t/lib/IncTestApp/root/overlay/o-ignored/tmpl.tt @@ -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 index 0000000..de57cdb --- /dev/null +++ b/t/lib/IncTestApp/root/overlay/overlay.jpg @@ -0,0 +1,3 @@ +body { + background: #fff; +}