File: 03-dynamic-schemas.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 (39 lines) | stat: -rw-r--r-- 945 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
# Test dynamic schema loading by not providing a schema_class config option.
# These tests require DBIx::Class::Schema::Loader to be installed

use strict;
use warnings;
use Test::More tests => 3;

use Dancer qw(:syntax !pass);
use Dancer::Plugin::DBIC;
use DBI;
use File::Temp qw(tempfile);
use Test::Requires qw(
    DBD::SQLite DBIx::Class::Schema::Loader
);

my (undef, $dbfile) = tempfile SUFFIX => '.db';

set plugins => {
    DBIC => {
        foo => {
            dsn =>  "dbi:SQLite:dbname=$dbfile",
        }
    }
};

my $dbh = DBI->connect("dbi:SQLite:dbname=$dbfile");
ok $dbh->do(q{
    create table user (name varchar(100) primary key, age int)
}), 'Created sqlite test db.';

my @users = ( ['bob', 40] );
for my $user (@users) { $dbh->do('insert into user values(?,?)', {}, @$user) }

my $user = schema('foo')->resultset('User')->find('bob');

ok $user, 'Found bob.';
is $user->age => '40', 'bob is even older';

unlink $dbfile;