Change API of deploy_depends_on: pass it source names. Fix optional deps on 105view_d...
Amiri Barksdale at Home [Sun, 13 Jun 2010 00:10:31 +0000 (17:10 -0700)]
lib/DBIx/Class/ResultSource/View.pm
lib/SQL/Translator/Parser/DBIx/Class.pm
t/105view_deps.t
t/lib/ViewDeps/Result/AbNameArtists.pm
t/lib/ViewDeps/Result/AbaNameArtists.pm
t/lib/ViewDeps/Result/AbaNameArtistsAnd2010CDsWithManyTracks.pm
t/lib/ViewDeps/Result/Year2010CDsWithManyTracks.pm
t/lib/ViewDepsBad/Result/AbNameArtists.pm
t/lib/ViewDepsBad/Result/AbaNameArtists.pm
t/lib/ViewDepsBad/Result/AbaNameArtistsAnd2010CDsWithManyTracks.pm
t/lib/ViewDepsBad/Result/Year2010CDsWithManyTracks.pm

index 2771ca9..91e59db 100644 (file)
@@ -4,6 +4,7 @@ use strict;
 use warnings;
 
 use DBIx::Class::ResultSet;
+use Devel::Dwarn;
 
 use base qw/DBIx::Class/;
 __PACKAGE__->load_components(qw/ResultSource/);
@@ -132,11 +133,11 @@ syntaxes.
 =head2 deploy_depends_on 
 
   __PACKAGE__->result_source_instance->deploy_depends_on(
-      "MyDB::Schema::Result::Year","MyDB::Schema::Result::CD"
+      ["Year","CD"]
       );
 
 Specify the views (and only the views) that this view depends on.
-Pass this an array reference.
+Pass this an array reference of source names.
 
 =head1 OVERRIDDEN METHODS
 
@@ -164,12 +165,10 @@ The constructor.
 sub new {
     my ( $self, @args ) = @_;
     my $new = $self->next::method(@args);
-    $new->{deploy_depends_on}
-        = {
-            map { $_->result_source_instance->name => 1 }
-            @{ $new->{deploy_depends_on}||[] }
-          }
-        unless ref $new->{deploy_depends_on} eq 'HASH';
+    $new->{deploy_depends_on} =
+      { map { $_ => 1 }
+          @{ $new->{deploy_depends_on} || [] } }
+      unless ref $new->{deploy_depends_on} eq 'HASH';
     return $new;
 }
 
index bd3d3ba..cbeaf86 100644 (file)
@@ -399,7 +399,7 @@ sub _resolve_view_deps {
             return {};
         }
         my ($new_source_name) =
