From: Daniel Westermann-Clark Date: Fri, 7 Jul 2006 05:30:53 +0000 (+0000) Subject: Commit failing test for unique constraints: When a table has two or more unique X-Git-Tag: v0.07002~75^2~40 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=365d06b716eb2b3894d83291c612b116ade1e9d7;p=dbsrgits%2FDBIx-Class.git Commit failing test for unique constraints: When a table has two or more unique constraints, and you satisfy one, you get a partial key in the WHERE clause. This required adding two unique constraints to the 'track' table, and fixing up a couple of cases where we had duplicate values. --- diff --git a/t/60core.t b/t/60core.t index b981365..aae959e 100644 --- a/t/60core.t +++ b/t/60core.t @@ -164,7 +164,7 @@ is($cd->get_column('name'), 'Caterwauler McCrae', 'Additional column returned'); $new = $schema->resultset("Track")->new( { trackid => 100, cd => 1, - position => 1, + position => 4, title => 'Insert or Update', } ); $new->update_or_insert; diff --git a/t/66relationship.t b/t/66relationship.t index 2565c48..406e289 100644 --- a/t/66relationship.t +++ b/t/66relationship.t @@ -72,7 +72,7 @@ $track = $schema->resultset("Track")->create( { trackid => 2, cd => 3, position => 99, - title => 'Hidden Track' + title => 'Hidden Track 2' } ); $track->update_from_related( cd => $cd ); diff --git a/t/80unique.t b/t/80unique.t index 18a41f2..ad62f0f 100644 --- a/t/80unique.t +++ b/t/80unique.t @@ -7,10 +7,24 @@ use DBICTest; my $schema = DBICTest->init_schema(); -plan tests => 36; +plan tests => 39; -is_deeply([ sort $schema->source('CD')->unique_constraint_names ], [ qw/cd_artist_title primary/ ], 'CD source has an automatically named unique constraint'); -is_deeply([ sort $schema->source('Producer')->unique_constraint_names ], [ qw/primary prod_name/ ], 'Producer source has a named unique constraint'); +# Check the defined unique constraints +is_deeply( + [ sort $schema->source('CD')->unique_constraint_names ], + [ qw/cd_artist_title primary/ ], + 'CD source has an automatically named unique constraint' +); +is_deeply( + [ sort $schema->source('Producer')->unique_constraint_names ], + [ qw/primary prod_name/ ], + 'Producer source has a named unique constraint' +); +is_deeply( + [ sort $schema->source('Track')->unique_constraint_names ], + [ qw/primary track_cd_position track_cd_title/ ], + 'Track source has three unique constraints' +); my $artistid = 1; my $title = 'UNIQUE Constraint'; @@ -126,3 +140,14 @@ 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'); +# KNOWN TO FAIL: Table with two unique constraints, and we're satisying one of them +my $track = $schema->resultset('Track')->find( + { + cd => 1, + position => 3, + }, + { order_by => 'position' } +); + +is($track->get_column('cd'), 1, 'track cd is correct'); +is($track->get_column('position'), 3, 'track position is correct'); diff --git a/t/lib/DBICTest/Schema/Track.pm b/t/lib/DBICTest/Schema/Track.pm index 691974a..d45e9f2 100644 --- a/t/lib/DBICTest/Schema/Track.pm +++ b/t/lib/DBICTest/Schema/Track.pm @@ -23,6 +23,9 @@ __PACKAGE__->add_columns( ); __PACKAGE__->set_primary_key('trackid'); +__PACKAGE__->add_unique_constraint([ qw/cd position/ ]); +__PACKAGE__->add_unique_constraint([ qw/cd title/ ]); + __PACKAGE__->belongs_to( cd => 'DBICTest::Schema::CD' ); __PACKAGE__->belongs_to( disc => 'DBICTest::Schema::CD' => 'cd'); diff --git a/t/lib/sqlite.sql b/t/lib/sqlite.sql index 868aba1..e4d4e6a 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 22 22:47:36 2006 +-- Created on Thu Jun 6 23:36:19 2006 -- BEGIN TRANSACTION; @@ -203,5 +203,7 @@ CREATE TABLE onekey ( CREATE UNIQUE INDEX tktlnameunique_twokeytreelike on twokeytreelike (name); CREATE UNIQUE INDEX cd_artist_title_cd on cd (artist, title); +CREATE UNIQUE INDEX track_cd_position_track on track (cd, position); +CREATE UNIQUE INDEX track_cd_title_track on track (cd, title); CREATE UNIQUE INDEX prod_name_producer on producer (name); COMMIT;