From: Daniel Westermann-Clark Date: Tue, 18 Apr 2006 15:55:04 +0000 (-0400) Subject: Add tests for find by specific key, ordered columns X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=c9bb4b2f0605c0a39d7b52901c48edf75ac2a358;p=dbsrgits%2FDBIx-Class-Historic.git Add tests for find by specific key, ordered columns --- diff --git a/t/run/20unique.tl b/t/run/20unique.tl index e438735..19481ef 100644 --- a/t/run/20unique.tl +++ b/t/run/20unique.tl @@ -1,7 +1,7 @@ sub run_tests { my $schema = shift; -plan tests => 31; +plan tests => 34; my $artistid = 1; my $title = 'UNIQUE Constraint'; @@ -24,7 +24,13 @@ is($cd2->get_column('artist'), $cd1->get_column('artist'), 'find by specific key is($cd2->title, $cd1->title, 'title is correct'); is($cd2->year, $cd1->year, 'year is correct'); -my $cd3 = $schema->resultset('CD')->update_or_create( +my $cd3 = $schema->resultset('CD')->find($artistid, $title, { key => 'artist_title' }); + +is($cd3->get_column('artist'), $cd1->get_column('artist'), 'find by specific key, ordered columns: artist is correct'); +is($cd3->title, $cd1->title, 'title is correct'); +is($cd3->year, $cd1->year, 'year is correct'); + +my $cd4 = $schema->resultset('CD')->update_or_create( { artist => $artistid, title => $title, @@ -32,13 +38,13 @@ my $cd3 = $schema->resultset('CD')->update_or_create( }, ); -ok(! $cd3->is_changed, 'update_or_create without key: row is clean'); -is($cd3->cdid, $cd2->cdid, 'cdid is correct'); -is($cd3->get_column('artist'), $cd2->get_column('artist'), 'artist is correct'); -is($cd3->title, $cd2->title, 'title is correct'); -is($cd3->year, 2007, 'updated year is correct'); +ok(! $cd4->is_changed, 'update_or_create without key: row is clean'); +is($cd4->cdid, $cd2->cdid, 'cdid is correct'); +is($cd4->get_column('artist'), $cd2->get_column('artist'), 'artist is correct'); +is($cd4->title, $cd2->title, 'title is correct'); +is($cd4->year, 2007, 'updated year is correct'); -my $cd4 = $schema->resultset('CD')->update_or_create( +my $cd5 = $schema->resultset('CD')->update_or_create( { artist => $artistid, title => $title, @@ -47,13 +53,13 @@ my $cd4 = $schema->resultset('CD')->update_or_create( { key => 'artist_title' } ); -ok(! $cd4->is_changed, 'update_or_create by specific key: row is clean'); -is($cd4->cdid, $cd2->cdid, 'cdid is correct'); -is($cd4->get_column('artist'), $cd2->get_column('artist'), 'artist is correct'); -is($cd4->title, $cd2->title, 'title is correct'); -is($cd4->year, 2007, 'updated year is correct'); +ok(! $cd5->is_changed, 'update_or_create by specific key: row is clean'); +is($cd5->cdid, $cd2->cdid, 'cdid is correct'); +is($cd5->get_column('artist'), $cd2->get_column('artist'), 'artist is correct'); +is($cd5->title, $cd2->title, 'title is correct'); +is($cd5->year, 2007, 'updated year is correct'); -my $cd5 = $schema->resultset('CD')->update_or_create( +my $cd6 = $schema->resultset('CD')->update_or_create( { cdid => $cd2->cdid, artist => 1, @@ -63,13 +69,13 @@ my $cd5 = $schema->resultset('CD')->update_or_create( { key => 'primary' } ); -ok(! $cd5->is_changed, 'update_or_create by PK: row is clean'); -is($cd5->cdid, $cd2->cdid, 'cdid is correct'); -is($cd5->get_column('artist'), $cd2->get_column('artist'), 'artist is correct'); -is($cd5->title, $cd2->title, 'title is correct'); -is($cd5->year, 2005, 'updated year is correct'); +ok(! $cd6->is_changed, 'update_or_create by PK: row is clean'); +is($cd6->cdid, $cd2->cdid, 'cdid is correct'); +is($cd6->get_column('artist'), $cd2->get_column('artist'), 'artist is correct'); +is($cd6->title, $cd2->title, 'title is correct'); +is($cd6->year, 2005, 'updated year is correct'); -my $cd6 = $schema->resultset('CD')->find_or_create( +my $cd7 = $schema->resultset('CD')->find_or_create( { artist => $artistid, title => $title, @@ -78,13 +84,13 @@ my $cd6 = $schema->resultset('CD')->find_or_create( { key => 'artist_title' } ); -is($cd6->cdid, $cd1->cdid, 'find_or_create by specific key: cdid is correct'); -is($cd6->get_column('artist'), $cd1->get_column('artist'), 'artist is correct'); -is($cd6->title, $cd1->title, 'title is correct'); -is($cd6->year, $cd1->year, 'year is correct'); +is($cd7->cdid, $cd1->cdid, 'find_or_create by specific key: cdid is correct'); +is($cd7->get_column('artist'), $cd1->get_column('artist'), 'artist is correct'); +is($cd7->title, $cd1->title, 'title is correct'); +is($cd7->year, $cd1->year, 'year is correct'); my $artist = $schema->resultset('Artist')->find($artistid); -my $cd7 = $artist->find_or_create_related('cds', +my $cd8 = $artist->find_or_create_related('cds', { artist => $artistid, title => $title, @@ -93,12 +99,12 @@ my $cd7 = $artist->find_or_create_related('cds', { key => 'artist_title' } ); -is($cd7->cdid, $cd1->cdid, 'find_or_create related by specific key: cdid is correct'); -is($cd7->get_column('artist'), $cd1->get_column('artist'), 'artist is correct'); -is($cd7->title, $cd1->title, 'title is correct'); -is($cd7->year, $cd1->year, 'year is correct'); +is($cd8->cdid, $cd1->cdid, 'find_or_create related by specific key: cdid is correct'); +is($cd8->get_column('artist'), $cd1->get_column('artist'), 'artist is correct'); +is($cd8->title, $cd1->title, 'title is correct'); +is($cd8->year, $cd1->year, 'year is correct'); -my $cd8 = $artist->update_or_create_related('cds', +my $cd9 = $artist->update_or_create_related('cds', { artist => $artistid, title => $title, @@ -107,11 +113,11 @@ my $cd8 = $artist->update_or_create_related('cds', { key => 'artist_title' } ); -ok(! $cd8->is_changed, 'update_or_create by specific key: row is clean'); -is($cd8->cdid, $cd1->cdid, 'cdid is correct'); -is($cd8->get_column('artist'), $cd1->get_column('artist'), 'artist is correct'); -is($cd8->title, $cd1->title, 'title is correct'); -is($cd8->year, 2021, 'year is correct'); +ok(! $cd9->is_changed, 'update_or_create by specific key: row is clean'); +is($cd9->cdid, $cd1->cdid, 'cdid is correct'); +is($cd9->get_column('artist'), $cd1->get_column('artist'), 'artist is correct'); +is($cd9->title, $cd1->title, 'title is correct'); +is($cd9->year, 2021, 'year is correct'); }