Skip to content

Commit

Permalink
fixed default format handling bug in render_exception and render_not_…
Browse files Browse the repository at this point in the history
…found
  • Loading branch information
kraih committed Jul 6, 2012
1 parent 2ab447f commit 74a80a0
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 16 deletions.
4 changes: 3 additions & 1 deletion Changes
Expand Up @@ -4,8 +4,10 @@
- Improved Hypnotoad log messages.
- Improved documentation.
- Improved tests.
- Fixed default format handling bug in render_exception and
render_not_found.
- Fixed small namespace detection bug in Mojo::DOM.
- Fixed small bug in Test::Mojo.
- Fixed small session reset bug in Test::Mojo.

3.02 2012-07-03
- Added pluck and uniq methods to Mojo::Collection.
Expand Down
7 changes: 4 additions & 3 deletions lib/Mojolicious/Controller.pm
Expand Up @@ -258,7 +258,7 @@ sub render_exception {
exception => $e,
snapshot => \%snapshot,
template => "exception.$mode",
format => $stash->{format} || 'html',
format => $stash->{format} || $app->renderer->default_format,
handler => undef,
status => 500
};
Expand All @@ -279,8 +279,9 @@ sub render_not_found {
my $self = shift;

# Render with fallbacks
my $mode = $self->app->mode;
my $format = $self->stash->{format} || 'html';
my $app = $self->app;
my $mode = $app->mode;
my $format = $self->stash->{format} || $app->renderer->default_format;
my $options
= {template => "not_found.$mode", format => $format, status => 404};
my $inline = $mode eq 'development' ? $DEV_NOT_FOUND : $NOT_FOUND;
Expand Down
1 change: 1 addition & 0 deletions t/mojolicious/exception_lite_app.t
Expand Up @@ -17,6 +17,7 @@ use Test::More tests => 86;
use Mojolicious::Lite;
use Test::Mojo;

# No real templates
app->renderer->paths->[0] = app->home->rel_dir('does_not_exist');

# Logger
Expand Down
17 changes: 12 additions & 5 deletions t/mojolicious/renderer.t
@@ -1,6 +1,6 @@
use Mojo::Base -strict;

use Test::More tests => 6;
use Test::More tests => 7;

# "Actually, she wasn't really my girlfriend,
# she just lived nextdoor and never closed her curtains."
Expand All @@ -16,32 +16,39 @@ is $c->render(text => 'works', partial => 1), 'works', 'renderer is working';
$c = Mojolicious::Controller->new(app => Mojolicious->new);
$c->app->log->path(undef);
$c->app->log->level('fatal');
$c->app->types->type(debug => 'text/debug');
my $r = Mojolicious::Renderer->new(default_format => 'debug');
$r->add_handler(
debug => sub {
my ($self, $c, $output) = @_;
$$output .= 'Hello Mojo!';
}
);
$c->stash->{format} = 'something';

# Normal rendering
# Normal rendering with custom format
$c->stash->{template} = 'something';
$c->stash->{handler} = 'debug';
is_deeply [$r->render($c)], ['Hello Mojo!', 'text/debug'], 'normal rendering';

# Normal rendering with custom format
$c->stash->{format} = 'something';
$c->stash->{template} = 'something';
$c->stash->{handler} = 'debug';
is_deeply [$r->render($c)], ['Hello Mojo!', 'text/plain'], 'normal rendering';

# Normal rendering with layout
delete $c->stash->{format};
$c->stash->{template} = 'something';
$c->stash->{layout} = 'something';
$c->stash->{handler} = 'debug';
is_deeply [$r->render($c)], ['Hello Mojo!Hello Mojo!', 'text/plain'],
is_deeply [$r->render($c)], ['Hello Mojo!Hello Mojo!', 'text/debug'],
'normal rendering with layout';
is delete $c->stash->{layout}, 'something';

# Rendering a path with dots
$c->stash->{template} = 'some.path.with.dots/template';
$c->stash->{handler} = 'debug';
is_deeply [$r->render($c)], ['Hello Mojo!', 'text/plain'],
is_deeply [$r->render($c)], ['Hello Mojo!', 'text/debug'],
'rendering a path with dots';

# Unrecognized handler
Expand Down
29 changes: 22 additions & 7 deletions t/mojolicious/twinkle_lite_app.t
Expand Up @@ -6,14 +6,17 @@ BEGIN {
$ENV{MOJO_REACTOR} = 'Mojo::Reactor::Poll';
}

use Test::More tests => 19;
use Test::More tests => 23;

# "Pizza delivery for...
# I. C. Weiner. Aww... I always thought by this stage in my life I'd be the
# one making the crank calls."
use Mojolicious::Lite;
use Test::Mojo;

# Custom format
app->renderer->default_format('foo');

# Twinkle template syntax
my $twinkle = {
capture_end => '-',
Expand Down Expand Up @@ -51,6 +54,9 @@ get '/docs2' => {codename => 'snowman'} => 'docs2';
# GET /docs3
get '/docs3' => sub { shift->stash(codename => undef) } => 'docs';

# GET /dead
get '/dead' => sub {die};

my $t = Test::Mojo->new;

# GET /
Expand All @@ -70,27 +76,36 @@ $t->get_ok('/docs2')->status_is(200)->content_like(qr!<h2>snowman</h2>!);
$t->get_ok('/docs3')->status_is(200)->content_like(qr!<h3></h3>!);

# GET /perldoc (disabled)
$t->get_ok('/perldoc')->status_is(404);
$t->get_ok('/perldoc')->status_is(404)->content_is("Whatever not found!\n");

# GET /dead (exception template with custom format)
$t->get_ok('/dead')->status_is(500)->content_is("Whatever exception!\n");

__DATA__
@@ index.html.twinkle
@@ index.foo.twinkle
. layout 'twinkle';
Hello **** $name **!\
@@ layouts/twinkle.html.ep
@@ layouts/twinkle.foo.ep
test<%= content %>123\
@@ advanced.html.twinkle
@@ advanced.foo.twinkle
.* '<escape me>'
. my $numbers = [1 .. 4];
** for my $i (@$numbers) { ***
*** $i ***
** } ***
** my $foo = (+*** 23 **-)->();*** *** $foo ***
@@ docs.html.pod
@@ docs.foo.pod
% no warnings;
<%= '=head3 ' . $codename %>
@@ docs2.html.teapod
@@ docs2.foo.teapod
.** '=head2 ' . $codename
@@ exception.foo.ep
Whatever exception!
@@ not_found.foo.ep
Whatever not found!

0 comments on commit 74a80a0

Please sign in to comment.