Skip to content

Commit

Permalink
added route introspection tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Mar 19, 2012
1 parent 6ebea44 commit 1dd5cb4
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 7 deletions.
1 change: 1 addition & 0 deletions Changes
Expand Up @@ -4,6 +4,7 @@ This file documents the revision history for Perl extension Mojolicious.
- Added find method to Mojolicious::Routes.
- Improved Mojolicious::Renderer performance.
- Improved documentation.
- Improved tests.
- Fixed bug that slowed down Mojolicious::Renderer.
- Fixed small newline capture bug in Mojolicious::Routes::Match.

Expand Down
6 changes: 3 additions & 3 deletions lib/Mojolicious/Routes.pm
Expand Up @@ -739,7 +739,7 @@ Match routes and dispatch.
=head2 C<find>
my $foo = $r->find('foo');
my $route = $r->find('foo');
Find child route by name, custom names have precedence over automatically
generated ones.
Expand Down Expand Up @@ -838,8 +838,8 @@ L<Mojolicious::Lite> tutorial for more argument variations.
=head2 C<render>
my $path = $r->render($path);
my $path = $r->render($path, {foo => 'bar'});
my $path = $r->render($suffix);
my $path = $r->render($suffix, {foo => 'bar'});
Render route with parameters into a path.
Expand Down
4 changes: 3 additions & 1 deletion t/mojolicious/app.t
Expand Up @@ -7,7 +7,7 @@ BEGIN {
$ENV{MOJO_MODE} = 'development';
}

use Test::More tests => 279;
use Test::More tests => 280;

use FindBin;
use lib "$FindBin::Bin/lib";
Expand All @@ -23,6 +23,8 @@ use Test::Mojo;
my $t = Test::Mojo->new('MojoliciousTest');

# Application is already available
is $t->app->routes->find('something')->to_string, '/test4/:something',
'right pattern';
is $t->app->sessions->cookie_domain, '.example.com', 'right domain';
is $t->app->sessions->cookie_path, '/bar', 'right path';

Expand Down
8 changes: 7 additions & 1 deletion t/mojolicious/production_app.t
Expand Up @@ -7,7 +7,7 @@ BEGIN {
$ENV{MOJO_MODE} = 'production';
}

use Test::More tests => 62;
use Test::More tests => 65;

use FindBin;
use lib "$FindBin::Bin/lib";
Expand All @@ -17,6 +17,12 @@ use Test::Mojo;
# "This concludes the part of the tour where you stay alive."
my $t = Test::Mojo->new('MojoliciousTest');

# Application is already available
is $t->app->routes->find('something')->to_string, '/test4/:something',
'right pattern';
is $t->app->sessions->cookie_domain, '.example.com', 'right domain';
is $t->app->sessions->cookie_path, '/bar', 'right path';

# Plugin::Test::SomePlugin2::register (security violation)
$t->get_ok('/plugin-test-some_plugin2/register')->status_isnt(500)
->status_is(404)->header_is(Server => 'Mojolicious (Perl)')
Expand Down
12 changes: 10 additions & 2 deletions t/mojolicious/routes.t
@@ -1,14 +1,14 @@
use Mojo::Base -strict;

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

# "They're not very heavy, but you don't hear me not complaining."
use Mojolicious::Routes;
use Mojolicious::Routes::Match;

# /clean
my $r = Mojolicious::Routes->new;
$r->route('/clean')->to(clean => 1);
$r->route('/clean')->to(clean => 1)->name('very_clean');

# /clean/too
$r->route('/clean/too')->to(something => 1);
Expand Down Expand Up @@ -201,6 +201,14 @@ is $m->stack->[0]->{something}, 1, 'right value';
is $m->path_for, '/clean/too', 'right path';
is @{$m->stack}, 1, 'right number of elements';

# Introspect
is $r->find('very_clean')->to_string, '/clean', 'right pattern';
is $r->find('0')->to_string, '/0', 'right pattern';
is $r->find('test_edit')->to_string, '/:controller/test/edit',
'right pattern';
is $r->find('articles_delete')->to_string, '/articles/:id/delete',
'right pattern';

# Null route
$m = Mojolicious::Routes::Match->new(GET => '/0')->match($r);
is $m->stack->[0]->{null}, 1, 'right value';
Expand Down

0 comments on commit 1dd5cb4

Please sign in to comment.