Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
a few more routing tests
  • Loading branch information
kraih committed Feb 22, 2013
1 parent 6227ec7 commit d0383ed
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
5 changes: 4 additions & 1 deletion Changes
@@ -1,6 +1,9 @@

3.87 2013-02-23
- Improved tests.

3.86 2013-02-22
- Welcome to the Mojolicious Core Team Joel Berger.
- Welcome to the Mojolicious core team Joel Berger.
- Improved portability of Mojo::Asset::File tests.
- Improved documentation.
- Improved tests. (jberger, sri)
Expand Down
2 changes: 1 addition & 1 deletion lib/Mojolicious.pm
Expand Up @@ -40,7 +40,7 @@ has static => sub { Mojolicious::Static->new };
has types => sub { Mojolicious::Types->new };

our $CODENAME = 'Rainbow';
our $VERSION = '3.86';
our $VERSION = '3.87';

sub AUTOLOAD {
my $self = shift;
Expand Down
26 changes: 26 additions & 0 deletions t/mojolicious/routes.t
Expand Up @@ -34,6 +34,10 @@ $r->route('/alternatives3/:foo', foo => [qw(foo foobar)]);
# /alternatives4/foo.bar
$r->route('/alternatives4/:foo', foo => [qw(foo foo.bar)]);

# /optional/*
# /optional/*/*
$r->route('/optional/:foo/:bar')->to(bar => 'test');

# /*/test
my $test = $r->route('/:controller/test')->to(action => 'test');

Expand Down Expand Up @@ -346,6 +350,28 @@ $m = Mojolicious::Routes::Match->new(GET => '/alternatives4/bar.foo');
$m->match($r, $c);
is @{$m->stack}, 0, 'right number of elements';

# Optional placeholder
$m = Mojolicious::Routes::Match->new(GET => '/optional/23');
$m->match($r, $c);
is $m->stack->[0]{foo}, 23, 'right value';
is $m->stack->[0]{bar}, 'test', 'right value';
is @{$m->stack}, 1, 'right number of elements';
is $m->path_for, '/optional/23', 'right path';
is $m->path_for(format => 'txt'), '/optional/23/test.txt', 'right path';
is $m->path_for(foo => 12, format => 'txt'), '/optional/12/test.txt',
'right path';
is $m->path_for('optionalfoobar', format => 'txt'), '/optional/23/test.txt',
'right path';
$m = Mojolicious::Routes::Match->new(GET => '/optional/23/24');
$m->match($r, $c);
is $m->stack->[0]{foo}, 23, 'right value';
is $m->stack->[0]{bar}, 24, 'right value';
is @{$m->stack}, 1, 'right number of elements';
is $m->path_for, '/optional/23/24', 'right path';
is $m->path_for(format => 'txt'), '/optional/23/24.txt', 'right path';
is $m->path_for('optionalfoobar'), '/optional/23/24', 'right path';
is $m->path_for('optionalfoobar', foo => 0), '/optional/0/24', 'right path';

# Real world example using most features at once
$m = Mojolicious::Routes::Match->new(GET => '/articles/1/edit');
$m->match($r, $c);
Expand Down

0 comments on commit d0383ed

Please sign in to comment.