X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2Frelationship%2Fcore.t;h=87f635e6a2f876096d1ba85562753ef295639fcd;hb=8a684aeaa7dd3c6bd8c7e9a1ff7e8f5704c67a6d;hp=504993da63aa54b4fe945529e82e3e6889f628a4;hpb=49eeb48de3d8ff685926b595fa0f3f5e680eaee2;p=dbsrgits%2FDBIx-Class.git diff --git a/t/relationship/core.t b/t/relationship/core.t index 504993d..87f635e 100644 --- a/t/relationship/core.t +++ b/t/relationship/core.t @@ -3,9 +3,9 @@ use warnings; use Test::More; use Test::Exception; +use Test::Warn; use lib qw(t/lib); -use DBICTest; -use DBIC::SqlMakerTest; +use DBICTest ':DiffSQL'; my $schema = DBICTest->init_schema(); @@ -191,11 +191,24 @@ is( $prod_rs->first->name, 'Testy McProducer', 'many_to_many add_to_$rel($hash) ok' ); $cd->add_to_producers({ name => 'Jack Black' }); is( $prod_rs->count(), 2, 'many_to_many add_to_$rel($hash) count ok' ); -$cd->set_producers($schema->resultset('Producer')->all); -is( $cd->producers->count(), $prod_before_count+2, - 'many_to_many set_$rel(@objs) count ok' ); -$cd->set_producers($schema->resultset('Producer')->find(1)); -is( $cd->producers->count(), 1, 'many_to_many set_$rel($obj) count ok' ); + +warnings_like { + $cd->set_producers($schema->resultset('Producer')->all); + is( $cd->producers->count(), $prod_before_count+2, + 'many_to_many set_$rel(@objs) count ok' ); + + $cd->set_producers($schema->resultset('Producer')->find(1)); + is( $cd->producers->count(), 1, 'many_to_many set_$rel($obj) count ok' ); +} [ + ( qr/\QCalling 'set_producers' with a list of items to link to is deprecated, use an arrayref instead/ ) x 2 +], 'Warnings on deprecated invocation of set_* found'; + +warnings_like { + is( $cd->producers( producerid => '666' )->count, 0 ); +} [ + qr/\Qsearch( %condition ) is deprecated/ +], 'Warning properly bubbled from search()'; + $cd->set_producers([$schema->resultset('Producer')->all]); is( $cd->producers->count(), $prod_before_count+2, 'many_to_many set_$rel(\@objs) count ok' ); @@ -204,11 +217,11 @@ is( $cd->producers->count(), 1, 'many_to_many set_$rel([$obj]) count ok' ); throws_ok { $cd->remove_from_producers({ fake => 'hash' }) -} qr/needs an object/, 'remove_from_$rel($hash) dies correctly'; +} qr/expects an object/, 'remove_from_$rel($hash) dies correctly'; throws_ok { $cd->add_to_producers() -} qr/needs an object or hashref/, 'add_to_$rel(undef) dies correctly'; +} qr/expects an object or hashref/, 'add_to_$rel(undef) dies correctly'; # many_to_many stresstest my $twokey = $schema->resultset('TwoKeys')->find(1,1); @@ -228,7 +241,7 @@ is( $twokey->fourkeys_to_twokeys->count, 0, my $undef_artist_cd = $schema->resultset("CD")->new_result({ 'title' => 'badgers', 'year' => 2007 }); -is($undef_artist_cd->has_column_loaded('artist'), '', 'FK not loaded'); +ok(! $undef_artist_cd->has_column_loaded('artist'), 'FK not loaded'); is($undef_artist_cd->search_related('artist')->count, 0, '0=1 search when FK does not exist and object not yet in db'); lives_ok { $undef_artist_cd->related_resultset('artist')->new({name => 'foo'}); @@ -263,6 +276,22 @@ is_same_sql_bind ( $undir_maps = $schema->resultset("Artist")->find(2)->artist_undirected_maps; is($undir_maps->count, 1, 'found 1 undirected map for artist 2'); +{ + my $artist_to_mangle = $schema->resultset('Artist')->find(2); + + $artist_to_mangle->set_from_related( artist_undirected_maps => { id1 => 42 } ); + + ok( ! $artist_to_mangle->is_changed, 'Unresolvable set_from_related did not alter object' ); + + $artist_to_mangle->set_from_related( artist_undirected_maps => {} ); + ok( $artist_to_mangle->is_changed, 'Definitive set_from_related did alter object' ); + is ( + $artist_to_mangle->id, + undef, + 'Correctly unset id on definitive outcome of OR condition', + ); +} + my $mapped_rs = $undir_maps->search_related('mapped_artists'); my @art = $mapped_rs->all;