Add a test lib and failing test for no explicit sequence declaration
Amiri Barksdale at Home [Thu, 23 Dec 2010 23:12:50 +0000 (15:12 -0800)]
t/04no_sequence_defined.t [new file with mode: 0644]
t/lib/Cafe/Result/Coffee.pm
t/lib/NoSequence.pm [new file with mode: 0644]
t/lib/NoSequence/Result/Dressing.pm [new file with mode: 0644]
t/lib/NoSequence/Result/Mesclun.pm [new file with mode: 0644]
t/lib/NoSequence/Result/Salad.pm [new file with mode: 0644]

diff --git a/t/04no_sequence_defined.t b/t/04no_sequence_defined.t
new file mode 100644 (file)
index 0000000..ce30122
--- /dev/null
@@ -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";
+
+
index 9562ecc..9468ddb 100644 (file)
@@ -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 (file)
index 0000000..1b59318
--- /dev/null
@@ -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 (file)
index 0000000..a57d225
--- /dev/null
@@ -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 (file)
index 0000000..68bbf18
--- /dev/null
@@ -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 (file)
index 0000000..7249d18
--- /dev/null
@@ -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;