-
Notifications
You must be signed in to change notification settings - Fork 274
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'bugfix/use-send_as-during-template-processing'
- Loading branch information
Showing
4 changed files
with
83 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
#!/usr/bin/env perl | ||
|
||
use strict; | ||
use warnings; | ||
|
||
use Test::More; | ||
use Plack::Test; | ||
use HTTP::Request::Common; | ||
use Ref::Util qw<is_coderef>; | ||
|
||
# Tests for obscure rendering situations that may occur whilst undertaking | ||
# template processing | ||
|
||
{ | ||
package MyApp; | ||
|
||
use Dancer2; | ||
|
||
set template => 'template_toolkit'; | ||
|
||
hook on_route_exception => sub { | ||
status 200; | ||
send_as(plain => "Some plain text"); | ||
}; | ||
|
||
get '/bork' => sub { | ||
my $bork = sub { | ||
die "I've borked in the template"; | ||
}; | ||
template 'exec', | ||
{ exec_sub => $bork } | ||
}; | ||
|
||
get '/plain' => sub { | ||
my $plain = sub { | ||
send_as(plain => "Some plain text"); | ||
}; | ||
template 'exec', | ||
{ exec_sub => $plain } | ||
}; | ||
|
||
get '/html' => sub { | ||
my $html = sub { | ||
send_as(html => "<p>HTML text</p>"); | ||
}; | ||
template 'exec', | ||
{ exec_sub => $html } | ||
}; | ||
} | ||
|
||
my $app = Dancer2->psgi_app; | ||
ok( is_coderef($app), 'Got app' ); | ||
|
||
test_psgi $app, sub { | ||
my $cb = shift; | ||
|
||
my $res = $cb->(GET '/bork'); | ||
is $res->code, 200, 'Correct status code when overriding exception handling'; | ||
like $res->content, qr/plain text/, 'Correct content when overriding exception handling'; | ||
|
||
$res = $cb->(GET '/plain'); | ||
is $res->code, 200, 'Correct status when sending as plain during template render'; | ||
like $res->content, qr/plain text/, 'Correct content when sending as plain'; | ||
|
||
$res = $cb->(GET '/html'); | ||
is $res->code, 200, 'Correct status when sending as HTML during template render'; | ||
like $res->content, qr/HTML text/, 'Correct content when sending as HTML'; | ||
}; | ||
|
||
done_testing(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
[% IF NOT exec_sub %]foobar[% END %] |