Commit | Line | Data |
08aa0414 |
1 | use lib qw(lib t/lib); |
2 | use DBICTest::Schema; |
3 | |
4 | use Test::More; |
5 | |
6 | my ($dsn, $user, $pass) = @ENV{map { "DBICTEST_MYSQL_${_}" } qw/DSN USER PASS/}; |
7 | |
cba994a1 |
8 | #warn "$dsn $user $pass"; |
08aa0414 |
9 | |
10 | plan skip_all, 'Set $ENV{DBICTEST_MYSQL_DSN}, _USER and _PASS to run this test' |
11 | unless ($dsn && $user); |
12 | |
13 | plan tests => 1; |
14 | |
15 | DBICTest::Schema->compose_connection('MySQLTest' => $dsn, $user, $pass); |
16 | |
17 | my $dbh = MySQLTest::Artist->storage->dbh; |
18 | |
19 | $dbh->do("DROP TABLE IF EXISTS artist;"); |
20 | |
21 | $dbh->do("CREATE TABLE artist (artistid INTEGER NOT NULL AUTO_INCREMENT PRIMARY KEY, name VARCHAR(255));"); |
22 | |
23 | #'dbi:mysql:host=localhost;database=dbic_test', 'dbic_test', ''); |
24 | |
25 | MySQLTest::Artist->load_components('PK::Auto::MySQL'); |
26 | |
502784de |
27 | # test primary key handling |
08aa0414 |
28 | my $new = MySQLTest::Artist->create({ name => 'foo' }); |
08aa0414 |
29 | ok($new->artistid, "Auto-PK worked"); |
30 | |
502784de |
31 | # test LIMIT support |
32 | for (1..6) { |
33 | MySQLTest::Artist->create({ name => 'Artist ' . $_ }); |
34 | } |
35 | my $it = MySQLTest::Artist->search( {}, |
36 | { rows => 3, |
37 | offset => 2, |
38 | order_by => 'artistid' } |
39 | ); |
40 | is( $it->count, 3, "LIMIT count ok" ); |
41 | is( $it->next->name, "Artist 2", "iterator->next ok" ); |
42 | $it->next; |
43 | $it->next; |
44 | is( $it->next, undef, "next past end of resultset ok" ); |
45 | |
46 | # clean up our mess |
47 | $dbh->do("DROP TABLE artist"); |
48 | |
08aa0414 |
49 | 1; |