From: Michael G Schwern Date: Fri, 10 Aug 2007 07:56:14 +0000 (-0700) Subject: Pull in some tests from CDBI 3.16 that already work. X-Git-Tag: v0.08240~541^2~52 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=d2cee1fa9efa9dd1f830d1ade5914c7297e15933;p=dbsrgits%2FDBIx-Class.git Pull in some tests from CDBI 3.16 that already work. Try to fix some issues with the testlibs. --- diff --git a/t/cdbi-t/08-inheritcols.t b/t/cdbi-t/08-inheritcols.t new file mode 100644 index 0000000..7c66949 --- /dev/null +++ b/t/cdbi-t/08-inheritcols.t @@ -0,0 +1,23 @@ +#!/usr/bin/perl -w + +use strict; +use Test::More tests => 3; + +use Class::DBI; + +package A; +@A::ISA = qw(Class::DBI); +__PACKAGE__->columns(Primary => 'id'); + +package A::B; +@A::B::ISA = 'A'; +__PACKAGE__->columns(All => qw(id b1)); + +package A::C; +@A::C::ISA = 'A'; +__PACKAGE__->columns(All => qw(id c1 c2 c3)); + +package main; +is join (' ', sort A->columns), 'id', "A columns"; +is join (' ', sort A::B->columns), 'b1 id', "A::B columns"; +is join (' ', sort A::C->columns), 'c1 c2 c3 id', "A::C columns"; diff --git a/t/cdbi-t/22-deflate_order.t b/t/cdbi-t/22-deflate_order.t new file mode 100644 index 0000000..965bc49 --- /dev/null +++ b/t/cdbi-t/22-deflate_order.t @@ -0,0 +1,24 @@ +$| = 1; +use strict; + +use Test::More; + +eval { require Time::Piece::MySQL }; +plan skip_all => "Need Time::Piece::MySQL for this test" if $@; + +eval { require 't/testlib/Log.pm' }; +plan skip_all => "Need MySQL for this test" if $@; + +plan tests => 2; + +package main; + +my $log = Log->insert( { message => 'initial message' } ); +ok eval { $log->datetime_stamp }, "Have datetime"; +diag $@ if $@; + +$log->message( 'a revised message' ); +$log->update; +ok eval { $log->datetime_stamp }, "Have datetime after update"; +diag $@ if $@; + diff --git a/t/cdbi-t/26-mutator.t b/t/cdbi-t/26-mutator.t new file mode 100644 index 0000000..a7f8f98 --- /dev/null +++ b/t/cdbi-t/26-mutator.t @@ -0,0 +1,41 @@ +use strict; +use Test::More; + +BEGIN { + eval "use DBD::SQLite"; + plan $@ + ? (skip_all => 'needs DBD::SQLite for testing') + : (tests => 6); +} + +use lib 't/testlib'; +require Film; + +sub Film::accessor_name_for { + my ($class, $col) = @_; + return "sheep" if lc $col eq "numexplodingsheep"; + return $col; +} + +my $data = { + Title => 'Bad Taste', + Director => 'Peter Jackson', + Rating => 'R', +}; + +my $bt; +eval { + my $data = $data; + $data->{sheep} = 1; + ok $bt = Film->insert($data), "Modified accessor - with +accessor"; + isa_ok $bt, "Film"; +}; +is $@, '', "No errors"; + +eval { + ok $bt->sheep(2), 'Modified accessor, set'; + ok $bt->update, 'Update'; +}; +is $@, '', "No errors"; + diff --git a/t/testlib/MyBase.pm b/t/testlib/MyBase.pm index da1e86f..7951482 100644 --- a/t/testlib/MyBase.pm +++ b/t/testlib/MyBase.pm @@ -2,7 +2,9 @@ package # hide from PAUSE MyBase; use strict; -use base qw(DBIx::Class); +use base qw(DBIx::Class::CDBICompat); + +use DBI; use vars qw/$dbh/; diff --git a/t/testlib/MyFoo.pm b/t/testlib/MyFoo.pm index fa536ab..d645d3d 100644 --- a/t/testlib/MyFoo.pm +++ b/t/testlib/MyFoo.pm @@ -13,7 +13,7 @@ __PACKAGE__->has_a( inflate => sub { Date::Simple->new(shift) }, deflate => 'format', ); -__PACKAGE__->find_column('tdate')->placeholder("IF(1, CURDATE(), ?)"); +#__PACKAGE__->find_column('tdate')->placeholder("IF(1, CURDATE(), ?)"); sub create_sql { return qq{ diff --git a/t/testlib/PgBase.pm b/t/testlib/PgBase.pm index 5428a50..8c13493 100644 --- a/t/testlib/PgBase.pm +++ b/t/testlib/PgBase.pm @@ -2,7 +2,7 @@ package # hide from PAUSE PgBase; use strict; -use base 'DBIx::Class'; +use base 'DBIx::Class::CDBICompat'; my $db = $ENV{DBD_PG_DBNAME} || 'template1'; my $user = $ENV{DBD_PG_USER} || 'postgres';