Skip to content

Commit

Permalink
test clean routes too
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Mar 14, 2015
1 parent ca3a8af commit cab348a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
7 changes: 3 additions & 4 deletions lib/Mojolicious/Plugin/TagHelpers.pm
Expand Up @@ -53,10 +53,9 @@ sub _form_for {
push @url, shift if ref $_[0] eq 'HASH';

# Method detection
my (@post, $method);
if (my $r = $c->app->routes->lookup($url[0])) {
@post = (method => 'POST') if ($method = $r->suggested_method) ne 'GET';
}
my $r = $c->app->routes->lookup($url[0]);
my $method = $r ? $r->suggested_method : 'GET';
my @post = $method ne 'GET' ? (method => 'POST') : ();

my $url = $c->url_for(@url);
$url->query({_method => $method}) if @post && $method ne 'POST';
Expand Down
2 changes: 2 additions & 0 deletions t/mojolicious/routes.t
Expand Up @@ -238,6 +238,7 @@ is $m->root, $r, 'right root';
is $m->endpoint->name, 'very_clean', 'right name';
is_deeply $m->stack, [{clean => 1}], 'right strucutre';
is $m->path_for->{path}, '/clean', 'right path';
is $m->endpoint->suggested_method, 'GET', 'right method';
$m = Mojolicious::Routes::Match->new(root => $r);
$m->find($c => {method => 'GET', path => '/clean/too'});
is_deeply $m->stack, [{something => 1}], 'right strucutre';
Expand Down Expand Up @@ -453,6 +454,7 @@ $m->find($c => {method => 'GET', path => '/foo/testedit'});
is_deeply $m->stack, [{controller => 'foo', action => 'testedit'}],
'right structure';
is $m->path_for->{path}, '/foo/testedit', 'right path';
is $m->endpoint->suggested_method, 'GET', 'right method';

# Optional captures in sub route with requirement
$m = Mojolicious::Routes::Match->new(root => $r);
Expand Down

0 comments on commit cab348a

Please sign in to comment.