Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
a few more post_ok examples
  • Loading branch information
kraih committed Feb 13, 2013
1 parent fdd8654 commit d277d66
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 6 deletions.
4 changes: 2 additions & 2 deletions Changes
Expand Up @@ -14,8 +14,8 @@
- Deprecated Test::Mojo->post_json_ok in favor of Test::Mojo->post_ok.
- Deprecated ojo->f in favor of ojo->p.
- Deprecated ojo->n in favor of ojo->p.
- Added pluggable content generator system to Mojo::UserAgent::Transactor.
(judofyr, sri)
- Added support for pluggable content generators to
Mojo::UserAgent::Transactor. (judofyr, sri)
- Added generators attribute to Mojo::UserAgent::Transactor.
- Added add_generator method to Mojo::UserAgent::Transactor.
- Updated jQuery to version 1.9.1.
Expand Down
2 changes: 1 addition & 1 deletion lib/Mojolicious/Controller.pm
Expand Up @@ -913,7 +913,7 @@ Get L<Mojo::UserAgent> object from L<Mojo/"ua">.
# Blocking
my $tx = $c->ua->get('http://mojolicio.us');
my $tx = $c->ua->post('http://kraih.com/login', form => {user => 'mojo'});
my $tx = $c->ua->post('http://kraih.com/login' => form => {user => 'mojo'});
# Non-blocking
$c->ua->get('http://mojolicio.us' => sub {
Expand Down
4 changes: 2 additions & 2 deletions lib/Mojolicious/Guides/Growing.pod
Expand Up @@ -300,7 +300,7 @@ on L<Mojo::DOM>.
->element_exists('form input[type="submit"]');

# Test login with valid credentials
$t->post_ok('/', form => {user => 'sri', pass => 'secr3t'})
$t->post_ok('/' => form => {user => 'sri', pass => 'secr3t'})
->status_is(200)->text_like('html body' => qr/Welcome sri/);

# Test accessing a protected page
Expand Down Expand Up @@ -673,7 +673,7 @@ C<t/login.t> can be simplified.
->element_exists('form input[name="pass"]')
->element_exists('form input[type="submit"]');

$t->post_ok('/', form => {user => 'sri', pass => 'secr3t'})
$t->post_ok('/' => form => {user => 'sri', pass => 'secr3t'})
->status_is(200)->text_like('html body' => qr/Welcome sri/);

$t->get_ok('/protected')->status_is(200)->text_like('a' => qr/Logout/);
Expand Down
2 changes: 1 addition & 1 deletion lib/Mojolicious/Guides/Routing.pod
Expand Up @@ -634,7 +634,7 @@ Same for monitoring tasks.
$self->hook(after_dispatch => sub {
my $self = shift;
return unless my $e = $self->stash('exception');
$self->ua->post('https://kraih.com/bugs', form => {exception => $e});
$self->ua->post('https://kraih.com/bugs' => form => {exception => $e});
});

For a full list of available hooks see L<Mojolicious/"hook">.
Expand Down
9 changes: 9 additions & 0 deletions lib/Test/Mojo.pm
Expand Up @@ -794,6 +794,15 @@ arguments as L<Mojo::UserAgent/"patch">.
Perform a C<POST> request and check for transport errors, takes the same
arguments as L<Mojo::UserAgent/"post">.
# Test file upload
$t->post_ok('/upload' => form => {foo => {content => 'bar'}})
->status_is(200);
# Test JSON API
$t->post_json_ok('/hello.json' => json => {hello => 'world'})
->status_is(200)
->json_content_is({bye => 'world'});
=head2 put_ok
$t = $t->put_ok('/foo');
Expand Down

0 comments on commit d277d66

Please sign in to comment.