From: Amiri Barksdale Date: Fri, 21 May 2010 12:42:27 +0000 (+0000) Subject: Add another test class to viewdeps stuff. X-Git-Tag: v0.08124~114^2~26 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=1e70d9dcf044751d671d22182a0bc56ac294c347;p=dbsrgits%2FDBIx-Class.git Add another test class to viewdeps stuff. --- diff --git a/t/105view_deps.t b/t/105view_deps.t index bf0e345..5d96987 100644 --- a/t/105view_deps.t +++ b/t/105view_deps.t @@ -13,25 +13,37 @@ BEGIN { use_ok('DBIx::Class::ResultSource::View'); } -my $view = DBIx::Class::ResultSource::View->new( { name => 'Upsilon' } ); +my $view = DBIx::Class::ResultSource::View->new( { name => 'Quux' } ); 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, 'Connected to ViewDeps schema OK'); +ok( $schema, 'Connected to ViewDeps schema OK' ); -#diag(DwarnS $schema); +my @bar_deps = keys %{ $schema->resultset('Bar')->result_source->depends_on }; -#diag keys %{$schema->resultset('Bar')->result_source->depends_on}; +my @foo_deps = keys %{ $schema->resultset('Foo')->result_source->depends_on }; -my @dependencies = keys %{$schema->resultset('Bar')->result_source->depends_on}; +isa_ok( $schema->resultset('Bar')->result_source, + 'DBIx::Class::ResultSource::View', 'Bar' ); -is($dependencies[0], 'mixin', 'Bar is indeed reported to depend on mixin'); +is( $bar_deps[0], 'mixin', 'which is reported to depend on mixin.' ); +is( $foo_deps[0], undef, 'Foo has no dependencies...' ); + +isa_ok( + $schema->resultset('Foo')->result_source, + 'DBIx::Class::ResultSource::View', + 'though Foo' +); +#diag($schema->resultset('Baz')->result_source->table_class); +isa_ok($schema->resultset('Baz')->result_source, 'DBIx::Class::ResultSource::Table', "Baz on the other hand"); +dies_ok { ViewDeps::Result::Baz->result_source_instance->depends_on( + { ViewDeps::Result::Mixin->result_source_instance->name => 1 } + ) } "...and you cannot use depends_on with that"; done_testing; diff --git a/t/lib/ViewDeps.pm b/t/lib/ViewDeps.pm index 6d597c6..05fea95 100644 --- a/t/lib/ViewDeps.pm +++ b/t/lib/ViewDeps.pm @@ -1,17 +1,11 @@ package # hide from PAUSE ViewDeps; +## Used in 105view_deps.t 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 index 99a1d68..3660c44 100644 --- a/t/lib/ViewDeps/Result/Bar.pm +++ b/t/lib/ViewDeps/Result/Bar.pm @@ -5,7 +5,7 @@ use strict; use warnings; use parent qw(ViewDeps::Result::Foo); -require ViewDeps::Result::Mixin; +use ViewDeps::Result::Mixin; __PACKAGE__->table('bar'); @@ -18,7 +18,7 @@ __PACKAGE__->add_columns( ); __PACKAGE__->belongs_to( - 'b_thang', + 'table', 'ViewDeps::Result::JustATable', { 'foreign.id' => 'self.b' }, ); @@ -26,7 +26,7 @@ __PACKAGE__->belongs_to( __PACKAGE__->has_many( 'foos', 'ViewDeps::Result::Foo', - { 'foreign.a' => 'self.id' } + { 'foreign.id' => 'self.id' } ); 1; diff --git a/t/lib/ViewDeps/Result/Baz.pm b/t/lib/ViewDeps/Result/Baz.pm new file mode 100644 index 0000000..63ee336 --- /dev/null +++ b/t/lib/ViewDeps/Result/Baz.pm @@ -0,0 +1,22 @@ +package # hide from PAUSE + ViewDeps::Result::Baz; +## Used in 105view_deps.t + +use strict; +use warnings; +use parent qw(DBIx::Class::Core); + +__PACKAGE__->table('bar'); + +__PACKAGE__->add_columns( id => { data_type => 'integer' } ); + +__PACKAGE__->belongs_to( + 'table', + '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 index 6e22bf3..f259001 100644 --- a/t/lib/ViewDeps/Result/Foo.pm +++ b/t/lib/ViewDeps/Result/Foo.pm @@ -1,4 +1,4 @@ -package # hide from PAUSE +package # hide from PAUSE ViewDeps::Result::Foo; use strict; @@ -7,20 +7,15 @@ 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 } + 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' } -); +__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 index fb17a80..7281b17 100644 --- a/t/lib/ViewDeps/Result/JustATable.pm +++ b/t/lib/ViewDeps/Result/JustATable.pm @@ -1,22 +1,19 @@ -package # hide from PAUSE +package # hide from PAUSE ViewDeps::Result::JustATable; +## Used in 105view_deps.t 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 } + 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' } -); - +__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 index e91b8aa..4cfb2c7 100644 --- a/t/lib/ViewDeps/Result/Mixin.pm +++ b/t/lib/ViewDeps/Result/Mixin.pm @@ -1,5 +1,6 @@ package # hide from PAUSE ViewDeps::Result::Mixin; +## Used in 105view_deps.t use strict; use warnings;