Skip to content

Commit

Permalink
return invocant from respond_to
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed May 14, 2013
1 parent 7d932b9 commit b09719d
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Changes
Expand Up @@ -14,7 +14,7 @@
- Changed heuristics for number detection in Mojo::JSON to better line up
with user expectations.
- Changed render and render_static methods in Mojolicious::Controller to
call render_not_found if generating a response fails.
call render_not_found if no response could be generated.
- Removed callback support from body method in Mojo::Message.
- Removed Mojolicious::Plugin::PoweredBy and
Mojolicious::Plugin::RequestTimer.
Expand Down
4 changes: 3 additions & 1 deletion lib/Mojolicious/Controller.pm
Expand Up @@ -290,6 +290,8 @@ sub respond_to {

# Dispatch
ref $target eq 'CODE' ? $target->($self) : $self->render(%$target);

return $self;
}

sub send {
Expand Down Expand Up @@ -747,7 +749,7 @@ Get L<Mojo::Message::Response> object from L<Mojo::Transaction/"res">.
=head2 respond_to
$c->respond_to(
$c = $c->respond_to(
json => {json => {message => 'Welcome!'}},
html => {template => 'welcome'},
any => sub {...}
Expand Down
8 changes: 5 additions & 3 deletions t/mojolicious/twinkle_lite_app.t
Expand Up @@ -71,7 +71,7 @@ get '/rest' => sub {
shift->respond_to(
foo => {text => 'foo works!'},
html => {text => 'html works!'}
);
)->res->headers->header('X-Rest' => 1);
};

get '/dead' => sub {die};
Expand All @@ -96,10 +96,12 @@ $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>!);

# REST request for "foo" format
$t->get_ok('/rest')->status_is(200)->content_is('foo works!');
$t->get_ok('/rest')->status_is(200)->header_is('X-Rest' => 1)
->content_is('foo works!');

# REST request for "html" format
$t->get_ok('/rest.html')->status_is(200)->content_is('html works!');
$t->get_ok('/rest.html')->status_is(200)->header_is('X-Rest' => 1)
->content_is('html works!');

# Perldoc browser is disabled
$t->get_ok('/perldoc')->status_is(404)->content_is("foo not found!\n");
Expand Down

0 comments on commit b09719d

Please sign in to comment.