X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2F80unique.t;h=2264f616bccbca7580739018657b19aa3feb7825;hb=b7743dabe3354b4a43954ec44a226dc1c44722ac;hp=2245511d1d90815b96d32e68c7fc72861e3ce2c3;hpb=246fa39d71feecdc126a39d916f34a28c1a554d5;p=dbsrgits%2FDBIx-Class.git diff --git a/t/80unique.t b/t/80unique.t index 2245511..2264f61 100644 --- a/t/80unique.t +++ b/t/80unique.t @@ -2,6 +2,7 @@ use strict; use warnings; use Test::More; +use Test::Exception; use lib qw(t/lib); use DBICTest; use DBIC::SqlMakerTest; @@ -25,6 +26,11 @@ is_deeply( [ qw/primary track_cd_position track_cd_title/ ], 'Track source has three unique constraints' ); +is_deeply( + [ sort $schema->source('Tag')->unique_constraint_names ], + [ qw/primary tagid_cd tagid_cd_tag tags_tagid_tag tags_tagid_tag_cd/ ], + 'Tag source has five unique constraints (from add_unique_constraings)' +); my $artistid = 1; my $title = 'UNIQUE Constraint'; @@ -126,6 +132,12 @@ 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'); +# Add an extra row to potentially confuse the query +$schema->resultset('CD')->create ({ + artist => 2, + title => $title, + year => 2022, +}); my $cd9 = $artist->cds->update_or_create( { cdid => $cd1->cdid, @@ -195,7 +207,7 @@ is($row->baz, 3, 'baz is correct'); { key => 'cd_artist_title' } ); - ok(!$cd1->in_storage, 'CD is not in storage yet after update_or_new'); + is($cd1->in_storage, 0, 'CD is not in storage yet after update_or_new'); $cd1->insert; ok($cd1->in_storage, 'CD got added to strage after update_or_new && insert'); @@ -232,4 +244,29 @@ is($row->baz, 3, 'baz is correct'); $schema->storage->debugobj(undef); } +{ + throws_ok { + eval <<'MOD' or die $@; + package # hide from PAUSE + DBICTest::Schema::UniqueConstraintWarningTest; + + use base qw/DBIx::Class::Core/; + + __PACKAGE__->table('dummy'); + + __PACKAGE__->add_column(qw/ foo bar /); + + __PACKAGE__->add_unique_constraint( + constraint1 => [qw/ foo /], + constraint2 => [qw/ bar /], + ); + + 1; +MOD + } qr/\Qadd_unique_constraint() does not accept multiple constraints, use add_unique_constraints() instead\E/, + 'add_unique_constraint throws when more than one constraint specified'; +} + + done_testing; +