Skip to content

Commit

Permalink
added a few tests for Mojolicious::Routes::Match
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Mar 19, 2012
1 parent 9311924 commit f0a3584
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
2 changes: 1 addition & 1 deletion lib/Mojolicious/Controller.pm
Expand Up @@ -16,7 +16,7 @@ use Scalar::Util ();
# "Scalpel... blood bucket... priest."
has app => sub { Mojolicious->new };
has match => sub {
Mojolicious::Routes::Match->new(get => '/')->root(shift->app->routes);
Mojolicious::Routes::Match->new(GET => '/')->root(shift->app->routes);
};
has tx => sub { Mojo::Transaction::HTTP->new };

Expand Down
7 changes: 4 additions & 3 deletions lib/Mojolicious/Routes/Match.pm
Expand Up @@ -160,7 +160,8 @@ sub route_for {
my ($self, $name) = @_;

# Check all children
my @children = (@{$self->root->children});
return unless my $root = $self->root;
my @children = (@{$root->children});
my $candidate;
while (my $child = shift @children) {

Expand Down Expand Up @@ -243,8 +244,8 @@ implements the following ones.
=head2 C<new>
my $m = Mojolicious::Routes::Match->new(get => '/foo');
my $m = Mojolicious::Routes::Match->new(get => '/foo', $ws);
my $m = Mojolicious::Routes::Match->new(GET => '/foo');
my $m = Mojolicious::Routes::Match->new(GET => '/foo', $ws);
Construct a new match object.
Expand Down
9 changes: 8 additions & 1 deletion t/mojolicious/routes.t
@@ -1,6 +1,6 @@
use Mojo::Base -strict;

use Test::More tests => 349;
use Test::More tests => 352;

# "They're not very heavy, but you don't hear me not complaining."
use Mojolicious::Routes;
Expand Down Expand Up @@ -189,6 +189,13 @@ $r->route('/regex/alternatives/:alternatives',
$r->route('/versioned')->route('/2.0')->to(controller => 'foo')
->route('/test')->to(action => 'bar');

# Empty match
ok !Mojolicious::Routes::Match->new(GET => '/')->path_for, 'no result';
is(Mojolicious::Routes::Match->new(GET => '/')->path_for('foo'),
'foo', 'right result');
ok !Mojolicious::Routes::Match->new(GET => '/')->route_for('foo'),
'no result';

# Make sure stash stays clean
my $m = Mojolicious::Routes::Match->new(get => '/clean')->match($r);
is $m->stack->[0]->{clean}, 1, 'right value';
Expand Down

0 comments on commit f0a3584

Please sign in to comment.