X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2Flib%2Fdbixcsl_common_tests.pm;h=20dbb0b6815e15b5ef8f0d78090a671ae66edd47;hb=9b1dd93554ec8f70923940e2ae88e2e0260d0b55;hp=94bf90a216bde23162edb8001c28afaa76ef34c5;hpb=c0767caf51045926284f203a7d59890db994aa76;p=dbsrgits%2FDBIx-Class-Schema-Loader.git diff --git a/t/lib/dbixcsl_common_tests.pm b/t/lib/dbixcsl_common_tests.pm index 94bf90a..20dbb0b 100644 --- a/t/lib/dbixcsl_common_tests.pm +++ b/t/lib/dbixcsl_common_tests.pm @@ -102,7 +102,7 @@ sub run_tests { $num_rescans++ if $self->{vendor} eq 'Firebird'; plan tests => @connect_info * - (194 + $num_rescans * $col_accessor_map_tests + $extra_count + ($self->{data_type_tests}{test_count} || 0)); + (202 + $num_rescans * $col_accessor_map_tests + $extra_count + ($self->{data_type_tests}{test_count} || 0)); foreach my $info_idx (0..$#connect_info) { my $info = $connect_info[$info_idx]; @@ -193,14 +193,13 @@ sub setup_schema { my $debug = ($self->{verbose} > 1) ? 1 : 0; - if ( - $ENV{SCHEMA_LOADER_TESTS_USE_MOOSE} - && - ! DBIx::Class::Schema::Loader::Optional::Dependencies->req_ok_for('use_moose') - ) { - die sprintf ("Missing dependencies for SCHEMA_LOADER_TESTS_USE_MOOSE: %s\n", - DBIx::Class::Schema::Loader::Optional::Dependencies->req_missing_for('use_moose') - ); + if ($ENV{SCHEMA_LOADER_TESTS_USE_MOOSE}) { + if (not DBIx::Class::Schema::Loader::Optional::Dependencies->req_ok_for('use_moose')) { + die sprintf ("Missing dependencies for SCHEMA_LOADER_TESTS_USE_MOOSE: %s\n", + DBIx::Class::Schema::Loader::Optional::Dependencies->req_missing_for('use_moose')); + } + + $self->{use_moose} = 1; } my %loader_opts = ( @@ -220,11 +219,15 @@ sub setup_schema { dump_directory => $DUMP_DIR, datetime_timezone => 'Europe/Berlin', datetime_locale => 'de_DE', - use_moose => $ENV{SCHEMA_LOADER_TESTS_USE_MOOSE}, + $self->{use_moose} ? ( + use_moose => 1, + result_roles => 'TestRole', + result_roles_map => { LoaderTest2X => 'TestRoleForMap' }, + ) : (), col_collision_map => { '^(can)\z' => 'caught_collision_%s' }, rel_collision_map => { '^(set_primary_key)\z' => 'caught_rel_collision_%s' }, col_accessor_map => \&test_col_accessor_map, - result_component_map => { LoaderTest2X => 'TestComponentForMap', LoaderTest1 => '+TestComponentForMapFQN' }, + result_components_map => { LoaderTest2X => 'TestComponentForMap', LoaderTest1 => '+TestComponentForMapFQN' }, %{ $self->{loader_options} || {} }, ); @@ -357,26 +360,49 @@ sub test_schema { isa_ok( $rsobj35, "DBIx::Class::ResultSet" ); my @columns_lt2 = $class2->columns; - is_deeply( \@columns_lt2, [ qw/id dat dat2 set_primary_key can dbix_class_testcomponent testcomponent_fqn meta/ ], "Column Ordering" ); + is_deeply( \@columns_lt2, [ qw/id dat dat2 set_primary_key can dbix_class_testcomponent dbix_class_testcomponentformap testcomponent_fqn meta test_role_method test_role_for_map_method/ ], "Column Ordering" ); is $class2->column_info('can')->{accessor}, 'caught_collision_can', 'accessor for column name that conflicts with a UNIVERSAL method renamed based on col_collision_map'; - is $class2->column_info('set_primary_key')->{accessor}, undef, - 'accessor for column name that conflicts with a result base class method removed'; + ok (exists $class2->column_info('set_primary_key')->{accessor} + && (not defined $class2->column_info('set_primary_key')->{accessor}), + 'accessor for column name that conflicts with a result base class method removed'); + + ok (exists $class2->column_info('dbix_class_testcomponent')->{accessor} + && (not defined $class2->column_info('dbix_class_testcomponent')->{accessor}), + 'accessor for column name that conflicts with a component class method removed'); + + ok (exists $class2->column_info('dbix_class_testcomponentformap')->{accessor} + && (not defined $class2->column_info('dbix_class_testcomponentformap')->{accessor}), + 'accessor for column name that conflicts with a component class method removed'); - is $class2->column_info('dbix_class_testcomponent')->{accessor}, undef, - 'accessor for column name that conflicts with a component class method removed'; + ok (exists $class2->column_info('testcomponent_fqn')->{accessor} + && (not defined $class2->column_info('testcomponent_fqn')->{accessor}), + 'accessor for column name that conflicts with a fully qualified component class method removed'); - is $class2->column_info('testcomponent_fqn')->{accessor}, undef, - 'accessor for column name that conflicts with a fully qualified component class method removed'; + if ($self->{use_moose}) { + ok (exists $class2->column_info('meta')->{accessor} + && (not defined $class2->column_info('meta')->{accessor}), + 'accessor for column name that conflicts with Moose removed'); - if ($conn->_loader->use_moose) { - is $class2->column_info('meta')->{accessor}, undef, - 'accessor for column name that conflicts with Moose removed'; + ok (exists $class2->column_info('test_role_for_map_method')->{accessor} + && (not defined $class2->column_info('test_role_for_map_method')->{accessor}), + 'accessor for column name that conflicts with a Result role removed'); + + ok (exists $class2->column_info('test_role_method')->{accessor} + && (not defined $class2->column_info('test_role_method')->{accessor}), + 'accessor for column name that conflicts with a Result role removed'); } else { - pass "not removing 'meta' accessor with use_moose disabled"; + ok ((not exists $class2->column_info('meta')->{accessor}), + "not removing 'meta' accessor with use_moose disabled"); + + ok ((not exists $class2->column_info('test_role_for_map_method')->{accessor}), + 'no role method conflicts with use_moose disabled'); + + ok ((not exists $class2->column_info('test_role_method')->{accessor}), + 'no role method conflicts with use_moose disabled'); } my %uniq1 = $class1->unique_constraints; @@ -453,6 +479,18 @@ sub test_schema { 'fully qualified component class from result_component_map not added to not mapped Result'; SKIP: { + skip 'not testing role methods with use_moose disabled', 2 + unless $self->{use_moose}; + + is try { $class1->test_role_method }, 'test_role_method works', + 'role from result_roles applied'; + + is try { $class2->test_role_for_map_method }, + 'test_role_for_map_method works', + 'role from result_roles_map applied'; + } + + SKIP: { can_ok( $class1, 'loader_test1_classmeth' ) or skip "Pre-requisite test failed", 1; is( $class1->loader_test1_classmeth, 'all is well', 'Class method' ); @@ -518,7 +556,7 @@ sub test_schema { } SKIP: { - skip $self->{skip_rels}, 120 if $self->{skip_rels}; + skip $self->{skip_rels}, 123 if $self->{skip_rels}; my $moniker3 = $monikers->{loader_test3}; my $class3 = $classes->{loader_test3}; @@ -677,6 +715,9 @@ sub test_schema { is try { $rsobj3->result_source->relationship_info('loader_test4zes')->{attrs}{cascade_copy} }, 0, 'cascade_copy => 0 on has_many by default'; + ok ((not try { exists $rsobj3->result_source->relationship_info('loader_test4zes')->{attrs}{cascade_update} }), + 'has_many does not have cascade_update'); + ok ((not try { exists $rsobj3->result_source->relationship_info('loader_test4zes')->{attrs}{on_delete} }), 'has_many does not have on_delete'); @@ -701,12 +742,18 @@ sub test_schema { ok ((not try { exists $rsobj4->result_source->relationship_info('fkid_singular')->{attrs}{cascade_copy} }), 'belongs_to does not have cascade_copy'); + ok ((not try { exists $rsobj4->result_source->relationship_info('fkid_singular')->{attrs}{cascade_update} }), + 'belongs_to does not have cascade_update'); + is try { $rsobj27->result_source->relationship_info('loader_test28')->{attrs}{cascade_delete} }, 0, 'cascade_delete => 0 on might_have by default'; is try { $rsobj27->result_source->relationship_info('loader_test28')->{attrs}{cascade_copy} }, 0, 'cascade_copy => 0 on might_have by default'; + is try { $rsobj27->result_source->relationship_info('loader_test28')->{attrs}{cascade_update} }, 0, + 'cascade_update => 0 on might_have by default'; + ok ((not try { exists $rsobj27->result_source->relationship_info('loader_test28')->{attrs}{on_delete} }), 'might_have does not have on_delete'); @@ -1257,8 +1304,11 @@ sub create { set_primary_key INTEGER $self->{null}, can INTEGER $self->{null}, dbix_class_testcomponent INTEGER $self->{null}, + dbix_class_testcomponentformap INTEGER $self->{null}, testcomponent_fqn INTEGER $self->{null}, meta INTEGER $self->{null}, + test_role_method INTEGER $self->{null}, + test_role_for_map_method INTEGER $self->{null}, UNIQUE (dat2, dat) ) $self->{innodb} },