-          grep { $view->schema->source($_)->name eq $dep }
+          grep { $view->schema->source($_)->source_name eq $dep }
           @{ [ $view->schema->sources ] };
         my $subdeps =
           _resolve_view_deps( $view->schema->source($new_source_name),
index d53dc79..b740c58 100644 (file)
@@ -5,11 +5,16 @@ use warnings;
 
 use Test::More;
 use Test::Exception;
+use Test::Warn;
 use lib qw(t/lib);
 use ViewDeps;
 use ViewDepsBad;
 
 BEGIN {
+  require DBIx::Class;
+  plan skip_all =>
+      'Test needs ' . DBIx::Class::Optional::Dependencies->req_missing_for ('deploy')
+    unless DBIx::Class::Optional::Dependencies->req_ok_for ('deploy');
     use_ok('DBIx::Class::ResultSource::View');
 }
 
@@ -65,7 +70,7 @@ ok( $schema2, 'Connected to ViewDepsBad schema OK' );
 
 #################### DEPLOY2
 
-$schema2->deploy( { add_drop_table => 1 } );
+warnings_exist { $schema2->deploy( { add_drop_table => 1 } ); } [qr/no such table: main.aba_name_artists/], "Deploying the bad schema produces a warning: aba_name_artists was not created.";
 
 #################### DOES ORDERING WORK 2?
 
index 3651a5b..fab3a7c 100644 (file)
@@ -11,7 +11,7 @@ __PACKAGE__->result_source_instance->view_definition(
     "SELECT id,name FROM a_name_artists WHERE name like 'ab%'"
 );
 __PACKAGE__->result_source_instance->deploy_depends_on(
-    ["ViewDeps::Result::ANameArtists"]
+    ["ANameArtists"]
 );
 
 __PACKAGE__->add_columns(
index fc989f6..d0a1f04 100644 (file)
@@ -10,7 +10,7 @@ __PACKAGE__->table('aba_name_artists');
 __PACKAGE__->result_source_instance->view_definition(
     "SELECT id,name FROM ab_name_artists WHERE name like 'aba%'" );
 __PACKAGE__->result_source_instance->deploy_depends_on(
-    ["ViewDeps::Result::AbNameArtists"] );
+    ["AbNameArtists"] );
 
 __PACKAGE__->add_columns(
     id   => { data_type => 'integer', is_auto_increment => 1 },
index 83c651b..4395923 100644 (file)
@@ -11,7 +11,7 @@ __PACKAGE__->result_source_instance->view_definition(
     "SELECT aba.id,aba.name,cd.title,cd.year,cd.number_tracks FROM aba_name_artists aba JOIN year_2010_cds_with_many_tracks cd on (aba.id = cd.artist)"
 );
 __PACKAGE__->result_source_instance->deploy_depends_on(
-    ["ViewDeps::Result::AbNameArtists","ViewDeps::Result::Year2010CDsWithManyTracks"] );
+    ["AbNameArtists","Year2010CDsWithManyTracks"] );
 
 __PACKAGE__->add_columns(
     id            => { data_type => 'integer', is_auto_increment => 1 },
index c6e4144..c7ccfcb 100644 (file)
@@ -12,7 +12,7 @@ __PACKAGE__->result_source_instance->view_definition(
 );
 
 __PACKAGE__->result_source_instance->deploy_depends_on(
-    ["ViewDeps::Result::Year2010CDs"] );
+    ["Year2010CDs"] );
 
 __PACKAGE__->add_columns(
     id            => { data_type => 'integer', is_auto_increment => 1 },
index 181d4ec..358abaa 100644 (file)
@@ -11,7 +11,7 @@ __PACKAGE__->result_source_instance->view_definition(
     "SELECT id,name FROM a_name_artists WHERE name like 'ab%'"
 );
 __PACKAGE__->result_source_instance->deploy_depends_on(
-    ["ViewDepsBad::Result::ANameArtists"]
+    ["ANameArtists"]
 );
 
 __PACKAGE__->add_columns(
index 715d56d..c1e6239 100644 (file)
@@ -10,7 +10,7 @@ __PACKAGE__->table('aba_name_artists');
 __PACKAGE__->result_source_instance->view_definition(
     "SELECT id,name FROM ab_name_artists WHERE name like 'aba%'" );
 __PACKAGE__->result_source_instance->deploy_depends_on(
-    ["ViewDepsBad::Result::AbNameArtists", "ViewDepsBad::Result::AbaNameArtistsAnd2010CDsWithManyTracks"] );
+    ["AbNameArtists", "AbaNameArtistsAnd2010CDsWithManyTracks"] );
 
 __PACKAGE__->add_columns(
     id   => { data_type => 'integer', is_auto_increment => 1 },
index 8751d57..b90669f 100644 (file)
@@ -11,7 +11,7 @@ __PACKAGE__->result_source_instance->view_definition(
     "SELECT aba.id,aba.name,cd.title,cd.year,cd.number_tracks FROM aba_name_artists aba JOIN year_2010_cds_with_many_tracks cd on (aba.id = cd.artist)"
 );
 __PACKAGE__->result_source_instance->deploy_depends_on(
-    ["ViewDepsBad::Result::AbNameArtists","ViewDepsBad::Result::Year2010CDsWithManyTracks"] );
+    ["AbNameArtists","Year2010CDsWithManyTracks"] );
 
 __PACKAGE__->add_columns(
     id            => { data_type => 'integer', is_auto_increment => 1 },
index 9a4900f..349addb 100644 (file)
@@ -12,7 +12,7 @@ __PACKAGE__->result_source_instance->view_definition(
 );
 
 __PACKAGE__->result_source_instance->deploy_depends_on(
-    ["ViewDepsBad::Result::Year2010CDs"] );
+    ["Year2010CDs"] );
 
 __PACKAGE__->add_columns(
     id            => { data_type => 'integer', is_auto_increment => 1 },