sub insert {
my ($self) = @_;
- warn "Got here";
for my $column (@{$self->uuid_auto_columns}) {
$self->store_column( $column, $self->get_uuid )
unless defined $self->get_column( $column );
plan tests => 29;
-my @art = DBICTest::Artist->search({ }, { order_by => 'name DESC'});
+my @art = DBICTest->class("Artist")->search({ }, { order_by => 'name DESC'});
cmp_ok(@art, '==', 3, "Three artists returned");
ok($art->update, 'Update run');
-@art = DBICTest::Artist->search({ name => 'We Are In Rehab' });
+@art = DBICTest->class("Artist")->search({ name => 'We Are In Rehab' });
cmp_ok(@art, '==', 1, "Changed artist returned by search");
$art->delete;
-@art = DBICTest::Artist->search({ });
+@art = DBICTest->class("Artist")->search({ });
cmp_ok(@art, '==', 2, 'And then there were two');
ok($art->in_storage, "Re-created");
-@art = DBICTest::Artist->search({ });
+@art = DBICTest->class("Artist")->search({ });
cmp_ok(@art, '==', 3, 'And now there are three again');
-my $new = DBICTest::Artist->create({ artistid => 4 });
+my $new = DBICTest->class("Artist")->create({ artistid => 4 });
cmp_ok($new->artistid, '==', 4, 'Create produced record ok');
-@art = DBICTest::Artist->search({ });
+@art = DBICTest->class("Artist")->search({ });
cmp_ok(@art, '==', 4, "Oh my god! There's four of them!");
$new->update;
-$new_again = DBICTest::Artist->find(4);
+$new_again = DBICTest->class("Artist")->find(4);
is($new_again->name, 'Man With A Spoon', 'Retrieved correctly');
is($new_again->ID, 'DBICTest::Artist|artistid=4', 'unique object id generated correctly');
-is(DBICTest::Artist->count, 4, 'count ok');
+is(DBICTest->class("Artist")->count, 4, 'count ok');
-my $cd = DBICTest::CD->find(1);
+my $cd = DBICTest->class("CD")->find(1);
my %cols = $cd->get_columns;
cmp_ok(keys %cols, '==', 4, 'get_columns number of columns ok');
$cd->discard_changes;
-$cd = DBICTest::CD->search({ title => 'Spoonful of bees' }, { cols => ['title'] })->next;
+$cd = DBICTest->class("CD")->search({ title => 'Spoonful of bees' }, { cols => ['title'] })->next;
is($cd->title, 'Spoonful of bees', 'subset of columns returned correctly');
# insert_or_update
-$new = DBICTest::Track->new( {
+$new = DBICTest->class("Track")->new( {
trackid => 100,
cd => 1,
position => 1,
# test in update mode
$new->position(5);
$new->insert_or_update;
-is( DBICTest::Track->find(100)->position, 5, 'insert_or_update update ok');
+is( DBICTest->class("Track")->find(100)->position, 5, 'insert_or_update update ok');
-eval { DBICTest::Track->load_components('DoesNotExist'); };
+eval { DBICTest->class("Track")->load_components('DoesNotExist'); };
ok $@, $@;
-is(DBICTest::Artist->field_name_for->{name}, 'artist name', 'mk_classdata usage ok');
+is(DBICTest->class("Artist")->field_name_for->{name}, 'artist name', 'mk_classdata usage ok');
}
# add some rows inside a transaction and commit it
# XXX: Is storage->dbh the only way to get a dbh?
-DBICTest::Artist->txn_begin;
+DBICTest->class("Artist")->txn_begin;
for (10..15) {
- DBICTest::Artist->create( {
+ DBICTest->class("Artist")->create( {
artistid => $_,
name => "artist number $_",
} );
}
-DBICTest::Artist->txn_commit;
-my ($artist) = DBICTest::Artist->find(15);
+DBICTest->class("Artist")->txn_commit;
+my ($artist) = DBICTest->class("Artist")->find(15);
is($artist->name, 'artist number 15', "Commit ok");
# add some rows inside a transaction and roll it back
-DBICTest::Artist->txn_begin;
+DBICTest->class("Artist")->txn_begin;
for (21..30) {
- DBICTest::Artist->create( {
+ DBICTest->class("Artist")->create( {
artistid => $_,
name => "artist number $_",
} );
}
-DBICTest::Artist->txn_rollback;
-($artist) = DBICTest::Artist->search( artistid => 25 );
+DBICTest->class("Artist")->txn_rollback;
+($artist) = DBICTest->class("Artist")->search( artistid => 25 );
is($artist, undef, "Rollback ok");
}
plan tests => 3;
-ok(DBICTest::FourKeys->find(1,2,3,4), "find multiple pks without hash");
-ok(DBICTest::FourKeys->find(5,4,3,6), "find multiple pks without hash");
+ok(DBICTest->class("FourKeys")->find(1,2,3,4), "find multiple pks without hash");
+ok(DBICTest->class("FourKeys")->find(5,4,3,6), "find multiple pks without hash");
-is(DBICTest::FourKeys->find(1,2,3,4)->ID, 'DBICTest::FourKeys|bar=2|foo=1|goodbye=4|hello=3', 'unique object id ok for multiple pks');
+is(DBICTest->class("FourKeys")->find(1,2,3,4)->ID, 'DBICTest::FourKeys|bar=2|foo=1|goodbye=4|hello=3', 'unique object id ok for multiple pks');
}
plan tests => 13;
# has_a test
-my $cd = DBICTest::CD->find(4);
+my $cd = DBICTest->class("CD")->find(4);
my ($artist) = ($INC{'DBICTest/HelperRels'}
? $cd->artist
: $cd->search_related('artist'));
is($artist->name, 'Random Boy Band', 'has_a search_related ok');
# has_many test with an order_by clause defined
-$artist = DBICTest::Artist->find(1);
+$artist = DBICTest->class("Artist")->find(1);
my @cds = ($INC{'DBICTest/HelperRels'}
? $artist->cds
: $artist->search_related('cds'));
is( $artist->count_related('cds'), 4, 'count_related ok' );
# set_from_related
-my $track = DBICTest::Track->create( {
+my $track = DBICTest->class("Track")->create( {
trackid => 1,
cd => 3,
position => 98,
}
# update_from_related, the same as set_from_related, but it calls update afterwards
-$track = DBICTest::Track->create( {
+$track = DBICTest->class("Track")->create( {
trackid => 2,
cd => 3,
position => 99,
} );
$track->update_from_related( cd => $cd );
-my $t_cd = (DBICTest::Track->search( cd => 4, position => 99 ))[0]->cd;
+my $t_cd = (DBICTest->class("Track")->search( cd => 4, position => 99 ))[0]->cd;
if ($INC{'DBICTest/HelperRels.pm'}) { # except inflated object
is( $t_cd->cdid, 4, 'update_from_related ok' );
#skip 'Need to add delete_related', 1;
# delete_related
$artist->delete_related( cds => { title => 'Greatest Hits' });
- cmp_ok( DBICTest::CD->search( title => 'Greatest Hits' ), '==', 0, 'delete_related ok' );
+ cmp_ok( DBICTest->class("CD")->search( title => 'Greatest Hits' ), '==', 0, 'delete_related ok' );
};
# try to add a bogus relationship using the wrong cols
eval {
- $artist->add_relationship(
+ DBICTest::Schema::Artist->add_relationship(
tracks => 'DBICTest::Track',
{ 'foreign.cd' => 'self.cdid' }
);
# another bogus relationship using no join condition
eval {
- $artist->add_relationship( tracks => 'DBICTest::Track' );
+ DBICTest::Schema::Artist->add_relationship( tracks => 'DBICTest::Track' );
};
like($@, qr/join condition/, 'failed when creating a rel without join condition, ok');
plan tests => 12;
# first page
-my $it = DBICTest::CD->search(
+my $it = DBICTest->class("CD")->search(
{},
{ order_by => 'title',
rows => 3,
is( $it->next, undef, "next past end of page ok" );
# second page, testing with array
-my @page2 = DBICTest::CD->search(
+my @page2 = DBICTest->class("CD")->search(
{},
{ order_by => 'title',
rows => 3,
is( $page2[0]->title, "Generic Manufactured Singles", "second page first title ok" );
# page a standard resultset
-$it = DBICTest::CD->search(
+$it = DBICTest->class("CD")->search(
{},
{ order_by => 'title',
rows => 3 }
is( $page->next->title, "Generic Manufactured Singles", "second page of standard resultset ok" );
# test software-based limit paging
-$it = DBICTest::CD->search(
+$it = DBICTest->class("CD")->search(
{},
{ order_by => 'title',
rows => 3,
Class::C3->reinitialize;
# inflation test
-my $cd = DBICTest::CD->find(3);
+my $cd = DBICTest->class("CD")->find(3);
is( ref($cd->year), 'DateTime', 'year is a DateTime, ok' );
$cd->year( $now );
$cd->update;
-($cd) = DBICTest::CD->search( year => $now->year );
+($cd) = DBICTest->class("CD")->search( year => $now->year );
is( $cd->year->year, $now->year, 'deflate ok' );
}
Class::C3->reinitialize;
# inflation test
-my $cd = DBICTest::CD->find(3);
+my $cd = DBICTest->class("CD")->find(3);
is( ref($cd->year), 'DateTime', 'year is a DateTime, ok' );
$cd->year( $now );
$cd->update;
-($cd) = DBICTest::CD->search( year => $now->year );
+($cd) = DBICTest->class("CD")->search( year => $now->year );
is( $cd->year->year, $now->year, 'deflate ok' );
# re-test using alternate deflate syntax
-DBICTest::CD->has_a( 'year', 'DateTime',
+DBICTest->class("CD")->has_a( 'year', 'DateTime',
inflate => sub { DateTime->new( year => shift ) },
deflate => 'year'
);
# inflation test
-$cd = DBICTest::CD->find(3);
+$cd = DBICTest->class("CD")->find(3);
is( ref($cd->year), 'DateTime', 'year is a DateTime, ok' );
$cd->year( $now );
$cd->update;
-($cd) = DBICTest::CD->search( year => $now->year );
+($cd) = DBICTest->class("CD")->search( year => $now->year );
is( $cd->year->year, $now->year, 'deflate ok' );
}
plan $@ ? (skip_all => 'needs DBD::SQLite for testing') : (tests => 3);
}
-my $art = DBICTest::Artist->find(1);
+my $art = DBICTest->class("Artist")->find(1);
isa_ok $art => 'DBICTest::Artist';
plan tests => 1;
-DBICTest::Artist->load_components(qw/PK::Auto::SQLite/);
+DBICTest->class("Artist")->load_components(qw/PK::Auto::SQLite/);
# add an artist without primary key to test Auto
-my $artist = DBICTest::Artist->create( { name => 'Auto' } );
+my $artist = DBICTest->class("Artist")->create( { name => 'Auto' } );
$artist->name( 'Auto Change' );
ok($artist->update, 'update on object created without PK ok');
plan tests => 4;
-DBICTest::Schema->compose_connection('MySQLTest' => $dsn, $user, $pass);
+DBICTest->class("Schema")->compose_connection('MySQLTest' => $dsn, $user, $pass);
my $dbh = MySQLTest::Artist->storage->dbh;
plan tests => 2;
-DBICTest::Schema->compose_connection('PgTest' => $dsn, $user, $pass);
+DBICTest->class("Schema")->compose_connection('PgTest' => $dsn, $user, $pass);
my $dbh = PgTest::Artist->storage->dbh;
plan tests => 4;
-DBICTest::Schema->compose_connection('OraTest' => $dsn, $user, $pass);
+DBICTest->class("Schema")->compose_connection('OraTest' => $dsn, $user, $pass);
my $dbh = OraTest::Artist->storage->dbh;
\r
plan tests => 4;\r
\r
-DBICTest::Schema->compose_connection( 'MSSQLTest' => $dsn, $user, $pass );\r
+DBICTest->class("Schema")->compose_connection( 'MSSQLTest' => $dsn, $user, $pass );\r
\r
my $dbh = MSSQLTest::Artist->storage->dbh;\r
\r
}
# test LIMIT
-my $it = DBICTest::CD->search( {},
+my $it = DBICTest->class("CD")->search( {},
{ rows => 3,
order_by => 'title' }
);
is( $it->next, undef, "next past end of resultset ok" );
# test OFFSET
-my @cds = DBICTest::CD->search( {},
+my @cds = DBICTest->class("CD")->search( {},
{ rows => 2,
offset => 2,
order_by => 'year' }
is( $cds[0]->title, "Spoonful of bees", "offset ok" );
# test software-based limiting
-$it = DBICTest::CD->search( {},
+$it = DBICTest->class("CD")->search( {},
{ rows => 3,
software_limit => 1,
order_by => 'title' }
$it->next;
is( $it->next, undef, "software next past end of resultset ok" );
-@cds = DBICTest::CD->search( {},
+@cds = DBICTest->class("CD")->search( {},
{ rows => 2,
offset => 2,
software_limit => 1,
# based on a failing criteria submitted by waswas
# requires SQL::Abstract >= 1.20
-$it = DBICTest::CD->search(
+$it = DBICTest->class("CD")->search(
{ title => [
-and =>
{
is( $sa->_recurse_from(@j3), $match, 'join 3 (inner join) ok');
-my $rs = DBICTest::CD->search(
+my $rs = DBICTest->class("CD")->search(
{ 'year' => 2001, 'artist.name' => 'Caterwauler McCrae' },
{ from => [ { 'me' => 'cd' },
[
is($rs->first->title, 'Forkful of bees', 'Correct record returned');
-$rs = DBICTest::CD->search(
+$rs = DBICTest->class("CD")->search(
{ 'year' => 2001, 'artist.name' => 'Caterwauler McCrae' },
{ join => 'artist' });
is($rs->first->title, 'Forkful of bees', 'Correct record returned');
-$rs = DBICTest::CD->search(
+$rs = DBICTest->class("CD")->search(
{ 'artist.name' => 'We Are Goth',
'liner_notes.notes' => 'Kill Yourself!' },
{ join => [ qw/artist liner_notes/ ] });
is($rs->first->title, 'Come Be Depressed With Us', 'Correct record returned');
-$rs = DBICTest::Artist->search(
+$rs = DBICTest->class("Artist")->search(
{ 'liner_notes.notes' => 'Kill Yourself!' },
{ join => { 'cds' => 'liner_notes' } });
{ 'foreign.liner_id' => 'self.cdid' },
{ join_type => 'LEFT', accessor => 'single' });
-$rs = DBICTest::CD->search(
+$rs = DBICTest->class("CD")->search(
{ 'artist.name' => 'Caterwauler McCrae' },
{ prefetch => [ qw/artist liner_notes/ ],
order_by => 'me.cdid' });
unlink 't/var/dbic.trace';
is($selects, 1, 'prefetch ran only 1 select statement');
-my ($artist) = DBICTest::Artist->search({ 'cds.year' => 2001 },
+my ($artist) = DBICTest->class("Artist")->search({ 'cds.year' => 2001 },
{ order_by => 'artistid DESC', join => 'cds' });
is($artist->name, 'Random Boy Band', "Join search by object ok");
-my @cds = DBICTest::CD->search({ 'liner_notes.notes' => 'Buy Merch!' },
+my @cds = DBICTest->class("CD")->search({ 'liner_notes.notes' => 'Buy Merch!' },
{ join => 'liner_notes' });
cmp_ok(scalar @cds, '==', 1, "Single CD retrieved via might_have");
is($cds[0]->title, "Generic Manufactured Singles", "Correct CD retrieved");
-my @artists = DBICTest::Artist->search({ 'tags.tag' => 'Shiny' },
+my @artists = DBICTest->class("Artist")->search({ 'tags.tag' => 'Shiny' },
{ join => { 'cds' => 'tags' } });
cmp_ok( @artists, '==', 2, "two-join search ok" );
plan skip_all => 'needs DBD::SQLite for testing' if $@;
plan tests => 4;
-cmp_ok(DBICTest::CD->count({ 'artist.name' => 'Caterwauler McCrae' },
+cmp_ok(DBICTest->class("CD")->count({ 'artist.name' => 'Caterwauler McCrae' },
{ join => 'artist' }),
'==', 3, 'Count by has_a ok');
-cmp_ok(DBICTest::CD->count({ 'tags.tag' => 'Blue' }, { join => 'tags' }),
+cmp_ok(DBICTest->class("CD")->count({ 'tags.tag' => 'Blue' }, { join => 'tags' }),
'==', 4, 'Count by has_many ok');
-cmp_ok(DBICTest::CD->count(
+cmp_ok(DBICTest->class("CD")->count(
{ 'liner_notes.notes' => { '!=' => undef } },
{ join => 'liner_notes' }),
'==', 3, 'Count by might_have ok');
-cmp_ok(DBICTest::CD->count(
+cmp_ok(DBICTest->class("CD")->count(
{ 'year' => { '>', 1998 }, 'tags.tag' => 'Cheesy',
'liner_notes.notes' => { 'like' => 'Buy%' } },
{ join => [ qw/tags liner_notes/ ] } ),
\r
plan tests => 4;\r
\r
-my $item = DBICTest::SelfRef->find( 1 );\r
+my $item = DBICTest->class("SelfRef")->find( 1 );\r
is( $item->name, 'First', 'proper start item' );\r
\r
my @aliases = $item->aliases;\r
DBICTest::Schema::Artist->uuid_columns('name');
Class::C3->reinitialize();
-my $artist = DBICTest::Artist->create( { artistid => 100 } );
+my $artist = DBICTest->class("Artist")->create( { artistid => 100 } );
like $artist->name, qr/[\w-]{36}/, 'got something like uuid';
}