X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Runtime.git;a=blobdiff_plain;f=t%2Fmiddleware-stash.t;h=dc22ab6f5acb7c45545faa01d36519d6781b1b26;hp=baeb1083c59716c197d191a156bade826372942f;hb=8e322ed0b39da75b8d888025782f496ca781527f;hpb=efa13fa482395db0a40aafba7e198e43759a5dc6 diff --git a/t/middleware-stash.t b/t/middleware-stash.t index baeb108..dc22ab6 100644 --- a/t/middleware-stash.t +++ b/t/middleware-stash.t @@ -3,6 +3,28 @@ use strict; { + package MyMiddleware; + $INC{'MyMiddleware'} = __FILE__; + + our $INNER_VAR_EXPOSED; + + use base 'Plack::Middleware'; + + sub call { + my ($self, $env) = @_; + + my $res = $self->app->($env); + + return $self->response_cb($res, sub{ + my $inner = shift; + + $INNER_VAR_EXPOSED = $env->{inner_var_from_catalyst}; + + return; + }); + + } + package MyAppChild::Controller::User; $INC{'MyAppChild/Controller/User.pm'} = __FILE__; @@ -14,6 +36,8 @@ use strict; $c->stash->{inner} = "inner"; $c->res->body( "inner: ${\$c->stash->{inner}}, outer: ${\$c->stash->{outer}}"); + $c->req->env->{inner_var_from_catalyst} = 'station'; + is_deeply [sort {$a cmp $b} keys(%{$c->stash})], ['inner','outer'], 'both keys in stash'; } @@ -34,11 +58,12 @@ use strict; $c->stash->{outer} = "outer"; $c->res->from_psgi_response( MyAppChild->to_app->($c->req->env) ); - is_deeply [keys(%{$c->stash})], ['outer'], 'only one key in stash'; + is_deeply [sort keys(%{$c->stash})], ['inner','outer']; } package MyAppParent; use Catalyst; + MyAppParent->config(psgi_middleware=>['+MyMiddleware']); MyAppParent->setup; } @@ -48,5 +73,6 @@ use Catalyst::Test 'MyAppParent'; my $res = request '/user/stash'; is $res->content, 'inner: inner, outer: outer', 'got expected response'; +is $MyMiddleware::INNER_VAR_EXPOSED, 'station', 'env does not get trampled'; done_testing;