From c2e2cf74cfdc05d58a0270d398c643631131952c Mon Sep 17 00:00:00 2001 From: t0m Date: Thu, 18 Jun 2009 08:48:10 +0100 Subject: [PATCH] Test local config works --- lib/TestConfig.pm | 9 +++++---- lib/TestConfig/Controller/Root.pm | 2 ++ t/01app.t | 10 ++++++++-- testconfig_local.conf | 4 ++++ 4 files changed, 19 insertions(+), 6 deletions(-) create mode 100644 testconfig_local.conf diff --git a/lib/TestConfig.pm b/lib/TestConfig.pm index bd19f4e..e99b9e2 100644 --- a/lib/TestConfig.pm +++ b/lib/TestConfig.pm @@ -1,7 +1,6 @@ package TestConfig; - -use strict; -use warnings; +use Moose; +use namespace::autoclean; use Catalyst::Runtime 5.80; @@ -13,7 +12,7 @@ use Catalyst::Runtime 5.80; # Static::Simple: will serve static files from the application's root # directory -use parent qw/Catalyst/; +extends qw/Catalyst/; use Catalyst qw/-Debug ConfigLoader Static::Simple/; @@ -30,6 +29,8 @@ our $VERSION = '0.01'; __PACKAGE__->config( name => 'TestConfig' ); +has name => ( isa => 'Str', is => 'ro' ); + # Start the application __PACKAGE__->setup(); diff --git a/lib/TestConfig/Controller/Root.pm b/lib/TestConfig/Controller/Root.pm index 3fddd9f..5090272 100644 --- a/lib/TestConfig/Controller/Root.pm +++ b/lib/TestConfig/Controller/Root.pm @@ -31,6 +31,8 @@ sub index :Path :Args(0) { # Hello World $c->response->body( $c->welcome_message ); + + $c->stash->{appname} = $c->name; } sub default :Path { diff --git a/t/01app.t b/t/01app.t index 03c84b3..8fd348c 100644 --- a/t/01app.t +++ b/t/01app.t @@ -1,8 +1,14 @@ #!/usr/bin/env perl use strict; use warnings; -use Test::More tests => 2; +use Test::More tests => 3; BEGIN { use_ok 'Catalyst::Test', 'TestConfig' } -ok( request('/')->is_success, 'Request should succeed' ); +my ($res, $c) = ctx_request('/'); +ok $res->is_success; +is $c->config->{name}, 'SomeOtherApp'; # Here it is in config +is $c->name, 'SomeOtherApp'; # Config passed to constructor, so in + # attribute +is $c->stash->{appname}, 'SomeOtherApp'; # And there it is in the stash.. + diff --git a/testconfig_local.conf b/testconfig_local.conf new file mode 100644 index 0000000..0e34673 --- /dev/null +++ b/testconfig_local.conf @@ -0,0 +1,4 @@ +# rename this file to TestConfig.yml and put a ':' in front of 'name' if +# you want to use YAML like in old versions of Catalyst +name SomeOtherApp + -- 1.6.2.1