Skip to content

Commit

Permalink
improved router to allow format detection for bridges
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Jan 23, 2014
1 parent e955b69 commit 300485b
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 3 deletions.
1 change: 1 addition & 0 deletions Changes
@@ -1,5 +1,6 @@

4.69 2014-01-23
- Improved router to allow format detection for bridges.

4.68 2014-01-22
- Added Mojo::DOM::Node.
Expand Down
6 changes: 5 additions & 1 deletion lib/Mojolicious/Routes/Match.pm
Expand Up @@ -71,7 +71,11 @@ sub _match {
my $endpoint = $r->is_endpoint;
if (($endpoint && $empty) || $r->inline) {
push @{$self->stack}, {%$captures};
return $self->endpoint($r) if $endpoint && $empty;
if ($endpoint && $empty) {
my $format = $captures->{format};
if ($format) { $_->{format} = $format for @{$self->stack} }
return $self->endpoint($r);
}
delete @$captures{qw(app cb)};
}

Expand Down
14 changes: 12 additions & 2 deletions t/mojolicious/group_lite_app.t
Expand Up @@ -377,10 +377,20 @@ $t->get_ok('/group/nested/whatever')->status_is(200)
$t->get_ok('/group/nested/something')->status_is(404)->content_is("Oops!\n");

# Authenticated by group
$t->get_ok('/authgroup?ok=1')->status_is(200)->content_is("You're ok.");
$t->get_ok('/authgroup?ok=1')->status_is(200)
->content_type_is('text/html;charset=UTF-8')->content_is("You're ok.");

# Not authenticated by group
$t->get_ok('/authgroup')->status_is(200)->content_is("You're not ok.");
$t->get_ok('/authgroup')->status_is(200)
->content_type_is('text/html;charset=UTF-8')->content_is("You're not ok.");

# Authenticated by group (with format)
$t->get_ok('/authgroup.txt?ok=1')->status_is(200)
->content_type_is('text/plain;charset=UTF-8')->content_is("You're ok.");

# Not authenticated by group (with format)
$t->get_ok('/authgroup.txt')->status_is(200)
->content_type_is('text/plain;charset=UTF-8')->content_is("You're not ok.");

# Bypassed group authentication
$t->get_ok('/noauthgroup')->status_is(200)->content_is("Whatever one.\n");
Expand Down
8 changes: 8 additions & 0 deletions t/mojolicious/routes.t
Expand Up @@ -383,6 +383,14 @@ $m->match($c => {method => 'GET', path => '/articles/1/delete'});
);
is_deeply $m->stack, \@stack, 'right structure';
is $m->path_for, '/articles/1/delete', 'right path';
$m = Mojolicious::Routes::Match->new(root => $r);
$m->match($c => {method => 'GET', path => '/articles/1/delete.json'});
@stack = (
{controller => 'articles', action => 'load', id => 1, format => 'json'},
{controller => 'articles', action => 'delete', id => 1, format => 'json'}
);
is_deeply $m->stack, \@stack, 'right structure';
is $m->path_for, '/articles/1/delete', 'right path';

# Root
$m = Mojolicious::Routes::Match->new(root => $r);
Expand Down

0 comments on commit 300485b

Please sign in to comment.