From: André Walker Date: Mon, 11 Jul 2011 15:52:01 +0000 (-0300) Subject: tests for calling controller() with no args X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Runtime.git;a=commitdiff_plain;h=e10b40fdbf404819d60169dee88175777d1bf109 tests for calling controller() with no args --- diff --git a/t/aggregate/unit_core_mvc.t b/t/aggregate/unit_core_mvc.t index 653b89f..fa1683c 100644 --- a/t/aggregate/unit_core_mvc.t +++ b/t/aggregate/unit_core_mvc.t @@ -1,6 +1,7 @@ use Test::More; use strict; use warnings; + use Moose::Meta::Class; use_ok('Catalyst'); @@ -36,7 +37,11 @@ Moose::Meta::Class->create( no warnings 'redefine'; *Catalyst::Log::warn = sub { $::warnings++ }; - *Catalyst::Utils::ensure_class_loaded = sub { $::loaded++ if Class::MOP::is_class_loaded(shift) }; + *Catalyst::Utils::ensure_class_loaded = sub { + my $class = shift; + $::loaded++ + if Class::MOP::is_class_loaded($class) && $class =~ /^MyMVCTestApp/ + }; __PACKAGE__->setup; } @@ -115,6 +120,15 @@ is ( bless ({stash=>{current_model_instance=> $model }}, 'MyMVCTestApp')->model is ( bless ({stash=>{current_model_instance=> $model, current_model=>'MyMVCTestApp::M::Model' }}, 'MyMVCTestApp')->model , $model, 'current_model_instance precedes current_model ok'); +{ + use FindBin '$Bin'; + use lib "$Bin/../lib"; + + use Catalyst::Test 'TestAppController'; + + is( get('/foo/test_controller'), 'bar', 'controller() with empty args returns current controller' ); +} + MyMVCTestApp->config->{default_view} = 'V'; is ( bless ({stash=>{}}, 'MyMVCTestApp')->view , 'MyMVCTestApp::View::V', 'default_view ok'); is ( MyMVCTestApp->view , 'MyMVCTestApp::View::V', 'default_view in class method ok'); diff --git a/t/lib/TestAppController.pm b/t/lib/TestAppController.pm new file mode 100644 index 0000000..8e65cf6 --- /dev/null +++ b/t/lib/TestAppController.pm @@ -0,0 +1,11 @@ +package TestAppController; +use Moose; +use namespace::autoclean; +use Catalyst; + +extends 'Catalyst'; + +__PACKAGE__->setup; +__PACKAGE__->meta->make_immutable; + +1; diff --git a/t/lib/TestAppController/Controller/Foo.pm b/t/lib/TestAppController/Controller/Foo.pm new file mode 100644 index 0000000..650793b --- /dev/null +++ b/t/lib/TestAppController/Controller/Foo.pm @@ -0,0 +1,21 @@ +package TestAppController::Controller::Foo; + +use Moose; +use namespace::autoclean; +BEGIN { extends 'Catalyst::Controller' }; + +has foo => ( + isa => 'Str', + is => 'ro', + default => 'bar', +); + +sub test_controller :Local { + my ( $self, $c ) = @_; + + $c->res->body( $c->controller->foo ); +} + +__PACKAGE__->meta->make_immutable; + +1;