add test for literal SQL through accessor
[catagits/Catalyst-Model-DBIC-Schema.git] / t / 09schema_options.t
1 use strict;
2 use warnings;
3
4 use FindBin '$Bin';
5 use lib "$Bin/lib";
6
7 use Test::More;
8 use Test::Exception;
9 use Catalyst::Model::DBIC::Schema;
10 use ASchemaClass;
11 use AnotherSchemaClass;
12
13 # reusing the same app for 2 models, gets a redefined warning
14 $SIG{__WARN__} = sub { warn $_[0] unless $_[0] =~ /redefined/ };
15
16 ok((my $m = instance(a_schema_option => 'mtfnpy')), 'instance');
17
18 is $m->schema->a_schema_option, 'mtfnpy', 'option was passed from config';
19
20 lives_ok { $m->a_schema_option('pass the crack pipe') } 'delegate called';
21
22 is $m->schema->a_schema_option, 'pass the crack pipe', 'delegation works';
23
24 ok(($m = instance(schema_class => 'AnotherSchemaClass')), 'instance');
25
26 is $m->resultset('User')->rs_config_option, 'configured rs value',
27     'ResultSet option passed from config';
28
29 done_testing;
30
31 sub instance {
32     MyApp::Model::DB->COMPONENT('MyApp', {
33         traits => 'SchemaProxy',
34         schema_class => 'ASchemaClass',
35         connect_info => ['dbi:SQLite:foo.db', '', ''],
36         @_,
37     })
38 }
39
40 BEGIN {
41     package MyApp;
42     use Catalyst;
43     __PACKAGE__->config({
44         'Model::DB::User' => {
45             rs_config_option => 'configured rs value',
46         },
47     });
48 }
49
50 {
51     package MyApp::Model::DB;
52     use base 'Catalyst::Model::DBIC::Schema';
53 }