From: Amiri Barksdale Date: Thu, 20 May 2010 22:09:45 +0000 (+0000) Subject: Add test files and test for vie X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=6ebf5cbb4dff9f173f41d5f31f2169f899dee492;p=dbsrgits%2FDBIx-Class-Historic.git Add test files and test for vie Add test files and lib for new view_deps functionality. AKB --- diff --git a/lib/DBIx/Class.pm b/lib/DBIx/Class.pm index 1a50606..4a5f0f7 100644 --- a/lib/DBIx/Class.pm +++ b/lib/DBIx/Class.pm @@ -222,6 +222,8 @@ abraxxa: Alexander Hartmaier aherzog: Adam Herzog +amiri: Amiri Barksdale + amoore: Andrew Moore andyg: Andy Grundman diff --git a/lib/DBIx/Class/ResultSource/View.pm b/lib/DBIx/Class/ResultSource/View.pm index 6d083bc..e14bc7f 100644 --- a/lib/DBIx/Class/ResultSource/View.pm +++ b/lib/DBIx/Class/ResultSource/View.pm @@ -11,12 +11,6 @@ __PACKAGE__->mk_group_accessors( 'simple' => qw(is_virtual view_definition depends_on) ); -sub new { - my $new = shift->next::method(@_); - $new->{depends_on} = { %{$new->{depends_on}||{}} }; - return $new; -} - =head1 NAME DBIx::Class::ResultSource::View - ResultSource object representing a view @@ -136,9 +130,21 @@ database-based view. An SQL query for your view. Will not be translated across database syntaxes. - =head1 OVERRIDDEN METHODS +=head2 new + +The constructor. This is a private method, as only other DBIC modules +should call this. See L. + +=cut + +sub new { + my $new = shift->next::method(@_); + $new->{depends_on} = { %{$new->{depends_on}||{}} }; + return $new; +} + =head2 from Returns the FROM entry for the table (i.e. the view name) @@ -152,6 +158,17 @@ sub from { return $self->name; } +=head1 PRIVATE METHODS + +=head2 depends_on + +An internal method for the construction of a hashref of the view's +superclasses, e.g., the sources that comprise it. + +See L. + +=cut + 1; =head1 AUTHORS diff --git a/lib/SQL/Translator/Parser/DBIx/Class.pm b/lib/SQL/Translator/Parser/DBIx/Class.pm index abb6c15..b838260 100644 --- a/lib/SQL/Translator/Parser/DBIx/Class.pm +++ b/lib/SQL/Translator/Parser/DBIx/Class.pm @@ -298,7 +298,7 @@ EOW <=> (exists $b->depends_on->{$a->source_name} ? 1 : 0) } - map { $dbicschema->source($_) } (sort keys %@view_monikers); + map { $dbicschema->source($_) } (sort keys %view_monikers); foreach my $source (@view_sources) { diff --git a/t/105view_deps.t b/t/105view_deps.t new file mode 100644 index 0000000..2b8ccf2 --- /dev/null +++ b/t/105view_deps.t @@ -0,0 +1,35 @@ +#!/usr/bin/perl + +use strict; +use warnings; + +use Test::More; +use Test::Exception; +use lib qw(t/lib); +use Devel::Dwarn; +use ViewDeps; + +BEGIN { + use_ok('DBIx::Class::ResultSource::View'); +} + +my $view = DBIx::Class::ResultSource::View->new( { name => 'Upsilon' } ); +isa_ok( $view, 'DBIx::Class::ResultSource' ); +isa_ok( $view, 'DBIx::Class' ); + +can_ok( $view, $_ ) for qw/new from depends_on/; + +diag( map {"$_\n"} @{ mro::get_linear_isa($view) } ); +#diag( DwarnS $view); + +my $schema = ViewDeps->connect; +ok($schema); + +#diag(DwarnS $schema); + +#diag(DwarnS $schema->resultset('Bar')->result_source->depends_on); +diag keys %{$schema->resultset('Bar')->result_source->depends_on}; +my @dependencies = keys %{$schema->resultset('Bar')->result_source->depends_on}; +is($dependencies[0], 'mixin'); + +done_testing; diff --git a/t/lib/ViewDeps.pm b/t/lib/ViewDeps.pm new file mode 100644 index 0000000..6d597c6 --- /dev/null +++ b/t/lib/ViewDeps.pm @@ -0,0 +1,17 @@ +package # hide from PAUSE + ViewDeps; + +use strict; +use warnings; +use parent qw(DBIx::Class::Schema); +use aliased 'DBIx::Class::ResultSource::View' => 'View'; + +__PACKAGE__->load_namespaces; + +#for my $p (__PACKAGE__) { + #$p->load_namespaces; + #$_->attach_additional_sources + #for grep $_->isa(View), map $p->source($_), $p->sources; +#} + +1; diff --git a/t/lib/ViewDeps/Result/Bar.pm b/t/lib/ViewDeps/Result/Bar.pm new file mode 100644 index 0000000..99a1d68 --- /dev/null +++ b/t/lib/ViewDeps/Result/Bar.pm @@ -0,0 +1,32 @@ +package # hide from PAUSE + ViewDeps::Result::Bar; + +use strict; +use warnings; +use parent qw(ViewDeps::Result::Foo); + +require ViewDeps::Result::Mixin; + +__PACKAGE__->table('bar'); + +__PACKAGE__->result_source_instance->depends_on( + { ViewDeps::Result::Mixin->result_source_instance->name => 1 } +); + +__PACKAGE__->add_columns( + b => { data_type => 'integer' } +); + +__PACKAGE__->belongs_to( + 'b_thang', + 'ViewDeps::Result::JustATable', + { 'foreign.id' => 'self.b' }, +); + +__PACKAGE__->has_many( + 'foos', + 'ViewDeps::Result::Foo', + { 'foreign.a' => 'self.id' } +); + +1; diff --git a/t/lib/ViewDeps/Result/Foo.pm b/t/lib/ViewDeps/Result/Foo.pm new file mode 100644 index 0000000..6e22bf3 --- /dev/null +++ b/t/lib/ViewDeps/Result/Foo.pm @@ -0,0 +1,26 @@ +package # hide from PAUSE + ViewDeps::Result::Foo; + +use strict; +use warnings; +use parent qw(DBIx::Class::Core); +use aliased 'DBIx::Class::ResultSource::View'; + +__PACKAGE__->table_class(View); + +__PACKAGE__->table('foo'); + +__PACKAGE__->add_columns( + id => { data_type => 'integer', is_auto_increment => 1 }, + a => { data_type => 'integer', is_nullable => 1 } +); + +__PACKAGE__->set_primary_key('id'); + +__PACKAGE__->belongs_to( + 'bar', + 'ViewDeps::Result::Bar', + { 'foreign.id' => 'self.a' } +); + +1; diff --git a/t/lib/ViewDeps/Result/JustATable.pm b/t/lib/ViewDeps/Result/JustATable.pm new file mode 100644 index 0000000..fb17a80 --- /dev/null +++ b/t/lib/ViewDeps/Result/JustATable.pm @@ -0,0 +1,22 @@ +package # hide from PAUSE + ViewDeps::Result::JustATable; + +use base qw(DBIx::Class::Core); + +__PACKAGE__->table('just_a_table'); + +__PACKAGE__->add_columns( + id => { data_type => 'integer', is_auto_increment => 1 }, + name => { data_type => 'varchar', size => 255 } +); + +__PACKAGE__->set_primary_key('id'); + +__PACKAGE__->has_many( + 'bars', + 'ViewDeps::Result::Bar', + { 'foreign.b' => 'self.id' } +); + + +1; diff --git a/t/lib/ViewDeps/Result/Mixin.pm b/t/lib/ViewDeps/Result/Mixin.pm new file mode 100644 index 0000000..e91b8aa --- /dev/null +++ b/t/lib/ViewDeps/Result/Mixin.pm @@ -0,0 +1,19 @@ +package # hide from PAUSE + ViewDeps::Result::Mixin; + +use strict; +use warnings; +use parent qw(DBIx::Class::Core); + +__PACKAGE__->table('mixin'); + +__PACKAGE__->add_columns( + id => { + data_type => 'integer', is_auto_increment => 1, sequence => 'foo_id_seq' + }, + words => { data_type => 'text' } +); + +__PACKAGE__->set_primary_key('id'); + +1;