Skip to content

Commit

Permalink
more arrows
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Aug 11, 2012
1 parent e68c988 commit 74af25c
Show file tree
Hide file tree
Showing 10 changed files with 172 additions and 154 deletions.
4 changes: 2 additions & 2 deletions lib/Mojolicious/Routes/Route.pm
Expand Up @@ -481,8 +481,8 @@ L<Mojolicious::Lite> tutorial for more argument variations.
my $over = $r->over;
$r = $r->over(foo => 1);
$r = $r->over(foo => 1, bar => qr/\w+/);
$r = $r->over([foo => 1, bar => qr/\w+/]);
$r = $r->over(foo => 1, bar => {baz => 'yada'});
$r = $r->over([foo => 1, bar => {baz => 'yada'}]);
Activate conditions for this route. Note that this automatically disables the
routing cache, since conditions are too complex for caching.
Expand Down
2 changes: 1 addition & 1 deletion t/mojo/app.t
Expand Up @@ -258,7 +258,7 @@ ok $remote_port > 0, 'has local port';
# Parallel requests
my $delay = Mojo::IOLoop->delay;
$ua->get('/13/', $delay->begin);
$ua->post('/14/', {Expect => 'fun'}, 'bar baz foo' x 128, $delay->begin);
$ua->post('/14/' => {Expect => 'fun'}, 'bar baz foo' x 128, $delay->begin);
$ua->get('/15/', $delay->begin);
($tx, $tx2, my $tx3) = $delay->wait;
ok $tx->is_finished, 'transaction is finished';
Expand Down
59 changes: 37 additions & 22 deletions t/mojo/transactor.t
Expand Up @@ -24,13 +24,13 @@ is $tx->req->url->path->to_string, 'foo%2Fbar', 'right path';
is $tx->req->method, 'GET', 'right method';

# POST with header
$tx = $t->tx(POST => 'https://mojolicio.us', {Expect => 'nothing'});
$tx = $t->tx(POST => 'https://mojolicio.us' => {Expect => 'nothing'});
is $tx->req->url->to_abs, 'https://mojolicio.us', 'right URL';
is $tx->req->method, 'POST', 'right method';
is $tx->req->headers->expect, 'nothing', 'right "Expect" value';

# POST with header and content
$tx = $t->tx(POST => 'https://mojolicio.us', {Expect => 'nothing'}, 'test');
$tx = $t->tx(POST => 'https://mojolicio.us' => {Expect => 'nothing'}, 'test');
is $tx->req->url->to_abs, 'https://mojolicio.us', 'right URL';
is $tx->req->method, 'POST', 'right method';
is $tx->req->headers->expect, 'nothing', 'right "Expect" value';
Expand Down Expand Up @@ -67,8 +67,10 @@ is $tx->req->headers->content_type, 'application/json',
is_deeply $tx->req->json, {test => 123}, 'right content';

# JSON POST with custom content type
$tx = $t->json('http://kraih.com/foo', => [1, 2, 3] =>
{DNT => 1, 'content-type' => 'application/something'});
$tx = $t->json(
'http://kraih.com/foo', => [1, 2, 3],
{DNT => 1, 'content-type' => 'application/something'}
);
is $tx->req->url->to_abs, 'http://kraih.com/foo', 'right URL';
is $tx->req->method, 'POST', 'right method';
is $tx->req->headers->dnt, 1, 'right "DNT" value';
Expand All @@ -93,16 +95,16 @@ is $tx->req->headers->content_type, 'application/x-www-form-urlencoded',
is $tx->req->body, 'test=1&test=2&test=3', 'right content';

# UTF-8 form
$tx = $t->form('http://kraih.com/foo', 'UTF-8', {test => 123});
$tx = $t->form('http://kraih.com/foo', 'UTF-8' => {test => 123});
is $tx->req->url->to_abs, 'http://kraih.com/foo', 'right URL';
is $tx->req->method, 'POST', 'right method';
is $tx->req->headers->content_type, 'application/x-www-form-urlencoded',
'right "Content-Type" value';
is $tx->req->body, 'test=123', 'right content';

