Much cleaner. The visit class test wasn't actually testing visiting the class, so...
[catagits/Catalyst-Runtime.git] / t / lib / TestApp / Controller / Action / Visit.pm
1 package TestApp::Controller::Action::Visit;
2
3 use strict;
4 use base 'TestApp::Controller::Action';
5
6 sub one : Local {
7     my ( $self, $c ) = @_;
8     $c->visit('two');
9 }
10
11 sub two : Private {
12     my ( $self, $c ) = @_;
13     $c->visit('three');
14 }
15
16 sub three : Local {
17     my ( $self, $c ) = @_;
18     $c->visit( $self, 'four' );
19 }
20
21 sub four : Private {
22     my ( $self, $c ) = @_;
23     $c->visit('/action/visit/five');
24 }
25
26 sub five : Local {
27     my ( $self, $c ) = @_;
28     $c->forward('View::Dump::Request');
29 }
30
31 sub inheritance : Local {
32     my ( $self, $c ) = @_;
33     $c->visit('/action/inheritance/a/b/default');
34 }
35
36 sub global : Local {
37     my ( $self, $c ) = @_;
38     $c->visit('/global_action');
39 }
40
41 sub with_args : Local {
42     my ( $self, $c, $arg ) = @_;
43     $c->visit( 'args', [$arg] );
44 }
45
46 sub with_method_and_args : Local {
47     my ( $self, $c, $arg ) = @_;
48     $c->visit( qw/TestApp::Controller::Action::Visit args/, [$arg] );
49 }
50
51 sub args : Local {
52     my ( $self, $c, $val ) = @_;
53     die "passed argument does not match args" unless $val eq $c->req->args->[0];
54     $c->res->body($val);
55 }
56
57 sub visit_die : Local {
58     my ( $self, $c, $val ) = @_;
59     eval { $c->visit( 'args', [qq/new/] ) };
60     $c->res->body( $@ ? $@ : "visit() doesn't die" );
61 }
62
63 sub visit_chained : Local {
64     my ( $self, $c, $val, $capture, @args ) = @_;
65     my @cap_and_args = ([$capture], [@args]);
66       $val eq 1 ? $c->visit( '/action/chained/foo/spoon',                                 @cap_and_args)
67     : $val eq 2 ? $c->visit( qw/ Action::Chained::Foo spoon /,                            @cap_and_args)
68     :             $c->visit( $c->controller('Action::Chained::Foo')->action_for('spoon'), @cap_and_args)
69 }
70
71 sub view : Local {
72     my ( $self, $c, $val ) = @_;
73     eval { $c->visit('View::Dump') };
74     $c->res->body( $@ ? $@ : "visit() did not die" );
75 }
76
77 sub model : Local {
78     my ( $self, $c, $val ) = @_;
79     eval { $c->visit('Model::Foo') };
80     $c->res->body( $@ ? $@ : "visit() did not die" );
81 }
82
83 sub args_embed_relative : Local {
84     my ( $self, $c ) = @_;
85     $c->visit('embed/ok');
86 }
87
88 sub args_embed_absolute : Local {
89     my ( $self, $c ) = @_;
90     $c->visit('/action/visit/embed/ok');
91 }
92
93 sub embed : Local {
94     my ( $self, $c, $ok ) = @_;
95     $ok ||= 'not ok';
96     $c->res->body($ok);
97 }
98
99 sub class_visit_test_action : Local {
100     my ( $self, $c ) = @_;
101     $c->visit(qw/TestApp/);
102 }
103
104 1;