update version info
[catagits/Catalyst-Runtime.git] / t / middleware-stash.t
1 use warnings;
2 use strict;
3
4 {
5
6   package MyAppChild::Controller::User;
7   $INC{'MyAppChild/Controller/User.pm'} = __FILE__;
8
9   use base 'Catalyst::Controller';
10   use Test::More;
11
12   sub stash :Local {
13     my ($self, $c) = @_;
14     $c->stash->{inner} = "inner";
15     $c->res->body( "inner: ${\$c->stash->{inner}}, outer: ${\$c->stash->{outer}}");
16
17     is_deeply [sort {$a cmp $b} keys(%{$c->stash})], ['inner','outer'], 'both keys in stash';
18   }
19
20   package MyAppChild;
21   $INC{'MyAppChild.pm'} = __FILE__;
22
23   use Catalyst;
24   MyAppChild->setup;
25
26   package MyAppParent::Controller::User;
27   $INC{'MyAppParent/Controller/User.pm'} = __FILE__;
28
29   use base 'Catalyst::Controller';
30   use Test::More;
31
32   sub stash :Local {
33     my ($self, $c) = @_;
34     $c->stash->{outer} = "outer";
35     $c->res->from_psgi_response( MyAppChild->to_app->($c->req->env) );
36
37     is_deeply [keys(%{$c->stash})], ['outer'], 'only one key in stash';
38   }
39
40   package MyAppParent;
41   use Catalyst;
42   MyAppParent->setup;
43
44 }
45
46 use Test::More;
47 use Catalyst::Test 'MyAppParent';
48
49 my $res = request '/user/stash';
50 is $res->content, 'inner: inner, outer: outer', 'got expected response';
51
52 done_testing;