Pull apart a test section (no functional changes)
[dbsrgits/DBIx-Class.git] / t / relationship / core.t
index e0e243c..be8d7c9 100644 (file)
@@ -1,9 +1,12 @@
+BEGIN { do "./t/lib/ANFANG.pm" or die ( $@ || $! ) }
+
 use strict;
 use warnings;
 
 use Test::More;
 use Test::Exception;
-use lib qw(t/lib);
+use Test::Warn;
+
 use DBICTest ':DiffSQL';
 
 my $schema = DBICTest->init_schema();
@@ -136,22 +139,6 @@ throws_ok {
     $new_bookmark->new_related( no_such_rel => {} );
 } qr/No such relationship 'no_such_rel'/, 'creating in uknown rel throws';
 
-{
-  local $TODO = "relationship checking needs fixing";
-  # try to add a bogus relationship using the wrong cols
-  throws_ok {
-      DBICTest::Schema::Artist->add_relationship(
-          tracks => 'DBICTest::Schema::Track',
-          { 'foreign.cd' => 'self.cdid' }
-      );
-  } qr/Unknown column/, 'failed when creating a rel with invalid key, ok';
-}
-
-# another bogus relationship using no join condition
-throws_ok {
-    DBICTest::Schema::Artist->add_relationship( tracks => 'DBICTest::Track' );
-} qr/join condition/, 'failed when creating a rel without join condition, ok';
-
 # many_to_many helper tests
 $cd = $schema->resultset("CD")->find(1);
 my @producers = $cd->producers(undef, { order_by => 'producerid'} );
@@ -190,11 +177,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' );
@@ -203,11 +203,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);