[Rt-commit] r5494 - in DBIx-SearchBuilder/trunk: .
inc/Module/Install t
ruz at bestpractical.com
ruz at bestpractical.com
Fri Jun 30 07:57:01 EDT 2006
Author: ruz
Date: Fri Jun 30 07:56:58 2006
New Revision: 5494
Modified:
DBIx-SearchBuilder/trunk/ (props changed)
DBIx-SearchBuilder/trunk/inc/Module/Install.pm
DBIx-SearchBuilder/trunk/inc/Module/Install/Base.pm
DBIx-SearchBuilder/trunk/inc/Module/Install/Makefile.pm
DBIx-SearchBuilder/trunk/inc/Module/Install/Metadata.pm
DBIx-SearchBuilder/trunk/t/01basics.t
DBIx-SearchBuilder/trunk/t/01records.t
DBIx-SearchBuilder/trunk/t/02records_object.t
DBIx-SearchBuilder/trunk/t/utils.pl
Log:
r1623 at cubic-pc: cubic | 2005-04-07 20:11:05 +0400
test suit changes:
@AvailableDrivers array of the drivers that has DBD:: module installed
connect_handle, connect_sqlite functions
Modified: DBIx-SearchBuilder/trunk/inc/Module/Install.pm
==============================================================================
Modified: DBIx-SearchBuilder/trunk/inc/Module/Install/Base.pm
==============================================================================
Modified: DBIx-SearchBuilder/trunk/inc/Module/Install/Makefile.pm
==============================================================================
Modified: DBIx-SearchBuilder/trunk/inc/Module/Install/Metadata.pm
==============================================================================
Modified: DBIx-SearchBuilder/trunk/t/01basics.t
==============================================================================
Modified: DBIx-SearchBuilder/trunk/t/01records.t
==============================================================================
Modified: DBIx-SearchBuilder/trunk/t/02records_object.t
==============================================================================
--- DBIx-SearchBuilder/trunk/t/02records_object.t (original)
+++ DBIx-SearchBuilder/trunk/t/02records_object.t Fri Jun 30 07:56:58 2006
@@ -9,7 +9,16 @@
BEGIN { require "t/utils.pl" }
our (@AvailableDrivers);
-use constant TESTS_PER_DRIVER => 11;
+use Test::More;
+eval "use DBD::SQLite";
+if ($@) {
+plan skip_all => "DBD::SQLite required for testing database interaction"
+} else{
+plan tests => 9;
+}
+my $handle = get_handle('SQLite');
+connect_handle( $handle );
+isa_ok($handle->dbh, 'DBI::db');
my $total = scalar(@AvailableDrivers) * TESTS_PER_DRIVER;
plan tests => $total;
Modified: DBIx-SearchBuilder/trunk/t/utils.pl
==============================================================================
--- DBIx-SearchBuilder/trunk/t/utils.pl (original)
+++ DBIx-SearchBuilder/trunk/t/utils.pl Fri Jun 30 07:56:58 2006
@@ -21,7 +21,7 @@
Sybase
);
-=head2 @AvailableDrivers
+our @AvailableDrivers = grep { eval "require DBD::". $_ } @SupportedDrivers;
Array that lists only drivers from supported list
that user has installed.
@@ -50,172 +50,21 @@
return $handle;
}
-=head2 handle_to_driver
-
-Returns driver name which gets from C<$handle> object argument.
-
-=cut
-
-sub handle_to_driver
-{
- my $driver = ref($_[0]);
- $driver =~ s/^.*:://;
- return $driver;
-}
-
-=head2 connect_handle
-
-Connects C<$handle> object to DB.
-
-=cut
-
sub connect_handle
{
- my $call = "connect_". lc handle_to_driver( $_[0] );
- return unless defined &$call;
- goto &$call;
-}
-
-=head2 connect_handle_with_driver($handle, $driver)
+ my $class = lc ref($_[0]);
+ $class =~ s/^.*:://;
+ my $call = "connect_$class";
-Connects C<$handle> using driver C<$driver>; can use this to test the
-magic that turns a C<DBIx::SearchBuilder::Handle> into a C<DBIx::SearchBuilder::Handle::Foo>
-on C<Connect>.
-
-=cut
-
-sub connect_handle_with_driver
-{
- my $call = "connect_". lc $_[1];
return unless defined &$call;
- @_ = $_[0];
goto &$call;
}
sub connect_sqlite
{
my $handle = shift;
- return $handle->Connect(
- Driver => 'SQLite',
- Database => File::Spec->catfile(File::Spec->tmpdir(), "sb-test.$$")
- );
-}
-
-sub connect_mysql
-{
- my $handle = shift;
- return $handle->Connect(
- Driver => 'mysql',
- Database => $ENV{'SB_TEST_MYSQL'},
- User => $ENV{'SB_TEST_MYSQL_USER'} || 'root',
- Password => $ENV{'SB_TEST_MYSQL_PASS'} || '',
- );
+ return $handle->Connect( Driver => 'SQLite', Database => File::Spec->catfile(File::Spec->tmpdir(), "sb-test.$$"));
}
-sub connect_pg
-{
- my $handle = shift;
- return $handle->Connect(
- Driver => 'Pg',
- Database => $ENV{'SB_TEST_PG'},
- User => $ENV{'SB_TEST_PG_USER'} || 'postgres',
- Password => $ENV{'SB_TEST_PG_PASS'} || '',
- );
-}
-
-=head2 should_test
-
-Checks environment for C<SB_TEST_*> variables.
-Returns true if specified DB back-end should be tested.
-Takes one argument C<$driver> name.
-
-=cut
-
-sub should_test
-{
- my $driver = shift;
- return 1 if lc $driver eq 'sqlite';
- my $env = 'SB_TEST_'. uc $driver;
- return $ENV{$env};
-}
-
-=head2 had_schema
-
-Returns true if C<$class> has schema for C<$driver>.
-
-=cut
-
-sub has_schema
-{
- my ($class, $driver) = @_;
- my $method = 'schema_'. lc $driver;
- return UNIVERSAL::can( $class, $method );
-}
-
-=head2 init_schema
-
-Takes C<$class> and C<$handle> and inits schema by calling
-C<schema_$driver> method of the C<$class>.
-Returns last C<DBI::st> on success or last return value of the
-SimpleQuery method on error.
-
-=cut
-
-sub init_schema
-{
- my ($class, $handle) = @_;
- my $call = "schema_". lc handle_to_driver( $handle );
- my $schema = $class->$call();
- $schema = ref( $schema )? $schema : [$schema];
- my $ret;
- foreach my $query( @$schema ) {
- $ret = $handle->SimpleQuery( $query );
- return $ret unless UNIVERSAL::isa( $ret, 'DBI::st' );
- }
- return $ret;
-}
-
-=head2 cleanup_schema
-
-Takes C<$class> and C<$handle> and cleanup schema by calling
-C<cleanup_schema_$driver> method of the C<$class> if method exists.
-Always returns undef.
-
-=cut
-
-sub cleanup_schema
-{
- my ($class, $handle) = @_;
- my $call = "cleanup_schema_". lc handle_to_driver( $handle );
- return unless UNIVERSAL::can( $class, $call );
- my $schema = $class->$call();
- $schema = ref( $schema )? $schema : [$schema];
- foreach my $query( @$schema ) {
- eval { $handle->SimpleQuery( $query ) };
- }
-}
-
-=head2 init_data
-
-=cut
-
-sub init_data
-{
- my ($class, $handle) = @_;
- my @data = $class->init_data();
- my @columns = @{ shift @data };
- my $count = 0;
- foreach my $values ( @data ) {
- my %args;
- for( my $i = 0; $i < @columns; $i++ ) {
- $args{ $columns[$i] } = $values->[$i];
- }
- my $rec = $class->new( $handle );
- my $id = $rec->Create( %args );
- die "Couldn't create record" unless $id;
- $count++;
- }
- return $count;
-}
1;
More information about the Rt-commit
mailing list