File: 09schema_options.t

package info (click to toggle)
libcatalyst-model-dbic-schema-perl 0.66-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 368 kB
  • sloc: perl: 2,984; makefile: 2
file content (53 lines) | stat: -rw-r--r-- 1,270 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
use strict;
use warnings;

use FindBin '$Bin';
use lib "$Bin/lib";

use Test::More;
use Test::Exception;
use Catalyst::Model::DBIC::Schema;
use ASchemaClass;
use AnotherSchemaClass;

# reusing the same app for 2 models, gets a redefined warning
$SIG{__WARN__} = sub { warn $_[0] unless $_[0] =~ /redefined/ };

ok((my $m = instance(a_schema_option => 'mtfnpy')), 'instance');

is $m->schema->a_schema_option, 'mtfnpy', 'option was passed from config';

lives_ok { $m->a_schema_option('pass the crack pipe') } 'delegate called';

is $m->schema->a_schema_option, 'pass the crack pipe', 'delegation works';

ok(($m = instance(schema_class => 'AnotherSchemaClass')), 'instance');

is $m->resultset('User')->rs_config_option, 'configured rs value',
    'ResultSet option passed from config';

done_testing;

sub instance {
    MyApp::Model::DB->COMPONENT('MyApp', {
        traits => 'SchemaProxy',
        schema_class => 'ASchemaClass',
        connect_info => ['dbi:SQLite:foo.db', '', ''],
        @_,
    })
}

BEGIN {
    package MyApp;
    use Catalyst;
    __PACKAGE__->config({
        'Model::DB::User' => {
            rs_config_option => 'configured rs value',
        },
    });
}

{
    package MyApp::Model::DB;
    use base 'Catalyst::Model::DBIC::Schema';
}