From 1ae483c1b1a0e602a178fa7ee8b646ac37f4e252 Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Tue, 4 Oct 2011 10:28:54 -0500 Subject: a few more tests --- t/data/route/templates/baz/index.tt | 1 + t/route.t | 71 +++++++++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+) create mode 100644 t/data/route/templates/baz/index.tt diff --git a/t/data/route/templates/baz/index.tt b/t/data/route/templates/baz/index.tt new file mode 100644 index 0000000..8d5f284 --- /dev/null +++ b/t/data/route/templates/baz/index.tt @@ -0,0 +1 @@ +Hello world: [% m.data %] diff --git a/t/route.t b/t/route.t index 722121b..ff67ac6 100644 --- a/t/route.t +++ b/t/route.t @@ -113,4 +113,75 @@ test_psgi } }; +{ + package Baz::Controller; + use Moose; + + has view => ( + is => 'ro', + isa => 'OX::View::TT', + required => 1, + handles => ['render'], + ); + + sub index { + my $self = shift; + my ($r) = @_; + + $self->render($r, 'index.tt'); + } +} + +{ + package Baz; + use OX; + + has template_root => ( + is => 'ro', + isa => 'Str', + block => sub { + Path::Class::dir($FindBin::Bin)->subdir('data', 'route', 'templates', 'baz')->stringify + }, + ); + + has view => ( + is => 'ro', + isa => 'OX::View::TT', + dependencies => ['template_root'], + ); + + has controller => ( + is => 'ro', + isa => 'Baz::Controller', + dependencies => ['view'], + ); + + router as { + route '/' => 'view.template', ( + template => 'index.tt', + data => 'index', + ); + route '/foo' => 'controller.index', ( + data => 'foo', + ); + }; +} + +test_psgi + app => Baz->new->to_app, + client => sub { + my $cb = shift; + + { + my $res = $cb->(GET 'http://localhost/'); + is($res->code, 200, "right code"); + is($res->content, "Hello world: index\n", "right content"); + } + { + my $res = $cb->(GET 'http://localhost/foo'); + is($res->code, 200, "right code"); + is($res->content, "Hello world: foo\n", "right content"); + } + }; + done_testing; -- cgit v1.2.3-54-g00ecf