[Rt-commit] r2001 - in DBIx-SearchBuilder/trunk: . SearchBuilder t
jesse at bestpractical.com
jesse at bestpractical.com
Thu Dec 16 15:57:55 EST 2004
Author: jesse
Date: Thu Dec 16 15:57:54 2004
New Revision: 2001
Added:
DBIx-SearchBuilder/trunk/t/02records_object.t
Modified:
DBIx-SearchBuilder/trunk/ (props changed)
DBIx-SearchBuilder/trunk/SearchBuilder/Record.pm
Log:
r2445 at hualien: jesse | 2004-12-16T20:54:10.427617Z
Fixed automatic Object Mapping code (automatic resolution of object relations based on column naming) -- From Ruslan
Modified: DBIx-SearchBuilder/trunk/SearchBuilder/Record.pm
==============================================================================
--- DBIx-SearchBuilder/trunk/SearchBuilder/Record.pm (original)
+++ DBIx-SearchBuilder/trunk/SearchBuilder/Record.pm Thu Dec 16 15:57:54 2004
@@ -505,7 +505,7 @@
local ($^W) = 0;
my $attribute = $self->_ClassAccessible(@_)->{$attr};
return 0 unless (defined $attribute && $attribute->{$mode});
- return 1;
+ return $attribute->{$mode};
}
# }}}
Added: DBIx-SearchBuilder/trunk/t/02records_object.t
==============================================================================
--- (empty file)
+++ DBIx-SearchBuilder/trunk/t/02records_object.t Thu Dec 16 15:57:54 2004
@@ -0,0 +1,115 @@
+#!/usr/bin/perl -w
+
+
+use strict;
+use warnings;
+
+use Test::More;
+eval "use DBD::SQLite";
+if ($@) {
+plan skip_all => "DBD::SQLite required for testing database interaction"
+} else{
+plan tests => 12;
+}
+use_ok('DBIx::SearchBuilder::Handle::SQLite');
+my $handle = DBIx::SearchBuilder::Handle::SQLite->new();
+
+isa_ok($handle, 'DBIx::SearchBuilder::Handle');
+isa_ok($handle, 'DBIx::SearchBuilder::Handle::SQLite');
+$handle->Connect( Driver => 'SQLite', Database => "/tmp/sb-test.$$" );
+can_ok($handle, 'dbh');
+isa_ok($handle->dbh, 'DBI::db');
+foreach( @{ TestApp->schema } ) {
+ my $ret = $handle->SimpleQuery($_);
+ isa_ok($ret,'DBI::st', "Inserted the schema. got a statement handle back");
+}
+
+
+my $emp = TestApp::Employee->new($handle);
+my $e_id = $emp->Create( Name => 'RUZ' );
+ok($e_id);
+my $phone = TestApp::Phone->new($handle);
+my $p_id = $phone->Create( Employee => $e_id, Phone => '+7(903)264-03-51');
+# XXX: test fails if next string is commented
+$phone->Load( $p_id );
+ok($p_id);
+
+my $obj = $phone->EmployeeObj($handle);
+ok($obj, "Employee #$e_id has phone #$p_id");
+is($obj->id, $e_id);
+is($obj->Name, 'RUZ');
+
+
+package TestApp;
+sub schema {
+[
+q{
+CREATE TABLE Employees (
+ id integer primary key,
+ Name varchar(36)
+)
+}, q{
+CREATE TABLE Phones (
+ id integer primary key,
+ Employee integer NOT NULL,
+ Phone varchar(18)
+) }
+]
+
+}
+
+package TestApp::Employee;
+
+use base qw/DBIx::SearchBuilder::Record/;
+use vars qw/$VERSION/;
+$VERSION=0.01;
+
+sub _Init {
+ my $self = shift;
+ my $handle = shift;
+ $self->Table('Employees');
+ $self->_Handle($handle);
+}
+
+sub _ClassAccessible {
+ {
+
+ id =>
+ {read => 1, type => 'int(11)'},
+ Name =>
+ {read => 1, write => 1, type => 'varchar(18)'},
+
+ }
+}
+
+1;
+
+package TestApp::Phone;
+
+use vars qw/$VERSION/;
+$VERSION=0.01;
+
+use base qw/DBIx::SearchBuilder::Record/;
+
+sub _Init {
+ my $self = shift;
+ my $handle = shift;
+ $self->Table('Phones');
+ $self->_Handle($handle);
+}
+
+sub _ClassAccessible {
+ {
+
+ id =>
+ {read => 1, type => 'int(11)'},
+ Employee =>
+ {read => 1, write => 1, type => 'int(11)', object => 'TestApp::Employee' },
+ Value =>
+ {read => 1, write => 1, type => 'varchar(18)'},
+
+ }
+}
+
+
+1;
More information about the Rt-commit
mailing list