From: Peter Rabbitson Date: Sat, 16 Oct 2010 14:18:29 +0000 (+0200) Subject: Add a unique constraint to artist.name in the test schema X-Git-Tag: v0.08124~38 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=84f7e8a1c6303091d753572648e37d3bd7270181;p=dbsrgits%2FDBIx-Class.git Add a unique constraint to artist.name in the test schema While at it adjust tests that assume the name is not unique --- diff --git a/t/100populate.t b/t/100populate.t index e179931..8bb0fdc 100644 --- a/t/100populate.t +++ b/t/100populate.t @@ -115,47 +115,46 @@ is($link7->id, 7, 'Link 7 id'); is($link7->url, undef, 'Link 7 url'); is($link7->title, 'gtitle', 'Link 7 title'); -my $rs = $schema->resultset('Artist'); -$rs->delete; +# populate with literals +{ + my $rs = $schema->resultset('Link'); + $rs->delete; -# test _execute_array_empty (insert_bulk with all literal sql) + # test _execute_array_empty (insert_bulk with all literal sql) -$rs->populate([ + $rs->populate([ (+{ - name => \"'DT'", - rank => \500, - charfield => \"'mtfnpy'", + url => \"'cpan.org'", + title => \"'The ''best of'' cpan'", }) x 5 -]); + ]); -is((grep { - $_->name eq 'DT' && - $_->rank == 500 && - $_->charfield eq 'mtfnpy' -} $rs->all), 5, 'populate with all literal SQL'); + is((grep { + $_->url eq 'cpan.org' && + $_->title eq "The 'best of' cpan", + } $rs->all), 5, 'populate with all literal SQL'); -$rs->delete; + $rs->delete; -# test mixed binds with literal sql + # test mixed binds with literal sql -$rs->populate([ + $rs->populate([ (+{ - name => \"'DT'", - rank => 500, - charfield => \"'mtfnpy'", + url => \"'cpan.org'", + title => "The 'best of' cpan", }) x 5 -]); - -is((grep { - $_->name eq 'DT' && - $_->rank == 500 && - $_->charfield eq 'mtfnpy' -} $rs->all), 5, 'populate with all literal SQL'); + ]); -$rs->delete; + is((grep { + $_->url eq 'cpan.org' && + $_->title eq "The 'best of' cpan", + } $rs->all), 5, 'populate with all literal SQL'); -### + $rs->delete; +} +my $rs = $schema->resultset('Artist'); +$rs->delete; throws_ok { $rs->populate([ { diff --git a/t/101populate_rs.t b/t/101populate_rs.t index 942d927..a2a2615 100644 --- a/t/101populate_rs.t +++ b/t/101populate_rs.t @@ -313,12 +313,12 @@ ARRAY_CONTEXT: { { title => 'Some CD3', year => '1997', - artist => { artistid=> ++$aid, name => 'Fred BloggsC'}, + artist => { artistid=> ++$aid, name => 'Fred BloggsE'}, }, { title => 'Some CD4', year => '1997', - artist => { artistid=> ++$aid, name => 'Fred BloggsD'}, + artist => { artistid=> ++$aid, name => 'Fred BloggsF'}, }, ]; @@ -326,11 +326,11 @@ ARRAY_CONTEXT: { isa_ok($cdA, 'DBICTest::CD', 'Created CD'); isa_ok($cdA->artist, 'DBICTest::Artist', 'Set Artist'); - is($cdA->artist->name, 'Fred BloggsC', 'Set Artist to FredC'); + is($cdA->artist->name, 'Fred BloggsE', 'Set Artist to FredE'); isa_ok($cdB, 'DBICTest::CD', 'Created CD'); isa_ok($cdB->artist, 'DBICTest::Artist', 'Set Artist'); - is($cdB->artist->name, 'Fred BloggsD', 'Set Artist to FredD'); + is($cdB->artist->name, 'Fred BloggsF', 'Set Artist to FredF'); ok($cdB->artist->artistid == $aid, "Got Expected Artist ID"); } diff --git a/t/60core.t b/t/60core.t index 41adcb2..215c033 100644 --- a/t/60core.t +++ b/t/60core.t @@ -307,15 +307,15 @@ ok($schema->storage(), 'Storage available'); ] }); - $rs->update({ name => 'Test _cond_for_update_delete' }); + $rs->update({ rank => 6134 }); my $art; $art = $schema->resultset("Artist")->find(1); - is($art->name, 'Test _cond_for_update_delete', 'updated first artist name'); + is($art->rank, 6134, 'updated first artist rank'); $art = $schema->resultset("Artist")->find(2); - is($art->name, 'Test _cond_for_update_delete', 'updated second artist name'); + is($art->rank, 6134, 'updated second artist rank'); } # test source_name diff --git a/t/82cascade_copy.t b/t/82cascade_copy.t index 5f8a542..14c4762 100644 --- a/t/82cascade_copy.t +++ b/t/82cascade_copy.t @@ -1,5 +1,5 @@ use strict; -use warnings; +use warnings; use Test::More; use lib qw(t/lib); @@ -7,11 +7,10 @@ use DBICTest; my $schema = DBICTest->init_schema(); -plan tests => 4; my $artist = $schema->resultset('Artist')->find(1); my $artist_cds = $artist->search_related('cds'); -my $cover_band = $artist->copy; +my $cover_band = $artist->copy ({name => $artist->name . '_cover' }); my $cover_cds = $cover_band->search_related('cds'); cmp_ok($cover_band->id, '!=', $artist->id, 'ok got new column id...'); @@ -24,3 +23,4 @@ cmp_ok($cover_band->search_related('twokeys')->count, '>', 0, 'duplicated multiP cmp_ok($cover_cds->search_related('tags')->count, '==', $artist_cds->search_related('tags')->count , 'duplicated count ok'); +done_testing; diff --git a/t/lib/DBICTest/Schema/Artist.pm b/t/lib/DBICTest/Schema/Artist.pm index fdecea3..62bd946 100644 --- a/t/lib/DBICTest/Schema/Artist.pm +++ b/t/lib/DBICTest/Schema/Artist.pm @@ -30,8 +30,10 @@ __PACKAGE__->add_columns( }, ); __PACKAGE__->set_primary_key('artistid'); +__PACKAGE__->add_unique_constraint(['name']); __PACKAGE__->add_unique_constraint(artist => ['artistid']); # do not remove, part of a test + __PACKAGE__->mk_classdata('field_name_for', { artistid => 'primary key', name => 'artist name', diff --git a/t/lib/sqlite.sql b/t/lib/sqlite.sql index e689c2d..e53bb23 100644 --- a/t/lib/sqlite.sql +++ b/t/lib/sqlite.sql @@ -1,6 +1,6 @@ -- -- Created by SQL::Translator::Producer::SQLite --- Created on Thu Jun 3 11:52:50 2010 +-- Created on Sat Oct 16 16:17:01 2010 -- -- @@ -15,6 +15,8 @@ CREATE TABLE artist ( CREATE INDEX artist_name_hookidx ON artist (name); +CREATE UNIQUE INDEX artist_name ON artist (name); + -- -- Table: bindtype_test -- @@ -384,6 +386,14 @@ CREATE TABLE tags ( CREATE INDEX tags_idx_cd ON tags (cd); +CREATE UNIQUE INDEX tagid_cd ON tags (tagid, cd); + +CREATE UNIQUE INDEX tagid_cd_tag ON tags (tagid, cd, tag); + +CREATE UNIQUE INDEX tags_tagid_tag ON tags (tagid, tag); + +CREATE UNIQUE INDEX tags_tagid_tag_cd ON tags (tagid, tag, cd); + -- -- Table: cd_to_producer -- diff --git a/t/storage/replicated.t b/t/storage/replicated.t index 67b6c2b..40342ea 100644 --- a/t/storage/replicated.t +++ b/t/storage/replicated.t @@ -735,7 +735,7 @@ ok my $transaction = sub { ->schema ->populate('Artist', [ [ qw/artistid name/ ], - [ $id, "Children of the Grave"], + [ $id, "Children of the Grave $id"], ]); ok my $result = $replicated->schema->resultset('Artist')->find($id)