# UTF-8 form with header
$tx = $t->form('http://kraih.com/foo', 'UTF-8', {test => 123},
{Accept => '*/*'});
$tx = $t->form(
'http://kraih.com/foo' => 'UTF-8' => {test => 123} => {Accept => '*/*'});
is $tx->req->url->to_abs, 'http://kraih.com/foo', 'right URL';
is $tx->req->method, 'POST', 'right method';
is $tx->req->headers->content_type, 'application/x-www-form-urlencoded',
Expand All @@ -111,8 +113,10 @@ is $tx->req->headers->accept, '*/*', 'right "Accept" value';
is $tx->req->body, 'test=123', 'right content';

# Multipart form
$tx = $t->form('http://kraih.com/foo' => {test => 123} =>
{'Content-Type' => 'multipart/form-data'});
$tx = $t->form(
'http://kraih.com/foo' => {test => 123},
{'Content-Type' => 'multipart/form-data'}
);
is $tx->req->url->to_abs, 'http://kraih.com/foo', 'right URL';
is $tx->req->method, 'POST', 'right method';
is $tx->req->headers->content_type, 'multipart/form-data',
Expand All @@ -123,8 +127,10 @@ is $tx->req->content->parts->[0]->asset->slurp, 123, 'right part';
is $tx->req->content->parts->[1], undef, 'no more parts';

# Multipart form with multiple values
$tx = $t->form('http://kraih.com/foo' => {test => [1, 2, 3]} =>
{'Content-Type' => 'multipart/form-data'});
$tx = $t->form(
'http://kraih.com/foo' => {test => [1, 2, 3]},
{'Content-Type' => 'multipart/form-data'}
);
is $tx->req->url->to_abs, 'http://kraih.com/foo', 'right URL';
is $tx->req->method, 'POST', 'right method';
is $tx->req->headers->content_type, 'multipart/form-data',
Expand Down Expand Up @@ -157,7 +163,7 @@ is $tx->req->content->parts->[0]->headers->dnt, 1, 'right "DNT" header';
is $tx->req->content->parts->[1], undef, 'no more parts';

# Multipart form with in-memory content
$tx = $t->form('http://kraih.com/foo', {mytext => {content => 'lalala'}});
$tx = $t->form('http://kraih.com/foo' => {mytext => {content => 'lalala'}});
is $tx->req->url->to_abs, 'http://kraih.com/foo', 'right URL';
is $tx->req->method, 'POST', 'right method';
is $tx->req->headers->content_type, 'multipart/form-data',
Expand Down Expand Up @@ -272,7 +278,7 @@ ok $tx->req->headers->sec_websocket_version,
is $tx->req->headers->upgrade, 'websocket', 'right "Upgrade" value';

# WebSocket handshake with header
$tx = $t->websocket('wss://127.0.0.1:3000/echo', {Expect => 'foo'});
$tx = $t->websocket('wss://127.0.0.1:3000/echo' => {Expect => 'foo'});
is $tx->req->url->to_abs, 'https://127.0.0.1:3000/echo', 'right URL';
is $tx->req->method, 'GET', 'right method';
is $tx->req->headers->expect, 'foo', 'right "Upgrade" value';
Expand Down Expand Up @@ -309,7 +315,8 @@ is $tx->req->headers->proxy_authorization, 'Basic c3JpOnNlY3IzdA==',
is $tx->req->headers->host, '127.0.0.1:3000', 'right "Host" header';

# Simple 302 redirect
$tx = $t->tx(POST => 'http://mojolico.us/foo', {Accept => 'application/json'});
$tx
= $t->tx(POST => 'http://mojolico.us/foo' => {Accept => 'application/json'});
$tx->res->code(302);
$tx->res->headers->location('http://kraih.com/bar');
is $tx->req->headers->accept, 'application/json', 'right "Accept" value';
Expand Down Expand Up @@ -338,7 +345,8 @@ is $tx->res->code, undef, 'no status';
is $tx->res->headers->location, undef, 'no "Location" value';

