File: 05-schema-aliases.t

package info (click to toggle)
libdancer-plugin-dbic-perl 0.2104-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 176 kB
  • sloc: perl: 48; makefile: 2
file content (44 lines) | stat: -rw-r--r-- 1,095 bytes parent folder | download | duplicates (6)
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
use Test::More tests => 4;

use lib 't/lib';

use Dancer::Plugin::DBIC qw(rset schema);
use Dancer qw(:syntax :tests);
use Test::Exception;

eval { require DBD::SQLite };
plan skip_all => 'DBD::SQLite required to run these tests' if $@;

set plugins => {
    DBIC => {
        default => {
            schema_class => 'Foo',
            dsn          =>  'dbi:SQLite:dbname=:memory:',
        },
        foo => {
            alias => 'default',
        },
        badalias => {
            alias => 'zzz',
        },
    }
};

schema->deploy;
ok rset('User')->create({ name => 'bob', age => 30 });

subtest 'default schema' => sub {
    ok my $user = rset('User')->find('bob'), 'found bob';
    is $user->age => '30', 'bob is getting old';
};

subtest 'schema alias' => sub {
    ok my $user = schema('foo')->resultset('User')->find('bob'), 'found bob';
    is $user->age => '30', 'bob is still old';
};

subtest 'bad alias' => sub {
    throws_ok { schema('badalias')->resultset('User')->find('bob') }
        qr/schema alias zzz does not exist in the config/,
        'got bad alias error';
};