From: Amiri Barksdale at Home Date: Thu, 23 Dec 2010 23:12:50 +0000 (-0800) Subject: Add a test lib and failing test for no explicit sequence declaration X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=709558168363bbc296a3148c1bc59cb35f9383e0;p=dbsrgits%2FDBIx-Class-ResultSource-MultipleTableInheritance.git Add a test lib and failing test for no explicit sequence declaration --- diff --git a/t/04no_sequence_defined.t b/t/04no_sequence_defined.t new file mode 100644 index 0000000..ce30122 --- /dev/null +++ b/t/04no_sequence_defined.t @@ -0,0 +1,41 @@ +use strict; +use warnings; +use lib 't/lib'; +use Test::More qw(no_plan); +use Test::Exception; +use Devel::Dwarn; + +BEGIN { + use_ok 'NoSequence'; + $ENV{DBIC_TRACE} = 0; +} + +my $schema = NoSequence->connect( 'dbi:Pg:dbname=test', 'postgres', '' ); +$schema->storage->dbh->{Warn} = 0; +$schema->storage->ensure_connected; +$schema->storage->_use_insert_returning(0); + +my $dir = "t/sql"; # tempdir(CLEANUP => 0); +$schema->create_ddl_dir( ['PostgreSQL'], 0.1, $dir ); +$schema->deploy( { add_drop_table => 1, add_drop_view => 1 } ); + +isa_ok( + $schema->source('Mesclun'), + 'DBIx::Class::ResultSource::View', + "My MTI class also" +); + +my ( $bowl_of_salad, $bowl_of_salad1 ); + +lives_ok { + $bowl_of_salad = $schema->resultset('Mesclun') + ->create( { acidity => 4, spiciness => '10', fresh => 0 } ); +} +"I can call a create on a view mesclun"; + +lives_ok { + $bowl_of_salad1 = $schema->resultset('Salad')->create( { fresh => 1 } ); +} +"I can do it for the other view, too"; + + diff --git a/t/lib/Cafe/Result/Coffee.pm b/t/lib/Cafe/Result/Coffee.pm index 9562ecc..9468ddb 100644 --- a/t/lib/Cafe/Result/Coffee.pm +++ b/t/lib/Cafe/Result/Coffee.pm @@ -8,7 +8,7 @@ use aliased 'DBIx::Class::ResultSource::MultipleTableInheritance' => 'MTI'; __PACKAGE__->table_class(MTI); __PACKAGE__->table('coffee'); __PACKAGE__->add_columns( - "id", { data_type => "integer", is_auto_increment => 1}, + "id", { data_type => "integer", is_auto_increment => 1, sequence => '_coffee_id_seq'}, "flavor", { data_type => "text", default_value => "good" }, ); diff --git a/t/lib/NoSequence.pm b/t/lib/NoSequence.pm new file mode 100644 index 0000000..1b59318 --- /dev/null +++ b/t/lib/NoSequence.pm @@ -0,0 +1,14 @@ +package NoSequence; + +use strict; +use warnings; +use parent 'DBIx::Class::Schema'; +use aliased 'DBIx::Class::ResultSource::MultipleTableInheritance' => 'MTIView'; + +for my $p (__PACKAGE__) { + $p->load_namespaces; + $_->attach_additional_sources + for grep $_->isa(MTIView), map $p->source($_), $p->sources; +} + +1; diff --git a/t/lib/NoSequence/Result/Dressing.pm b/t/lib/NoSequence/Result/Dressing.pm new file mode 100644 index 0000000..a57d225 --- /dev/null +++ b/t/lib/NoSequence/Result/Dressing.pm @@ -0,0 +1,19 @@ +package NoSequence::Result::Dressing; + +use strict; +use warnings; +use parent 'DBIx::Class::Core'; + +__PACKAGE__->table('dressing'); + +__PACKAGE__->add_columns( + id => { + data_type => 'integer', + is_auto_increment => 1, + }, + acidity => { data_type => 'integer', default => '2' } +); + +__PACKAGE__->set_primary_key('id'); + +1; diff --git a/t/lib/NoSequence/Result/Mesclun.pm b/t/lib/NoSequence/Result/Mesclun.pm new file mode 100644 index 0000000..68bbf18 --- /dev/null +++ b/t/lib/NoSequence/Result/Mesclun.pm @@ -0,0 +1,14 @@ +package NoSequence::Result::Mesclun; + +use strict; +use warnings; +use parent 'NoSequence::Result::Salad'; + +require NoSequence::Result::Dressing; + +__PACKAGE__->table('mesclun'); +__PACKAGE__->result_source_instance->add_additional_parent( + NoSequence::Result::Dressing->result_source_instance ); +__PACKAGE__->add_columns( "spiciness", { data_type => "integer" } ); + +1; diff --git a/t/lib/NoSequence/Result/Salad.pm b/t/lib/NoSequence/Result/Salad.pm new file mode 100644 index 0000000..7249d18 --- /dev/null +++ b/t/lib/NoSequence/Result/Salad.pm @@ -0,0 +1,17 @@ +package NoSequence::Result::Salad; + +use strict; +use warnings; +use parent 'DBIx::Class::Core'; +use aliased 'DBIx::Class::ResultSource::MultipleTableInheritance' => 'MTI'; + +__PACKAGE__->table_class(MTI); +__PACKAGE__->table('salad'); +__PACKAGE__->add_columns( + "id", { data_type => "integer", is_auto_increment => 1 }, + "fresh", { data_type => "boolean", }, +); + +__PACKAGE__->set_primary_key("id"); + +1;