# Simple 303 redirect
$tx = $t->tx(POST => 'http://mojolico.us/foo', {Accept => 'application/json'});
$tx
= $t->tx(POST => 'http://mojolico.us/foo' => {Accept => 'application/json'});
$tx->res->code(303);
$tx->res->headers->location('http://kraih.com/bar');
is $tx->req->headers->accept, 'application/json', 'right "Accept" value';
Expand Down Expand Up @@ -395,7 +403,8 @@ is $tx->res->code, undef, 'no status';
is $tx->res->headers->location, undef, 'no "Location" value';

# Simple 301 redirect
$tx = $t->tx(POST => 'http://mojolico.us/foo', {Accept => 'application/json'});
$tx
= $t->tx(POST => 'http://mojolico.us/foo' => {Accept => 'application/json'});
$tx->res->code(301);
$tx->res->headers->location('http://kraih.com/bar');
is $tx->req->headers->accept, 'application/json', 'right "Accept" value';
Expand All @@ -410,7 +419,8 @@ is $tx->res->code, undef, 'no status';
is $tx->res->headers->location, undef, 'no "Location" value';

# 301 redirect with content
$tx = $t->tx(POST => 'http://mojolico.us/foo', {Accept => '*/*'}, 'whatever');
$tx
= $t->tx(POST => 'http://mojolico.us/foo' => {Accept => '*/*'}, 'whatever');
$tx->res->code(301);
$tx->res->headers->location('http://kraih.com/bar');
is $tx->req->headers->accept, '*/*', 'right "Accept" value';
Expand All @@ -432,7 +442,8 @@ $tx->req->write_chunk('whatever' => sub { shift->finish });
is $t->redirect($tx), undef, 'unsupported redirect';

# Simple 307 redirect
$tx = $t->tx(POST => 'http://mojolico.us/foo', {Accept => 'application/json'});
$tx
= $t->tx(POST => 'http://mojolico.us/foo' => {Accept => 'application/json'});
$tx->res->code(307);
$tx->res->headers->location('http://kraih.com/bar');
is $tx->req->headers->accept, 'application/json', 'right "Accept" value';
Expand All @@ -447,7 +458,8 @@ is $tx->res->code, undef, 'no status';
is $tx->res->headers->location, undef, 'no "Location" value';

# 307 redirect with content
$tx = $t->tx(POST => 'http://mojolico.us/foo', {Accept => '*/*'}, 'whatever');
$tx
= $t->tx(POST => 'http://mojolico.us/foo' => {Accept => '*/*'}, 'whatever');
$tx->res->code(307);
$tx->res->headers->location('http://kraih.com/bar');
is $tx->req->headers->accept, '*/*', 'right "Accept" value';
Expand Down Expand Up @@ -497,7 +509,8 @@ is $tx->res->code, undef, 'no status';
is $tx->res->headers->location, undef, 'no "Location" value';

# Simple 308 redirect
$tx = $t->tx(POST => 'http://mojolico.us/foo', {Accept => 'application/json'});
$tx
= $t->tx(POST => 'http://mojolico.us/foo' => {Accept => 'application/json'});
$tx->res->code(308);
$tx->res->headers->location('http://kraih.com/bar');
is $tx->req->headers->accept, 'application/json', 'right "Accept" value';
Expand All @@ -512,7 +525,8 @@ is $tx->res->code, undef, 'no status';
is $tx->res->headers->location, undef, 'no "Location" value';

