added test for ->view() with one view not returning a blessed instance
Rafael Kitover [Tue, 9 Jun 2009 12:46:43 +0000 (12:46 +0000)]
t/aggregate/live_component_view_single.t [new file with mode: 0644]
t/lib/TestAppOneView.pm [new file with mode: 0644]
t/lib/TestAppOneView/Controller/Root.pm [new file with mode: 0644]
t/lib/TestAppOneView/View/Dummy.pm [new file with mode: 0644]

diff --git a/t/aggregate/live_component_view_single.t b/t/aggregate/live_component_view_single.t
new file mode 100644 (file)
index 0000000..6c50c18
--- /dev/null
@@ -0,0 +1,33 @@
+#!perl
+
+use strict;
+use warnings;
+
+use FindBin;
+use lib "$FindBin::Bin/../lib";
+
+our $iters;
+
+BEGIN { $iters = $ENV{CAT_BENCH_ITERS} || 1; }
+
+use Test::More tests => 3*$iters;
+use Catalyst::Test 'TestAppOneView';
+
+if ( $ENV{CAT_BENCHMARK} ) {
+    require Benchmark;
+    Benchmark::timethis( $iters, \&run_tests );
+}
+else {
+    for ( 1 .. $iters ) {
+        run_tests();
+    }
+}
+
+sub run_tests {
+    {
+        is(get('/view_by_name?view=Dummy'), 'TestAppOneView::View::Dummy',
+            '$c->view("name") returns blessed instance');
+        is(get('/view_no_args'), 'TestAppOneView::View::Dummy',
+            '$c->view() returns blessed instance');
+    }
+}
diff --git a/t/lib/TestAppOneView.pm b/t/lib/TestAppOneView.pm
new file mode 100644 (file)
index 0000000..59354b3
--- /dev/null
@@ -0,0 +1,8 @@
+package TestAppOneView;
+use strict;
+use warnings;
+use Catalyst;
+
+__PACKAGE__->setup;
+
+1;
diff --git a/t/lib/TestAppOneView/Controller/Root.pm b/t/lib/TestAppOneView/Controller/Root.pm
new file mode 100644 (file)
index 0000000..1da451c
--- /dev/null
@@ -0,0 +1,24 @@
+package TestAppOneView::Controller::Root;
+
+use base 'Catalyst::Controller';
+use Scalar::Util ();
+
+__PACKAGE__->config->{namespace} = '';
+
+sub view_no_args : Local {
+    my ( $self, $c ) = @_;
+
+    my $v = $c->view;
+
+    $c->res->body(Scalar::Util::blessed($v));
+}
+
+sub view_by_name : Local {
+    my ( $self, $c ) = @_;
+
+    my $v = $c->view($c->req->param('view'));
+
+    $c->res->body(Scalar::Util::blessed($v));
+}
+
+1;
diff --git a/t/lib/TestAppOneView/View/Dummy.pm b/t/lib/TestAppOneView/View/Dummy.pm
new file mode 100644 (file)
index 0000000..bba0855
--- /dev/null
@@ -0,0 +1,5 @@
+package TestAppOneView::View::Dummy;
+
+use base 'Catalyst::View';
+
+1;