Skip to content

Commit

Permalink
more helper tests with state variables
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Jan 21, 2013
1 parent c7b4d67 commit 8696a62
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Changes
@@ -1,5 +1,5 @@

3.83 2013-01-21
3.83 2013-01-22
- Improved documentation.
- Improved tests.

Expand Down
12 changes: 12 additions & 0 deletions t/mojolicious/embedded_lite_app.t
Expand Up @@ -235,12 +235,24 @@ $t->get_ok('/x/♥/template/does_not_exist')->status_is(404);
# A little bit of everything from myapp2.pl
$t->get_ok('/y/1')->status_is(200)->content_is("works 4!\nInsecure too!");

# Caching helper from myapp2.pl
$t->get_ok('/y/1/cached?cache=foo')->status_is(200)->content_is('foo');

# Caching helper with cached value from myapp2.pl
$t->get_ok('/y/1/cached?cache=fail')->status_is(200)->content_is('foo');

# 404 from myapp2.pl
$t->get_ok('/y/1/2')->status_is(404);

# myapp2.pl with unicode prefix
$t->get_ok('/y/♥')->status_is(200)->content_is("works 3!\nInsecure too!");

# Caching helper from myapp2.pl with unicode prefix
$t->get_ok('/y/♥/cached?cache=bar')->status_is(200)->content_is('bar');

# Caching helper with cached value from myapp2.pl with unicode prefix
$t->get_ok('/y/♥/cached?cache=fail')->status_is(200)->content_is('bar');

# 404 from myapp2.pl with unicode prefix
$t->get_ok('/y/♥/2')->status_is(404);

Expand Down
8 changes: 8 additions & 0 deletions t/mojolicious/external/myapp2.pl
Expand Up @@ -6,6 +6,9 @@
# Default for config file tests
app->defaults(secret => 'Insecure too!');

# Caching helper for state variable test
helper my_cache => sub { state $cache = shift->param('cache') };

# Delay dispatching
hook around_dispatch => sub {
my ($next, $c) = @_;
Expand All @@ -18,6 +21,11 @@
$self->render_partial('menubar') . app->defaults->{secret});
};

get '/cached' => sub {
my $self = shift;
$self->render(text => $self->my_cache);
};

app->start;
__DATA__
Expand Down

0 comments on commit 8696a62

Please sign in to comment.