# 308 redirect with content
$tx = $t->tx(POST => 'http://mojolico.us/foo', {Accept => '*/*'}, 'whatever');
$tx
= $t->tx(POST => 'http://mojolico.us/foo' => {Accept => '*/*'}, 'whatever');
$tx->res->code(308);
$tx->res->headers->location('http://kraih.com/bar');
is $tx->req->headers->accept, '*/*', 'right "Accept" value';
Expand All @@ -534,7 +548,8 @@ $tx->req->write_chunk('whatever' => sub { shift->finish });
is $t->redirect($tx), undef, 'unsupported redirect';

# 309 redirect (unsupported)
$tx = $t->tx(POST => 'http://mojolico.us/foo', {Accept => 'application/json'});
$tx
= $t->tx(POST => 'http://mojolico.us/foo' => {Accept => 'application/json'});
$tx->res->code(309);
$tx->res->headers->location('http://kraih.com/bar');
is $tx->req->headers->accept, 'application/json', 'right "Accept" value';
Expand Down
49 changes: 25 additions & 24 deletions t/mojolicious/app.t
Expand Up @@ -56,8 +56,8 @@ $t->get_ok('/plugin-test-some_plugin2/register')->status_isnt(500)
# Foo::fun
my $url = $t->ua->app_url;
$url->path('/fun/time');
$t->get_ok($url, {'X-Test' => 'Hi there!'})->status_isnt(404)->status_is(200)
->header_isnt('X-Bender' => 'Bite my shiny metal ass!')
$t->get_ok($url => {'X-Test' => 'Hi there!'})->status_isnt(404)
->status_is(200)->header_isnt('X-Bender' => 'Bite my shiny metal ass!')
->header_is('X-Bender' => undef)->header_is(Server => 'Mojolicious (Perl)')
->header_is('X-Powered-By' => 'Mojolicious (Perl)')->content_isnt('Have')
->content_is('Have fun!');
Expand Down Expand Up @@ -98,7 +98,7 @@ $t->get_ok('/exceptional_too/this_one_dies')->status_is(500)
->content_is("double doh!\n\n");

# Exceptional::this_one_dies (action behind bridge dies)
$t->get_ok('/exceptional_too/this_one_dies', {'X-DoNotDie' => 1})
$t->get_ok('/exceptional_too/this_one_dies' => {'X-DoNotDie' => 1})
->status_is(500)->header_is(Server => 'Mojolicious (Perl)')
->header_is('X-Powered-By' => 'Mojolicious (Perl)')->content_is("doh!\n\n");

Expand All @@ -109,31 +109,32 @@ $t->get_ok('/exceptional/this_one_does_not_exist')->status_is(404)
->content_like(qr/Page not found/);

# Exceptional::this_one_does_not_exist (action behind bridge does not exist)
$t->get_ok('/exceptional_too/this_one_does_not_exist', {'X-DoNotDie' => 1})
$t->get_ok('/exceptional_too/this_one_does_not_exist' => {'X-DoNotDie' => 1})
->status_is(404)->header_is(Server => 'Mojolicious (Perl)')
->header_is('X-Powered-By' => 'Mojolicious (Perl)')
->content_like(qr/Page not found/);

# Foo::fun
$t->get_ok('/fun/time', {'X-Test' => 'Hi there!'})->status_is(200)
$t->get_ok('/fun/time' => {'X-Test' => 'Hi there!'})->status_is(200)
->header_is('X-Bender' => undef)->header_is(Server => 'Mojolicious (Perl)')
->header_is('X-Powered-By' => 'Mojolicious (Perl)')->content_is('Have fun!');

# Foo::fun
$url = $t->ua->app_url;
$url->path('/fun/time');
$t->get_ok($url, {'X-Test' => 'Hi there!'})->status_is(200)
$t->get_ok($url => {'X-Test' => 'Hi there!'})->status_is(200)
->header_is('X-Bender' => undef)->header_is(Server => 'Mojolicious (Perl)')
->header_is('X-Powered-By' => 'Mojolicious (Perl)')->content_is('Have fun!');

