[Catalyst] myapp_local.yml gets ignored

Jochen Luig jochen.luig at skytel.de
Wed Jun 17 13:50:01 GMT 2009


Hi,

I'm currently writing tests for an application. To be able to test with
a live database, I wrote a test database package along the lines of the
example in chapter 8 (page 165) of Johnathan's Catalyst book:

package MyApp::Test::Database::Live;

use strict;
use warnings;

use MyAppDB;
use MyApp::Model::MyAppDB;
use Directory::Scratch;
use YAML qw( DumpFile );
use FindBin qw( $Bin );
use Digest::SHA1 qw( sha1_hex );
use HTTP::Request;

use base 'Exporter';
our @EXPORT = qw /schema log_in /;
my $schema;
my $config;

BEGIN {
    my $tmp = Directory::Scratch->new;
    my $db = $tmp->touch('db');
    my $dsn = "DBI:SQLite:$db";
    $schema = MyAppDB->connect($dsn);
    $schema->deploy;
    $config = "$Bin/../myapp_local.yml";
    DumpFile($config, { 'MyApp::Model::MyAppDB' => { connect_info =>
[$dsn]}});
    DumpFile('/home/jochen/location.txt', { 'path' => $config });
}

sub schema { $schema };

sub log_in {
    my $mech = shift;

    my $obj = '{ "login": "testuser", "password": "testing"}' . "\n";
    my $dummy = [ 'Content-type' => 'application/json', 'Content-Length'
=> length($obj) ];
    my $user = schema()->resultset('MyAppDB::User')->create({
        login => 'testuser',
        password => sha1_hex('testing'),
        #password => 'testing',
        mail => 'testuser at mydomain.com',
        first_name => 'Max',
        last_name => 'Mustermann',
        company => 'mycompany',
        customer_id => '002096',
    });
    my $req = HTTP::Request->new('POST',
'http://localhost/rest/login/login', $dummy, $obj);
    $mech->request($req);
    return $user;
}

END { unlink $config };

1;

When the login request failed, I first thought it had to do with the
authentication process. But when there was a change in the db schema
that I hadn't made accordingly in my local mysql database, the test
script complained about the columns not present in the database. So the
myapp_local.yml seems to get ignored. OTOH, the test user is not created
in that database.
According to the ConfigLoader docs, 'local' is the default suffix for
files used to override the main config, so AFAIU the above code is
supposed to "just work". 
Maybe I'm just not seeing the wood for the trees here, but are there any
prerequisites for this to work that I may have overlooked?

Jochen




More information about the Catalyst mailing list