1use strict; 2use Test::More tests => 6; 3use Test::Exception; 4use lib qw(t/lib); 5use make_dbictest_db; 6 7use DBIx::Class::Schema::Loader; 8 9# test skip_relationships 10my $regular = schema_with(); 11is( ref($regular->source('Bar')->relationship_info('fooref')), 'HASH', 12 'regularly-made schema has fooref rel', 13 ); 14my $skip_rel = schema_with( skip_relationships => 1 ); 15is_deeply( $skip_rel->source('Bar')->relationship_info('fooref'), undef, 16 'skip_relationships blocks generation of fooref rel', 17 ); 18 19 20# test relationship_attrs 21throws_ok { 22 schema_with( relationship_attrs => 'laughably invalid!!!' ); 23} qr/relationship_attrs/, 'throws error for invalid relationship_attrs'; 24 25 26{ 27 my $nodelete = schema_with( relationship_attrs => 28 { 29 all => { cascade_delete => 0 }, 30 belongs_to => { cascade_delete => 1 }, 31 }, 32 ); 33 34 my $bars_info = $nodelete->source('Foo')->relationship_info('bars'); 35 #use Data::Dumper; 36 #die Dumper([ $nodelete->source('Foo')->relationships() ]); 37 my $fooref_info = $nodelete->source('Bar')->relationship_info('fooref'); 38 is( ref($fooref_info), 'HASH', 39 'fooref rel is present', 40 ); 41 is( $bars_info->{attrs}->{cascade_delete}, 0, 42 'relationship_attrs settings seem to be getting through to the generated rels', 43 ); 44 is( $fooref_info->{attrs}->{cascade_delete}, 1, 45 'belongs_to in relationship_attrs overrides all def', 46 ); 47} 48 49 50#### generates a new schema with the given opts every time it's called 51my $schema_counter = 0; 52sub schema_with { 53 $schema_counter++; 54 DBIx::Class::Schema::Loader::make_schema_at( 55 'DBICTest::Schema::'.$schema_counter, 56 { naming => 'current', @_ }, 57 [ $make_dbictest_db::dsn ], 58 ); 59 "DBICTest::Schema::$schema_counter"->clone; 60} 61