# Foo::fun
$t->get_ok('/happy/fun/time', {'X-Test' => 'Hi there!'})->status_is(200)
$t->get_ok('/happy/fun/time' => {'X-Test' => 'Hi there!'})->status_is(200)
->header_is('X-Bender' => undef)->header_is(Server => 'Mojolicious (Perl)')
->header_is('X-Powered-By' => 'Mojolicious (Perl)')->content_is('Have fun!');

# Foo::authenticated (authentication bridge)
$t->get_ok('/auth/authenticated', {'X-Bender' => 'Hi there!'})->status_is(200)
->header_is('X-Bender' => undef)->header_is(Server => 'Mojolicious (Perl)')
$t->get_ok('/auth/authenticated' => {'X-Bender' => 'Hi there!'})
->status_is(200)->header_is('X-Bender' => undef)
->header_is(Server => 'Mojolicious (Perl)')
->header_is('X-Powered-By' => 'Mojolicious (Perl)')
->content_is('authenticated');

Expand All @@ -144,82 +145,82 @@ $t->get_ok('/auth/authenticated')->status_is(404)
->content_like(qr/Page not found/);

# Foo::test
$t->get_ok('/foo/test', {'X-Test' => 'Hi there!'})->status_is(200)
$t->get_ok('/foo/test' => {'X-Test' => 'Hi there!'})->status_is(200)
->header_is('X-Bender' => 'Bite my shiny metal ass!')
->header_is(Server => 'Mojolicious (Perl)')
->header_is('X-Powered-By' => 'Mojolicious (Perl)')
->content_like(qr!/bar/test!);

# Foo::index
$t->get_ok('/foo', {'X-Test' => 'Hi there!'})->status_is(200)
$t->get_ok('/foo' => {'X-Test' => 'Hi there!'})->status_is(200)
->header_is(Server => 'Mojolicious (Perl)')
->header_is('X-Powered-By' => 'Mojolicious (Perl)')
->content_like(qr|<body>\s+23\nHello Mojo from the template /foo! He|);

# Foo::Bar::index
$t->get_ok('/foo-bar', {'X-Test' => 'Hi there!'})->status_is(200)
$t->get_ok('/foo-bar' => {'X-Test' => 'Hi there!'})->status_is(200)
->header_is(Server => 'Mojolicious (Perl)')
->header_is('X-Powered-By' => 'Mojolicious (Perl)')
->content_like(qr|Hello Mojo from the other template /foo-bar!|);

# Foo::something
$t->get_ok('/somethingtest', {'X-Test' => 'Hi there!'})->status_is(200)
$t->get_ok('/somethingtest' => {'X-Test' => 'Hi there!'})->status_is(200)
->header_is(Server => 'Mojolicious (Perl)')
->header_is('X-Powered-By' => 'Mojolicious (Perl)')->content_is('/test4/42');

# Foo::url_for_missing
$t->get_ok('/something_missing', {'X-Test' => 'Hi there!'})->status_is(200)
$t->get_ok('/something_missing' => {'X-Test' => 'Hi there!'})->status_is(200)
->header_is(Server => 'Mojolicious (Perl)')
->header_is('X-Powered-By' => 'Mojolicious (Perl)')
->content_is('does_not_exist');

# Foo::templateless
$t->get_ok('/foo/templateless', {'X-Test' => 'Hi there!'})->status_is(200)
$t->get_ok('/foo/templateless' => {'X-Test' => 'Hi there!'})->status_is(200)
->header_is(Server => 'Mojolicious (Perl)')
->header_is('X-Powered-By' => 'Mojolicious (Perl)')
->content_like(qr/Hello Mojo from a templateless renderer!/);

# Foo::withlayout
$t->get_ok('/foo/withlayout', {'X-Test' => 'Hi there!'})->status_is(200)
$t->get_ok('/foo/withlayout' => {'X-Test' => 'Hi there!'})->status_is(200)
->header_is(Server => 'Mojolicious (Perl)')
->header_is('X-Powered-By' => 'Mojolicious (Perl)')
->content_like(qr/Same old in green Seems to work!/);

