Add test that env does not get trampled
Arthur Axel 'fREW' Schmidt [Thu, 13 Aug 2015 23:23:20 +0000 (16:23 -0700)]
Changes
t/middleware-stash.t

diff --git a/Changes b/Changes
index 92d65c0..452584f 100644 (file)
--- a/Changes
+++ b/Changes
@@ -1,5 +1,7 @@
 # This file documents the revision history for Perl extension Catalyst.
 
+  - Add test that env does not get trampled (Arthur Axel fREW Schmidt)
+
 5.90098 - 2015-08-11
   - Fix for RT#106373 (Issue when you try to install and also have an old
   verion of Test::Mechanize::WWW::Catalyst)
index baeb108..24b95f2 100644 (file)
@@ -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';
   }
 
@@ -48,5 +72,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;