From: John Napiorkowski Date: Thu, 8 May 2008 21:43:16 +0000 (+0000) Subject: more cleanup of the test suite so that we can run it against other databases. fixed... X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=8871d4ad1ce3afa80338d355a21ba28d9b4a46ca;p=dbsrgits%2FDBIx-Class-Historic.git more cleanup of the test suite so that we can run it against other databases. fixed the problem with tests using self-referential constrainsts for dbs that have trouble handling that --- diff --git a/lib/SQL/Translator/Parser/DBIx/Class.pm b/lib/SQL/Translator/Parser/DBIx/Class.pm index 996d461..e960ff6 100644 --- a/lib/SQL/Translator/Parser/DBIx/Class.pm +++ b/lib/SQL/Translator/Parser/DBIx/Class.pm @@ -128,7 +128,7 @@ sub parse { # Force the order of the referenced fields to be the same as # ->add_columns method. my $idx; - my %other_columns_idx = map {$_ => $idx++} $othertable->columns; + my %other_columns_idx = map {$_ => ++$idx } $othertable->columns; @refkeys = sort { $other_columns_idx{$a} cmp $other_columns_idx{$b} } @refkeys; my @keys = map {$rel_info->{cond}->{$_} =~ /^\w+\.(\w+)$/} @cond; diff --git a/t/77prefetch.t b/t/77prefetch.t index b4ef5b9..a8e0673 100644 --- a/t/77prefetch.t +++ b/t/77prefetch.t @@ -227,7 +227,7 @@ $schema->storage->debugcb(sub { $queries++ }); $schema->storage->debug(1); my $tree_like = - $schema->resultset('TreeLike')->find(4, + $schema->resultset('TreeLike')->find(5, { join => { parent => { parent => 'parent' } }, prefetch => { parent => { parent => 'parent' } } }); @@ -244,21 +244,21 @@ $schema->storage->debugobj->callback(undef); cmp_ok($queries, '==', 1, 'Only one query run'); -$tree_like = $schema->resultset('TreeLike')->search({'me.id' => 1}); +$tree_like = $schema->resultset('TreeLike')->search({'me.id' => 2}); $tree_like = $tree_like->search_related('children')->search_related('children')->search_related('children')->first; is($tree_like->name, 'quux', 'Tree search_related ok'); $tree_like = $schema->resultset('TreeLike')->search_related('children', - { 'children.id' => 2, 'children_2.id' => 3 }, + { 'children.id' => 3, 'children_2.id' => 4 }, { prefetch => { children => 'children' } } )->first; is(eval { $tree_like->children->first->children->first->name }, 'quux', 'Tree search_related with prefetch ok'); $tree_like = eval { $schema->resultset('TreeLike')->search( - { 'children.id' => 2, 'children_2.id' => 5 }, + { 'children.id' => 3, 'children_2.id' => 6 }, { join => [qw/children children/] } - )->search_related('children', { 'children_4.id' => 6 }, { prefetch => 'children' } + )->search_related('children', { 'children_4.id' => 7 }, { prefetch => 'children' } )->first->children->first; }; is(eval { $tree_like->name }, 'fong', 'Tree with multiple has_many joins ok'); diff --git a/t/86sqlt.t b/t/86sqlt.t index 366f907..7db1d28 100644 --- a/t/86sqlt.t +++ b/t/86sqlt.t @@ -153,9 +153,9 @@ my %fk_constraints = ( treelike => [ { 'display' => 'treelike->treelike for parent', - 'name' => 'treelike_fk_parent', 'index_name' => 'parent', + 'name' => 'treelike_fk_parent_fk', 'index_name' => 'parent_fk', 'selftable' => 'treelike', 'foreigntable' => 'treelike', - 'selfcols' => ['parent'], 'foreigncols' => ['id'], + 'selfcols' => ['parent_fk'], 'foreigncols' => ['id'], on_delete => 'CASCADE', on_update => 'CASCADE', deferrable => 1, }, ], @@ -198,7 +198,7 @@ my %fk_constraints = ( 'display' => 'forceforeign->artist', 'name' => 'forceforeign_fk_artist', 'index_name' => 'artist', 'selftable' => 'forceforeign', 'foreigntable' => 'artist', - 'selfcols' => ['artist'], 'foreigncols' => ['artist_id'], + 'selfcols' => ['artist'], 'foreigncols' => ['artistid'], on_delete => '', on_update => '', deferrable => 1, }, ], diff --git a/t/lib/DBICTest.pm b/t/lib/DBICTest.pm index 516c299..8252ecc 100755 --- a/t/lib/DBICTest.pm +++ b/t/lib/DBICTest.pm @@ -118,10 +118,7 @@ sub deploy_schema { my $args = shift || {}; if ($ENV{"DBICTEST_SQLT_DEPLOY"}) { - -#$schema->create_ddl_dir([qw/MySQL/], $schema->VERSION, '.', undef, $args); -$schema->deploy($args); - + $schema->deploy($args); } else { open IN, "t/lib/sqlite.sql"; my $sql; @@ -230,17 +227,17 @@ sub populate_schema { [ 1, 2 ], [ 1, 3 ], ]); - - # $schema->populate('TreeLike', [ - # [ qw/id parent name/ ], - # [ 0, 0, 'root' ], - # [ 1, 0, 'foo' ], - # [ 2, 1, 'bar' ], - # [ 5, 1, 'blop' ], - # [ 3, 2, 'baz' ], - # [ 4, 3, 'quux' ], - # [ 6, 2, 'fong' ], - # ]); + + $schema->populate('TreeLike', [ + [ qw/id parent_fk name/ ], + [ 1, undef, 'root' ], + [ 2, 1, 'foo' ], + [ 3, 2, 'bar' ], + [ 6, 2, 'blop' ], + [ 4, 3, 'baz' ], + [ 5, 4, 'quux' ], + [ 7, 3, 'fong' ], + ]); $schema->populate('Track', [ [ qw/trackid cd position title/ ], diff --git a/t/lib/DBICTest/Schema/TreeLike.pm b/t/lib/DBICTest/Schema/TreeLike.pm index b5b2763..c124241 100644 --- a/t/lib/DBICTest/Schema/TreeLike.pm +++ b/t/lib/DBICTest/Schema/TreeLike.pm @@ -6,15 +6,15 @@ use base qw/DBIx::Class::Core/; __PACKAGE__->table('treelike'); __PACKAGE__->add_columns( 'id' => { data_type => 'integer', is_auto_increment => 1 }, - 'parent' => { data_type => 'integer' }, + 'parent_fk' => { data_type => 'integer' , is_nullable=>1}, 'name' => { data_type => 'varchar', size => 100, }, ); __PACKAGE__->set_primary_key(qw/id/); __PACKAGE__->belongs_to('parent', 'TreeLike', - { 'foreign.id' => 'self.parent' }); -__PACKAGE__->has_many('children', 'TreeLike', { 'foreign.parent' => 'self.id' }); + { 'foreign.id' => 'self.parent_fk' }); +__PACKAGE__->has_many('children', 'TreeLike', { 'foreign.parent_fk' => 'self.id' }); ## since this is a self referential table we need to do a post deploy hook and get ## some data in while constraints are off diff --git a/t/lib/sqlite.sql b/t/lib/sqlite.sql index 5f17ebe..828c85a 100644 --- a/t/lib/sqlite.sql +++ b/t/lib/sqlite.sql @@ -151,7 +151,7 @@ CREATE TABLE tags ( -- CREATE TABLE treelike ( id INTEGER PRIMARY KEY NOT NULL, - parent integer NOT NULL, + parent_fk integer NULL, name varchar(100) NOT NULL );