# Foo::withblock
$t->get_ok('/foo/withblock.txt', {'X-Test' => 'Hi there!'})->status_is(200)
$t->get_ok('/foo/withblock.txt' => {'X-Test' => 'Hi there!'})->status_is(200)
->header_is(Server => 'Mojolicious (Perl)')
->header_is('X-Powered-By' => 'Mojolicious (Perl)')
->content_type_isnt('text/html')->content_type_is('text/plain')
->content_like(qr/Hello Baerbel\.\s+Hello Wolfgang\./);

# MojoliciousTest2::Foo::test
$t->get_ok('/test2', {'X-Test' => 'Hi there!'})->status_is(200)
$t->get_ok('/test2' => {'X-Test' => 'Hi there!'})->status_is(200)
->header_is('X-Bender' => 'Bite my shiny metal ass!')
->header_is(Server => 'Mojolicious (Perl)')
->header_is('X-Powered-By' => 'Mojolicious (Perl)')
->content_like(qr!/test2!);

# MojoliciousTestController::index
$t->get_ok('/test3', {'X-Test' => 'Hi there!'})->status_is(200)
$t->get_ok('/test3' => {'X-Test' => 'Hi there!'})->status_is(200)
->header_is('X-Bender' => 'Bite my shiny metal ass!')
->header_is(Server => 'Mojolicious (Perl)')
->header_is('X-Powered-By' => 'Mojolicious (Perl)')
->content_like(qr/No class works!/);

# MojoliciousTestController::index (only namespace)
$t->get_ok('/test5', {'X-Test' => 'Hi there!'})->status_is(200)
$t->get_ok('/test5' => {'X-Test' => 'Hi there!'})->status_is(200)
->header_is('X-Bender' => 'Bite my shiny metal ass!')
->header_is(Server => 'Mojolicious (Perl)')
->header_is('X-Powered-By' => 'Mojolicious (Perl)')->content_is('/test5');

# MojoliciousTestController::index (no namespace)
$t->get_ok('/test6', {'X-Test' => 'Hi there!'})->status_is(200)
$t->get_ok('/test6' => {'X-Test' => 'Hi there!'})->status_is(200)
->header_is('X-Bender' => 'Bite my shiny metal ass!')
->header_is(Server => 'Mojolicious (Perl)')
->header_is('X-Powered-By' => 'Mojolicious (Perl)')->content_is('/test6');

# 404
$t->get_ok('/', {'X-Test' => 'Hi there!'})->status_is(404)
$t->get_ok('/' => {'X-Test' => 'Hi there!'})->status_is(404)
->header_is(Server => 'Mojolicious (Perl)')
->header_is('X-Powered-By' => 'Mojolicious (Perl)')
->content_like(qr/Page not found/);
Expand Down Expand Up @@ -256,7 +257,7 @@ $t->get_ok('/../../mojolicious/secret.txt')->status_is(404)
->content_like(qr/Page not found/);

# Check If-Modified-Since
$t->get_ok('/hello.txt', {'If-Modified-Since' => $mtime})->status_is(304)
$t->get_ok('/hello.txt' => {'If-Modified-Since' => $mtime})->status_is(304)
->header_is(Server => 'Mojolicious (Perl)')
->header_is('X-Powered-By' => 'Mojolicious (Perl)')->content_is('');

Expand Down Expand Up @@ -389,7 +390,7 @@ $t->get_ok('/plugin/camel_case')->status_is(200)
->content_is('Welcome aboard!');

# MojoliciousTestController::Foo::stage2
$t->get_ok('/staged', {'X-Pass' => '1'})->status_is(200)
$t->get_ok('/staged' => {'X-Pass' => '1'})->status_is(200)
->header_is(Server => 'Mojolicious (Perl)')
->header_is('X-Powered-By' => 'Mojolicious (Perl)')
->content_is('Welcome aboard!');
Expand Down

0 comments on commit 74af25c

Please sign in to comment.