From: Aran Deltac Date: Wed, 24 May 2006 21:53:03 +0000 (+0000) Subject: Incorporate changes in -current. X-Git-Tag: v0.07002~75^2~165^2~2 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=ae51573612aec70814b81bfe0c3683b824564368;p=dbsrgits%2FDBIx-Class.git Incorporate changes in -current. --- diff --git a/t/53delete_related.t b/t/53delete_related.t index f193566..5c47959 100644 --- a/t/53delete_related.t +++ b/t/53delete_related.t @@ -3,11 +3,10 @@ use strict; use warnings; use lib qw(t/lib); use DBICTest; -use DBICTest::BasicRels; plan tests => 7; -my $schema = DBICTest->schema; +my $schema = DBICTest->init_schema(); my $total_cds = $schema->resultset('CD')->count; cmp_ok($total_cds, '>', 0, 'need cd records'); diff --git a/t/60core.t b/t/60core.t index ad34e54..6ac90c7 100644 --- a/t/60core.t +++ b/t/60core.t @@ -5,9 +5,9 @@ use Test::More; use lib qw(t/lib); use DBICTest; -my $schema = DBICTest::init_schema(); +my $schema = DBICTest->init_schema(); -plan tests => 58; +plan tests => 60; # figure out if we've got a version of sqlite that is older than 3.2.6, in # which case COUNT(DISTINCT()) doesn't work @@ -38,6 +38,14 @@ is($art->get_column("name"), 'We Are In Rehab', 'And via get_column'); ok($art->update, 'Update run'); +my $record_jp = $schema->resultset("Artist")->search(undef, { join => 'cds' })->search(undef, { prefetch => 'cds' })->next; + +ok($record_jp, "prefetch on same rel okay"); + +my $record_fn = $schema->resultset("Artist")->search(undef, { join => 'cds' })->search({'cds.cdid' => '1'}, {join => 'artist_undirected_maps'})->next; + +ok($record_fn, "funny join is okay"); + @art = $schema->resultset("Artist")->search({ name => 'We Are In Rehab' }); cmp_ok(@art, '==', 1, "Changed artist returned by search"); diff --git a/t/72pg.t b/t/72pg.t index 754a830..3e55bcb 100644 --- a/t/72pg.t +++ b/t/72pg.t @@ -10,16 +10,17 @@ my ($dsn, $user, $pass) = @ENV{map { "DBICTEST_PG_${_}" } qw/DSN USER PASS/}; #warn "$dsn $user $pass"; plan skip_all => 'Set $ENV{DBICTEST_PG_DSN}, _USER and _PASS to run this test' - . ' (note: creates and drops a table named artist!)' unless ($dsn && $user); + . ' (note: creates and drops tables named artist and casecheck!)' unless ($dsn && $user); -plan tests => 4; +plan tests => 8; DBICTest::Schema->compose_connection('PgTest' => $dsn, $user, $pass); my $dbh = PgTest->schema->storage->dbh; PgTest->schema->source("Artist")->name("testschema.artist"); $dbh->do("CREATE SCHEMA testschema;"); -$dbh->do("CREATE TABLE testschema.artist (artistid serial PRIMARY KEY, name VARCHAR(255), charfield CHAR(10));"); +$dbh->do("CREATE TABLE testschema.artist (artistid serial PRIMARY KEY, name VARCHAR(100), charfield CHAR(10));"); +ok ( $dbh->do('CREATE TABLE testschema.casecheck (id serial PRIMARY KEY, "name" VARCHAR(1), "NAME" VARCHAR(2), "UC_NAME" VARCHAR(3));'), 'Creation of casecheck table'); PgTest::Artist->load_components('PK::Auto'); @@ -40,7 +41,7 @@ my $test_type_info = { 'name' => { 'data_type' => 'character varying', 'is_nullable' => 1, - 'size' => 255, + 'size' => 100, 'default_value' => undef, }, 'charfield' => { @@ -60,6 +61,16 @@ like($artistid_defval, is_deeply($type_info, $test_type_info, 'columns_info_for - column data types'); +my $name_info = PgTest::Casecheck->column_info( 'name' ); +is( $name_info->{size}, 1, "Case sensitive matching info for 'name'" ); + +my $NAME_info = PgTest::Casecheck->column_info( 'NAME' ); +is( $NAME_info->{size}, 2, "Case sensitive matching info for 'NAME'" ); + +my $uc_name_info = PgTest::Casecheck->column_info( 'uc_name' ); +is( $uc_name_info->{size}, 3, "Case insensitive matching info for 'uc_name'" ); + $dbh->do("DROP TABLE testschema.artist;"); +$dbh->do("DROP TABLE testschema.casecheck;"); $dbh->do("DROP SCHEMA testschema;"); diff --git a/t/76joins.t b/t/76joins.t index 63e0363..069626a 100644 --- a/t/76joins.t +++ b/t/76joins.t @@ -13,7 +13,7 @@ BEGIN { eval "use DBD::SQLite"; plan $@ ? ( skip_all => 'needs DBD::SQLite for testing' ) - : ( tests => 44 ); + : ( tests => 42 ); } # figure out if we've got a version of sqlite that is older than 3.2.6, in @@ -107,10 +107,6 @@ $rs = $schema->resultset("CD")->search( ); cmp_ok( scalar $rs->all, '==', scalar $rs->slice(0, $rs->count - 1), 'slice() with join has same count as all()' ); -eval { $rs->search(undef, { rows => 0, offset => 3 })->all; }; - -ok($@, "rows => 0 errors: $@"); - $rs = $schema->resultset("Artist")->search( { 'liner_notes.notes' => 'Kill Yourself!' }, { join => { 'cds' => 'liner_notes' } }); @@ -283,22 +279,3 @@ $schema->storage->debug(0); cmp_ok($queries, '==', 1, 'Only one query run'); -# has_many resulting in an additional select if no records available despite prefetch -my $track = $schema->resultset("Artist")->create( { - artistid => 4, - name => 'Artist without CDs', -} ); - -$queries = 0; -$schema->storage->debug(1); - -my $artist_without_cds = $schema->resultset("Artist")->find(4, { - join => [qw/ cds /], - prefetch => [qw/ cds /], -}); -my @no_cds = $artist_without_cds->cds; - -is($queries, 1, 'prefetch ran only 1 sql statement'); - -$schema->storage->debug(0); - diff --git a/t/86sqlt.t b/t/86sqlt.t index eeb0ca9..d01a630 100644 --- a/t/86sqlt.t +++ b/t/86sqlt.t @@ -12,7 +12,7 @@ plan skip_all => 'SQL::Translator required' if $@; my $schema = 'DBICTest::Schema'; -plan tests => 33; +plan tests => 31; my $translator = SQL::Translator->new( parser_args => { @@ -73,10 +73,14 @@ my @fk_constraints = 'selftable' => 'treelike', 'foreigntable' => 'treelike', 'selfcols' => ['parent'], 'foreigncols' => ['id'], 'needed' => 1, on_delete => '', on_update => ''}, - {'display' => 'twokeytreelike -> twokeytreelike for parent1,parent2', - 'selftable' => 'twokeytreelike', 'foreigntable' => 'twokeytreelike', - 'selfcols' => ['parent1', 'parent2'], 'foreigncols' => ['id1','id2'], - 'needed' => 1, on_delete => '', on_update => ''}, + + # shouldn't this be generated? + # + #{'display' => 'twokeytreelike -> twokeytreelike for parent1,parent2', + # 'selftable' => 'twokeytreelike', 'foreigntable' => 'twokeytreelike', + # 'selfcols' => ['parent1', 'parent2'], 'foreigncols' => ['id1','id2'], + # 'needed' => 1, on_delete => '', on_update => ''}, + {'display' => 'tags -> cd', 'selftable' => 'tags', 'foreigntable' => 'cd', 'selfcols' => ['cd'], 'foreigncols' => ['cdid'], diff --git a/t/88result_set_column.t b/t/88result_set_column.t index 50ef1e6..5ed86d4 100644 --- a/t/88result_set_column.t +++ b/t/88result_set_column.t @@ -7,7 +7,7 @@ use DBICTest; my $schema = DBICTest::init_schema(); -plan tests => 5; +plan tests => 8; my $cd; my $rs = $cd = $schema->resultset("CD")->search({}); @@ -25,3 +25,20 @@ is($rs_title->min, 'Caterwaulin\' Blues', "min okay for title"); cmp_ok($rs_year->sum, '==', 9996, "three artists returned"); +my $psrs = $schema->resultset('CD')->search({}, + { + '+select' => \'COUNT(*)', + '+as' => 'count' + } +); +ok(defined($psrs->get_column('count')), '+select/+as count'); + +$psrs = $schema->resultset('CD')->search({}, + { + '+select' => [ \'COUNT(*)', 'title' ], + '+as' => [ 'count', 'addedtitle' ] + } +); +ok(defined($psrs->get_column('count')), '+select/+as arrayref count'); +ok(defined($psrs->get_column('addedtitle')), '+select/+as title'); + diff --git a/t/89inflate_datetime.t b/t/89inflate_datetime.t new file mode 100644 index 0000000..254348a --- /dev/null +++ b/t/89inflate_datetime.t @@ -0,0 +1,21 @@ +use strict; +use warnings; + +use Test::More; +use lib qw(t/lib); +use DBICTest; + +my $schema = DBICTest->init_schema(); + +eval { require DateTime::Format::MySQL }; +plan skip_all => "Need DateTime::Format::MySQL for inflation tests" if $@; + +plan tests => 2; + +# inflation test +my $event = $schema->resultset("Event")->find(1); + +isa_ok($event->starts_at, 'DateTime', 'DateTime returned'); + +is($event->starts_at, '2006-04-25T22:24:33', 'Correct date/time'); + diff --git a/t/90ensure_class_loaded.t b/t/90ensure_class_loaded.t new file mode 100644 index 0000000..8f66c2e --- /dev/null +++ b/t/90ensure_class_loaded.t @@ -0,0 +1,44 @@ +use strict; +use warnings; + +use Test::More; +use lib qw(t/lib); +use DBICTest; +use Class::Inspector; + +BEGIN { + package TestPackage::A; + sub some_method {} +} + +my $schema = DBICTest->init_schema(); + +plan tests => 6; + +ok(Class::Inspector->loaded('TestPackage::A'), + 'anon. package exists'); +eval { + $schema->ensure_class_loaded('TestPackage::A'); +}; + +ok(!$@, 'ensure_class_loaded detected an anon. class'); + +eval { + $schema->ensure_class_loaded('FakePackage::B'); +}; + +like($@, qr/Can't locate/, + 'ensure_class_loaded threw exception for nonexistent class'); + +ok(!Class::Inspector->loaded('DBICTest::FakeComponent'), + 'DBICTest::FakeComponent not loaded yet'); + +eval { + $schema->ensure_class_loaded('DBICTest::FakeComponent'); +}; + +ok(!$@, 'ensure_class_loaded detected an existing but non-loaded class'); +ok(Class::Inspector->loaded('DBICTest::FakeComponent'), + 'DBICTest::FakeComponent now loaded'); + +1; diff --git a/t/90join_torture.t b/t/90join_torture.t new file mode 100644 index 0000000..eb66445 --- /dev/null +++ b/t/90join_torture.t @@ -0,0 +1,29 @@ +use strict; +use warnings; + +use Test::More; +use lib qw(t/lib); +use DBICTest; + +my $schema = DBICTest->init_schema(); + +plan tests => 4; + +my $rs1 = $schema->resultset("Artist")->search({ 'tags.tag' => 'Blue' }, { join => {'cds' => 'tracks'}, prefetch => {'cds' => 'tags'} }); +my @artists = $rs1->all; +cmp_ok(@artists, '==', 1, "Two artists returned"); + +my $rs2 = $rs1->search({ artistid => '1' }, { join => {'cds' => {'cd_to_producer' => 'producer'} } }); +my $rs3 = $rs2->search_related('cds')->search({'cds.title' => 'Forkful of bees'}); +cmp_ok($rs3->count, '==', 3, "Three artists returned"); + +my $rs4 = $schema->resultset("CD")->search({ 'artist.artistid' => '1' }, { join => ['tracks', 'artist'], prefetch => 'artist' }); +my @rs4_results = $rs4->all; + + +is($rs4_results[0]->cdid, 1, "correct artist returned"); + +my $rs5 = $rs4->search({'tracks.title' => 'Sticky Honey'}); +is($rs5->count, 1, "search without using previous joins okay"); + +1; diff --git a/t/lib/DBICTest.pm b/t/lib/DBICTest.pm index 78f788a..9dbbf55 100755 --- a/t/lib/DBICTest.pm +++ b/t/lib/DBICTest.pm @@ -218,6 +218,11 @@ sub populate_schema { [ 18, 1, 3, "Beehind You"], ]); + $schema->populate('Event', [ + [ qw/id starts_at/ ], + [ 1, '2006-04-25 22:24:33' ], + ]); + $schema->populate('Link', [ [ qw/id title/ ], [ 1, 'aaa' ] diff --git a/t/lib/DBICTest/Schema/SelfRef.pm b/t/lib/DBICTest/Schema/SelfRef.pm index 474c1a2..ec715c7 100644 --- a/t/lib/DBICTest/Schema/SelfRef.pm +++ b/t/lib/DBICTest/Schema/SelfRef.pm @@ -16,4 +16,6 @@ __PACKAGE__->add_columns( ); __PACKAGE__->set_primary_key('id'); +__PACKAGE__->has_many( aliases => 'DBICTest::Schema::SelfRefAlias' => 'self_ref' ); + 1; diff --git a/t/lib/DBICTest/Schema/SelfRefAlias.pm b/t/lib/DBICTest/Schema/SelfRefAlias.pm index d03e7ce..e7ed491 100644 --- a/t/lib/DBICTest/Schema/SelfRefAlias.pm +++ b/t/lib/DBICTest/Schema/SelfRefAlias.pm @@ -16,6 +16,5 @@ __PACKAGE__->set_primary_key(qw/self_ref alias/); __PACKAGE__->belongs_to( self_ref => 'DBICTest::Schema::SelfRef' ); __PACKAGE__->belongs_to( alias => 'DBICTest::Schema::SelfRef' ); -__PACKAGE__->has_many( aliases => 'DBICTest::Schema::SelfRefAlias' => 'self_ref' ); 1; diff --git a/t/lib/DBICTest/Schema/TwoKeyTreeLike.pm b/t/lib/DBICTest/Schema/TwoKeyTreeLike.pm index c7258e0..1c1b7b9 100644 --- a/t/lib/DBICTest/Schema/TwoKeyTreeLike.pm +++ b/t/lib/DBICTest/Schema/TwoKeyTreeLike.pm @@ -1,9 +1,7 @@ package # hide from PAUSE DBICTest::Schema::TwoKeyTreeLike; -use base qw/DBIx::Class/; - -__PACKAGE__->load_components(qw/Core/); +use base qw/DBIx::Class::Core/; __PACKAGE__->table('twokeytreelike'); __PACKAGE__->add_columns(