X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2F20invocations.t;h=fe52379601dec013c9c9054b5a606eb9631cd43c;hb=c9cf9b4def5db80a79facea0eaba6dc32ac1e2c3;hp=49d16af63bfa158974b3412eeb8fa6c23fe95ed1;hpb=23e88965d9a70c89c26e54c731aeb9573f03d640;p=dbsrgits%2FDBIx-Class-Schema-Loader.git diff --git a/t/20invocations.t b/t/20invocations.t index 49d16af..fe52379 100644 --- a/t/20invocations.t +++ b/t/20invocations.t @@ -3,7 +3,9 @@ use Test::More; use lib qw(t/lib); use make_dbictest_db; -$SIG{__WARN__} = sub { }; # Suppress warnings, as we test a lot of deprecated stuff here +local $SIG{__WARN__} = sub { + warn $_[0] unless $_[0] =~ /really_erase_my_files/ +}; # Takes a $schema as input, runs 4 basic tests sub test_schema { @@ -23,56 +25,25 @@ sub test_schema { } my @invocations = ( - 'deprecated_one' => sub { - package DBICTest::Schema::1; - use base qw/ DBIx::Class::Schema::Loader /; - __PACKAGE__->connection($make_dbictest_db::dsn); - __PACKAGE__->load_from_connection( relationships => 1 ); - __PACKAGE__; - }, - 'deprecated_two' => sub { - package DBICTest::Schema::2; - use base qw/ DBIx::Class::Schema::Loader /; - __PACKAGE__->load_from_connection( - relationships => 1, - connect_info => [ $make_dbictest_db::dsn ], - ); - __PACKAGE__; - }, - 'deprecated_three' => sub { - package DBICTest::Schema::3; - use base qw/ DBIx::Class::Schema::Loader /; - __PACKAGE__->load_from_connection( - relationships => 1, - dsn => $make_dbictest_db::dsn, - ); - __PACKAGE__; - }, - 'deprecated_four' => sub { - package DBICTest::Schema::4; - use base qw/ DBIx::Class::Schema::Loader /; - __PACKAGE__->connection($make_dbictest_db::dsn); - __PACKAGE__->loader_options( relationships => 1 ); - __PACKAGE__; - }, 'hardcode' => sub { package DBICTest::Schema::5; use base qw/ DBIx::Class::Schema::Loader /; - __PACKAGE__->loader_options( relationships => 1 ); + __PACKAGE__->naming('current'); __PACKAGE__->connection($make_dbictest_db::dsn); __PACKAGE__; }, 'normal' => sub { package DBICTest::Schema::6; use base qw/ DBIx::Class::Schema::Loader /; - __PACKAGE__->loader_options( relationships => 1 ); + __PACKAGE__->loader_options(); + __PACKAGE__->naming('current'); __PACKAGE__->connect($make_dbictest_db::dsn); }, 'make_schema_at' => sub { use DBIx::Class::Schema::Loader qw/ make_schema_at /; make_schema_at( 'DBICTest::Schema::7', - { relationships => 1 }, + { really_erase_my_files => 1, naming => 'current' }, [ $make_dbictest_db::dsn ], ); DBICTest::Schema::7->clone; @@ -80,19 +51,21 @@ my @invocations = ( 'embedded_options' => sub { package DBICTest::Schema::8; use base qw/ DBIx::Class::Schema::Loader /; + __PACKAGE__->naming('current'); __PACKAGE__->connect( $make_dbictest_db::dsn, - { loader_options => { relationships => 1 } } + { loader_options => { really_erase_my_files => 1 } } ); }, 'embedded_options_in_attrs' => sub { package DBICTest::Schema::9; use base qw/ DBIx::Class::Schema::Loader /; + __PACKAGE__->naming('current'); __PACKAGE__->connect( $make_dbictest_db::dsn, undef, undef, - { AutoCommit => 1, loader_options => { relationships => 1 } } + { AutoCommit => 1, loader_options => { really_erase_my_files => 1 } } ); }, 'embedded_options_make_schema_at' => sub { @@ -102,7 +75,10 @@ my @invocations = ( { }, [ $make_dbictest_db::dsn, - { loader_options => { relationships => 1 } }, + { loader_options => { + really_erase_my_files => 1, + naming => 'current' + } }, ], ); "DBICTest::Schema::10"; @@ -110,7 +86,10 @@ my @invocations = ( 'almost_embedded' => sub { package DBICTest::Schema::11; use base qw/ DBIx::Class::Schema::Loader /; - __PACKAGE__->loader_options( relationships => 1 ); + __PACKAGE__->loader_options( + really_erase_my_files => 1, + naming => 'current' + ); __PACKAGE__->connect( $make_dbictest_db::dsn, undef, undef, { AutoCommit => 1 } @@ -120,18 +99,56 @@ my @invocations = ( use DBIx::Class::Schema::Loader; DBIx::Class::Schema::Loader::make_schema_at( 'DBICTest::Schema::12', - { relationships => 1 }, + { really_erase_my_files => 1, naming => 'current' }, [ $make_dbictest_db::dsn ], ); DBICTest::Schema::12->clone; - } + }, + 'no_skip_load_external' => sub { + # By default we should pull in t/lib/DBICTest/Schema/13/Foo.pm $skip_me since t/lib is in @INC + use DBIx::Class::Schema::Loader; + DBIx::Class::Schema::Loader::make_schema_at( + 'DBICTest::Schema::13', + { really_erase_my_files => 1, naming => 'current' }, + [ $make_dbictest_db::dsn ], + ); + DBICTest::Schema::13->clone; + }, + 'skip_load_external' => sub { + # When we explicitly skip_load_external t/lib/DBICTest/Schema/14/Foo.pm should be ignored + use DBIx::Class::Schema::Loader; + DBIx::Class::Schema::Loader::make_schema_at( + 'DBICTest::Schema::14', + { really_erase_my_files => 1, naming => 'current', skip_load_external => 1 }, + [ $make_dbictest_db::dsn ], + ); + DBICTest::Schema::14->clone; + }, + 'moose' => sub { + package DBICTest::Schema::8; + use base qw/ DBIx::Class::Schema::Loader /; + __PACKAGE__->naming('current'); + __PACKAGE__->connect( + $make_dbictest_db::dsn, + { loader_options => { use_moose => 1 } } + ); + }, ); # 4 tests per k/v pair -plan tests => 2 * @invocations; +plan tests => 2 * @invocations + 2; # + 2 more manual ones below. while(@invocations >= 2) { my $style = shift @invocations; my $subref = shift @invocations; test_schema($style, &$subref); } + +{ + no warnings 'once'; + + is($DBICTest::Schema::13::Foo::skip_me, "bad mojo", + "external content loaded"); + is($DBICTest::Schema::14::Foo::skip_me, undef, + "external content not loaded with skip_load_external => 1"); +}