Permalink
Browse files

Make public/ files available to Dancer2::Test

Problem: I broke a lot of tests. Tomorrow I'll look into them with detail.
  • Loading branch information...
1 parent a380684 commit 3dd7224a4c6eb470d6b2fef3874cf5185195b889 @ambs ambs committed Aug 28, 2013
Showing with 19 additions and 3 deletions.
  1. +9 −1 lib/Dancer2/Core/App.pm
  2. +0 −1 lib/Dancer2/Handler/File.pm
  3. +4 −1 lib/Dancer2/Test.pm
  4. +6 −0 t/auto_page.t
@@ -47,6 +47,12 @@ has default_config => (
builder => '_build_default_config',
);
+has route_handlers_order => (
+ is => 'rw',
+ isa => ArrayRef,
+ default => sub { [] },
+);
+
has route_handlers => (
is => 'rw',
isa => HashRef,
@@ -430,18 +436,20 @@ sub init_route_handlers {
my ($handler_name, $config) = @$handler_data;
$config = {} if !ref($config);
$config->{app} = $self;
+
my $handler = Dancer2::Core::Factory->create(
Handler => $handler_name,
%$config,
postponed_hooks => $self->postponed_hooks,
);
$self->route_handlers->{$handler_name} = $handler;
+ push @{$self->route_handlers_order}, $handler_name;
}
}
sub register_route_handlers {
my ($self) = @_;
- for my $handler_name ( keys %{ $self->route_handlers } ) {
+ for my $handler_name ( @{$self->{route_handlers_order}} ) {
my $handler = $self->route_handlers->{$handler_name};
$handler->register($self);
}
@@ -40,7 +40,6 @@ has regexp => (
sub BUILD {
my ($self) = @_;
-
if ( !defined $self->public_dir ) {
my $public =
$self->app->config->{public}
View
@@ -767,7 +767,10 @@ sub import {
}
# register the apps to the test dispatcher
- $_dispatcher->apps( [ map { $_->dancer_app } @applications ] );
+ $_dispatcher->apps( [ map {
+ $_->dancer_app->finish();
+ $_->dancer_app
+ } @applications ] );
$class->export_to_level( 1, $class, @EXPORT );
}
View
@@ -12,6 +12,7 @@ use Test::More;
Dancer2::Handler::AutoPage->register(app);
engine('template')->views('t/views');
engine('template')->layout('main');
+
}
use Dancer2::Test apps => ['AutoPageTest'];
@@ -29,4 +30,9 @@ like $r->content, qr/---\nPage under folder/, '...with proper content';
$r = dancer_response GET => '/non_existent_page';
is $r->status, 404, 'Autopage doesnt try to render nonexistent pages';
+$r = dancer_response GET => '/file.txt';
+is $r->status, 200, 'Found file on public with Autopage';
+
+like $r->headers->{'content-type'}, qr!text/plain!, "Public served file as correct mime";
+
done_testing;

0 comments on commit 3dd7224

Please sign in to comment.