preserve $c->state
[catagits/Catalyst-Runtime.git] / t / state.t
CommitLineData
e459bd03 1use warnings;
2use strict;
3use Test::More;
4use HTTP::Request::Common;
5
6{
7 package MyApp::Controller::Root;
8 $INC{'MyApp/Controller/Root.pm'} = __FILE__;
9
10 use base 'Catalyst::Controller';
11
12 MyApp::Controller::Root->config(namespace=>'');
13
14 sub begin :Action {
15 my ($self, $c) = @_;
16 Test::More::is($c->state, 0);
17 return 'begin';
18 }
19
20 sub auto :Action {
21 my ($self, $c) = @_;
22 Test::More::is($c->state, 'begin'); # default state of 1 is new to 9.0102
23 return 'auto';
24
25 }
26
27 sub base :Chained('/') PathPrefix CaptureArgs(0) {
28 my ($self, $c) = @_;
29 Test::More::is($c->state, 'auto');
30 return 10;
31 }
32
33 sub one :Chained('base') PathPart('') CaptureArgs(0) {
34 my ($self, $c) = @_;
35 Test::More::is($c->state, 10);
36 return 20;
37 }
38
39 sub two :Chained('one') PathPart('') Args(1) {
40 my ($self, $c, $arg) = @_;
41 Test::More::is($c->state, 20);
42 my $ret = $c->forward('forward2');
43 Test::More::is($ret, 25);
44 Test::More::is($c->state, 25);
45 return 30;
46 }
47
48 sub end :Action {
49 my ($self, $c) = @_;
50 Test::More::is($c->state, 30);
51 my $ret = $c->forward('forward1');
52 Test::More::is($ret, 100);
53 Test::More::is($c->state, 100);
54 $c->detach('detach1');
55 }
56
57 sub forward1 :Action {
58 my ($self, $c) = @_;
59 Test::More::is($c->state, 30);
60 return 100;
61 }
62
63 sub forward2 :Action {
64 my ($self, $c) = @_;
65 Test::More::is($c->state, 20);
66 return 25;
67 }
68
69 sub detach1 :Action {
70 my ($self, $c) = @_;
71 Test::More::is($c->state, 100);
72 }
73
74 package MyApp;
75 use Catalyst;
76
77 MyApp->config(show_internal_actions=>1);
78 MyApp->setup;
79}
80
81use Catalyst::Test 'MyApp';
82
83{
84 ok my $res = request "/100";
85}
86
87done_testing;