2 use Test::More tests => 12;
7 use DBIx::Class::Schema::Loader;
9 my $schema_counter = 0;
11 # test skip_relationships
12 my $regular = schema_with();
13 is( ref($regular->source('Bar')->relationship_info('fooref')), 'HASH',
14 'regularly-made schema has fooref rel',
16 my $skip_rel = schema_with( skip_relationships => 1 );
17 is_deeply( $skip_rel->source('Bar')->relationship_info('fooref'), undef,
18 'skip_relationships blocks generation of fooref rel',
21 # test hashref as rel_name_map
22 my $hash_relationship = schema_with(
24 fooref => "got_fooref",
32 is( ref($hash_relationship->source('Foo')->relationship_info('got_bars')),
34 'single level hash in rel_name_map picked up correctly'
36 is( ref($hash_relationship->source('Bar')->relationship_info('got_fooref')),
38 'double level hash in rel_name_map picked up correctly'
41 # test coderef as rel_name_map
42 my $code_relationship = schema_with(
46 if ($args->{local_moniker} eq 'Foo') {
53 "DBICTest::Schema::${schema_counter}::Result::Foo",
54 local_moniker => 'Foo',
55 local_columns => ['fooid'],
57 "DBICTest::Schema::${schema_counter}::Result::Bar",
58 remote_moniker => 'Bar',
59 remote_columns => ['fooref'],
61 'correct args for Foo passed'
65 elsif ($args->{local_moniker} eq 'Bar') {
72 "DBICTest::Schema::${schema_counter}::Result::Bar",
73 local_moniker => 'Bar',
74 local_columns => ['fooref'],
76 "DBICTest::Schema::${schema_counter}::Result::Foo",
77 remote_moniker => 'Foo',
78 remote_columns => ['fooid'],
80 'correct args for Foo passed'
83 return 'fooref_caught';
87 is( ref($code_relationship->source('Foo')->relationship_info('bars_caught')),
89 'rel_name_map overrode local_info correctly'
91 is( ref($code_relationship->source('Bar')->relationship_info('fooref_caught')),
93 'rel_name_map overrode remote_info correctly'
98 # test relationship_attrs
100 schema_with( relationship_attrs => 'laughably invalid!!!' );
101 } qr/relationship_attrs/, 'throws error for invalid relationship_attrs';
105 my $nodelete = schema_with( relationship_attrs =>
107 all => { cascade_delete => 0 },
108 belongs_to => { cascade_delete => 1 },
112 my $bars_info = $nodelete->source('Foo')->relationship_info('bars');
114 #die Dumper([ $nodelete->source('Foo')->relationships() ]);
115 my $fooref_info = $nodelete->source('Bar')->relationship_info('fooref');
116 is( ref($fooref_info), 'HASH',
117 'fooref rel is present',
119 is( $bars_info->{attrs}->{cascade_delete}, 0,
120 'relationship_attrs settings seem to be getting through to the generated rels',
122 is( $fooref_info->{attrs}->{cascade_delete}, 1,
123 'belongs_to in relationship_attrs overrides all def',
127 #### generates a new schema with the given opts every time it's called
130 DBIx::Class::Schema::Loader::make_schema_at(
131 'DBICTest::Schema::'.$schema_counter,
132 { naming => 'current', @_ },
133 [ $make_dbictest_db::dsn ],
135 "DBICTest::Schema::$schema_counter"->clone;