[Jifty-commit] r1107 - in Jifty-DBI/trunk: lib/Jifty t
jifty-commit at lists.jifty.org
jifty-commit at lists.jifty.org
Tue May 23 14:21:38 EDT 2006
Author: alexmv
Date: Tue May 23 14:21:36 2006
New Revision: 1107
Modified:
Jifty-DBI/trunk/ (props changed)
Jifty-DBI/trunk/lib/Jifty/DBI.pm
Jifty-DBI/trunk/t/01-version_checks.t
Jifty-DBI/trunk/t/01basics.t
Jifty-DBI/trunk/t/01records.t
Jifty-DBI/trunk/t/01searches.t
Jifty-DBI/trunk/t/02records_object.t
Jifty-DBI/trunk/t/03rebless.t
Jifty-DBI/trunk/t/06filter_datetime.t
Jifty-DBI/trunk/t/06filter_truncate.t
Jifty-DBI/trunk/t/06filter_utf8.t
Jifty-DBI/trunk/t/10schema.t
Jifty-DBI/trunk/t/11schema_records.t
Jifty-DBI/trunk/t/utils.pl
Log:
r13252 at zoq-fot-pik: chmrr | 2006-05-23 14:20:56 -0400
* Untabify
Modified: Jifty-DBI/trunk/lib/Jifty/DBI.pm
==============================================================================
--- Jifty-DBI/trunk/lib/Jifty/DBI.pm (original)
+++ Jifty-DBI/trunk/lib/Jifty/DBI.pm Tue May 23 14:21:36 2006
@@ -184,13 +184,13 @@
Finally, adding a removing records from the database. ::Record provides a
Create method which simply takes a hash of key=>value pairs. The keys
-exactly map to database columns.
+exactly map to database columns.
## Get a new record object.
$s1 = Simple->new($handle);
my ($id, $status_msg) = $s1->create(id => 4,
- foo => 'Foooooo',
- bar => 'Barrrrr');
+ foo => 'Foooooo',
+ bar => 'Barrrrr');
Poof! A new row in the database has been created! Now lets delete the
object!
Modified: Jifty-DBI/trunk/t/01-version_checks.t
==============================================================================
--- Jifty-DBI/trunk/t/01-version_checks.t (original)
+++ Jifty-DBI/trunk/t/01-version_checks.t Tue May 23 14:21:36 2006
@@ -19,9 +19,9 @@
# die join "\n", '', @files, '';
foreach my $file (@files) {
- # Gah! parse_version complains on stderr!
- my ($e, @a) = error_catch(sub {MM->parse_version($file)});
- ok(($e || '') eq '', $file) or warn "$e ";
+ # Gah! parse_version complains on stderr!
+ my ($e, @a) = error_catch(sub {MM->parse_version($file)});
+ ok(($e || '') eq '', $file) or warn "$e ";
}
# runs subroutine reference, looking for error message $look in STDERR
@@ -29,15 +29,15 @@
# ($errs, @ans) = error_catch(sub {$this->test()});
#
sub error_catch {
- my ($sub) = @_;
- my $TO_ERR;
- open($TO_ERR, '<&STDERR');
- close(STDERR);
- my $catch;
- open(STDERR, '>', \$catch);
- my @ans = $sub->();
- open(STDERR, ">&", $TO_ERR);
- close($TO_ERR);
- return($catch, @ans);
+ my ($sub) = @_;
+ my $TO_ERR;
+ open($TO_ERR, '<&STDERR');
+ close(STDERR);
+ my $catch;
+ open(STDERR, '>', \$catch);
+ my @ans = $sub->();
+ open(STDERR, ">&", $TO_ERR);
+ close($TO_ERR);
+ return($catch, @ans);
} # end subroutine error_catch definition
########################################################################
Modified: Jifty-DBI/trunk/t/01basics.t
==============================================================================
--- Jifty-DBI/trunk/t/01basics.t (original)
+++ Jifty-DBI/trunk/t/01basics.t Tue May 23 14:21:36 2006
@@ -13,11 +13,11 @@
foreach my $d ( @available_drivers ) {
SKIP: {
- use_ok('Jifty::DBI::Handle::'. $d);
- my $handle = get_handle( $d );
- isa_ok($handle, 'Jifty::DBI::Handle');
- isa_ok($handle, 'Jifty::DBI::Handle::'. $d);
- can_ok($handle, 'dbh');
+ use_ok('Jifty::DBI::Handle::'. $d);
+ my $handle = get_handle( $d );
+ isa_ok($handle, 'Jifty::DBI::Handle');
+ isa_ok($handle, 'Jifty::DBI::Handle::'. $d);
+ can_ok($handle, 'dbh');
}
}
Modified: Jifty-DBI/trunk/t/01records.t
==============================================================================
--- Jifty-DBI/trunk/t/01records.t (original)
+++ Jifty-DBI/trunk/t/01records.t Tue May 23 14:21:36 2006
@@ -15,193 +15,193 @@
foreach my $d ( @available_drivers ) {
SKIP: {
- unless( has_schema( 'TestApp::Address', $d ) ) {
- skip "No schema for '$d' driver", TESTS_PER_DRIVER;
- }
- unless( should_test( $d ) ) {
- skip "ENV is not defined for driver '$d'", TESTS_PER_DRIVER;
- }
-
- my $handle = get_handle( $d );
- connect_handle( $handle );
- isa_ok($handle->dbh, 'DBI::db');
+ unless( has_schema( 'TestApp::Address', $d ) ) {
+ skip "No schema for '$d' driver", TESTS_PER_DRIVER;
+ }
+ unless( should_test( $d ) ) {
+ skip "ENV is not defined for driver '$d'", TESTS_PER_DRIVER;
+ }
+
+ my $handle = get_handle( $d );
+ connect_handle( $handle );
+ isa_ok($handle->dbh, 'DBI::db');
- my $ret = init_schema( 'TestApp::Address', $handle );
- isa_ok($ret,'DBI::st', "Inserted the schema. got a statement handle back");
+ my $ret = init_schema( 'TestApp::Address', $handle );
+ isa_ok($ret,'DBI::st', "Inserted the schema. got a statement handle back");
- my $rec = TestApp::Address->new($handle);
- isa_ok($rec, 'Jifty::DBI::Record');
+ my $rec = TestApp::Address->new($handle);
+ isa_ok($rec, 'Jifty::DBI::Record');
# _accessible testings
- is( $rec->_accessible('id' => 'read'), 1, 'id is accessible for read' );
- is( $rec->_accessible('id' => 'write'), 0, 'id is not accessible for write' );
- is( $rec->_accessible('id'), undef, "any column is not accessible in undefined mode" );
- is( $rec->_accessible('unexpected_column' => 'read'), undef, "column doesn't exist and can't be accessible for read" );
+ is( $rec->_accessible('id' => 'read'), 1, 'id is accessible for read' );
+ is( $rec->_accessible('id' => 'write'), 0, 'id is not accessible for write' );
+ is( $rec->_accessible('id'), undef, "any column is not accessible in undefined mode" );
+ is( $rec->_accessible('unexpected_column' => 'read'), undef, "column doesn't exist and can't be accessible for read" );
- is_deeply( [sort($rec->readable_attributes)], [sort qw(address employee_id id name phone)], 'readable attributes' );
- is_deeply( [sort($rec->writable_attributes)], [sort qw(address employee_id name phone)], 'writable attributes' );
+ is_deeply( [sort($rec->readable_attributes)], [sort qw(address employee_id id name phone)], 'readable attributes' );
+ is_deeply( [sort($rec->writable_attributes)], [sort qw(address employee_id name phone)], 'writable attributes' );
- can_ok($rec,'create');
+ can_ok($rec,'create');
- my ($id) = $rec->create( name => 'Jesse', phone => '617 124 567');
- ok($id,"Created record ". $id);
- ok($rec->load($id), "Loaded the record");
+ my ($id) = $rec->create( name => 'Jesse', phone => '617 124 567');
+ ok($id,"Created record ". $id);
+ ok($rec->load($id), "Loaded the record");
- is($rec->id, $id, "The record has its id");
- is ($rec->name, 'Jesse', "The record's name is Jesse");
+ is($rec->id, $id, "The record has its id");
+ is ($rec->name, 'Jesse', "The record's name is Jesse");
- my ($val, $msg) = $rec->set_name('Obra');
- ok($val, $msg) ;
- is($rec->name, 'Obra', "We did actually change the name");
+ my ($val, $msg) = $rec->set_name('Obra');
+ ok($val, $msg) ;
+ is($rec->name, 'Obra', "We did actually change the name");
# Validate immutability of the column id
- ($val, $msg) = $rec->set_id( $rec->id + 1 );
- ok(!$val, $msg);
- is($msg, 'Immutable column', 'id is immutable column');
- is($rec->id, $id, "The record still has its id");
+ ($val, $msg) = $rec->set_id( $rec->id + 1 );
+ ok(!$val, $msg);
+ is($msg, 'Immutable column', 'id is immutable column');
+ is($rec->id, $id, "The record still has its id");
# Check some non existant column
- ok( !eval{ $rec->some_unexpected_column }, "The record has no 'some_unexpected_column'");
- {
- # test produce DBI warning
- local $SIG{__WARN__} = sub {return};
- is( $rec->_value( 'some_unexpected_column' ), undef, "The record has no 'some_unexpected_column'");
- }
- ok (!eval { $rec->set_some_unexpected_column( 'foo' )}, "Can't call nonexistent columns");
- ($val, $msg) = $rec->_set(column =>'some_unexpected_column', value =>'foo');
- ok(!$val, "$msg");
+ ok( !eval{ $rec->some_unexpected_column }, "The record has no 'some_unexpected_column'");
+ {
+ # test produce DBI warning
+ local $SIG{__WARN__} = sub {return};
+ is( $rec->_value( 'some_unexpected_column' ), undef, "The record has no 'some_unexpected_column'");
+ }
+ ok (!eval { $rec->set_some_unexpected_column( 'foo' )}, "Can't call nonexistent columns");
+ ($val, $msg) = $rec->_set(column =>'some_unexpected_column', value =>'foo');
+ ok(!$val, "$msg");
# Validate truncation on update
- ($val,$msg) = $rec->set_name('1234567890123456789012345678901234567890');
- ok($val, $msg);
- is($rec->name, '12345678901234', "Truncated on update");
+ ($val,$msg) = $rec->set_name('1234567890123456789012345678901234567890');
+ ok($val, $msg);
+ is($rec->name, '12345678901234', "Truncated on update");
# make sure we do _not_ truncate things which should not be truncated
- ($val,$msg) = $rec->set_employee_id('1234567890');
- ok($val, $msg) ;
- is($rec->employee_id, '1234567890', "Did not truncate id on create");
+ ($val,$msg) = $rec->set_employee_id('1234567890');
+ ok($val, $msg) ;
+ is($rec->employee_id, '1234567890', "Did not truncate id on create");
- #delete prev record
- $rec->delete;
+ #delete prev record
+ $rec->delete;
# make sure we do truncation on create
- my $newrec = TestApp::Address->new($handle);
- my $newid = $newrec->create( name => '1234567890123456789012345678901234567890',
- employee_id => '1234567890' );
-
- $newrec->load($newid);
-
- ok ($newid, "Created a new record");
- is($newrec->name, '12345678901234', "Truncated on create");
- is($newrec->employee_id, '1234567890', "Did not truncate id on create");
+ my $newrec = TestApp::Address->new($handle);
+ my $newid = $newrec->create( name => '1234567890123456789012345678901234567890',
+ employee_id => '1234567890' );
+
+ $newrec->load($newid);
+
+ ok ($newid, "Created a new record");
+ is($newrec->name, '12345678901234', "Truncated on create");
+ is($newrec->employee_id, '1234567890', "Did not truncate id on create");
# no prefetch feature and _load_from_sql sub checks
- $newrec = TestApp::Address->new($handle);
- ($val, $msg) = $newrec->_load_from_sql('SELECT id FROM addresses WHERE id = ?', $newid);
- is($val, 1, 'found object');
- is($newrec->name, '12345678901234', "autoloaded not prefetched column");
- is($newrec->employee_id, '1234567890', "autoloaded not prefetched column");
+ $newrec = TestApp::Address->new($handle);
+ ($val, $msg) = $newrec->_load_from_sql('SELECT id FROM addresses WHERE id = ?', $newid);
+ is($val, 1, 'found object');
+ is($newrec->name, '12345678901234', "autoloaded not prefetched column");
+ is($newrec->employee_id, '1234567890', "autoloaded not prefetched column");
# _load_from_sql and missing PK
- $newrec = TestApp::Address->new($handle);
- ($val, $msg) = $newrec->_load_from_sql('SELECT name FROM addresses WHERE name = ?', '12345678901234');
- is($val, 0, "didn't find object");
- is($msg, "Missing a primary key?", "reason is missing PK");
+ $newrec = TestApp::Address->new($handle);
+ ($val, $msg) = $newrec->_load_from_sql('SELECT name FROM addresses WHERE name = ?', '12345678901234');
+ is($val, 0, "didn't find object");
+ is($msg, "Missing a primary key?", "reason is missing PK");
# _load_from_sql and not existant row
- $newrec = TestApp::Address->new($handle);
- ($val, $msg) = $newrec->_load_from_sql('SELECT id FROM addresses WHERE id = ?', 0);
- is($val, 0, "didn't find object");
- is($msg, "Couldn't find row", "reason is wrong id");
+ $newrec = TestApp::Address->new($handle);
+ ($val, $msg) = $newrec->_load_from_sql('SELECT id FROM addresses WHERE id = ?', 0);
+ is($val, 0, "didn't find object");
+ is($msg, "Couldn't find row", "reason is wrong id");
# _load_from_sql and wrong SQL
- $newrec = TestApp::Address->new($handle);
- {
- local $SIG{__WARN__} = sub{return};
- ($val, $msg) = $newrec->_load_from_sql('SELECT ...');
- }
- is($val, 0, "didn't find object");
- is($msg, "Couldn't execute query", "reason is bad SQL");
+ $newrec = TestApp::Address->new($handle);
+ {
+ local $SIG{__WARN__} = sub{return};
+ ($val, $msg) = $newrec->_load_from_sql('SELECT ...');
+ }
+ is($val, 0, "didn't find object");
+ is($msg, "Couldn't execute query", "reason is bad SQL");
# test load_* methods
- $newrec = TestApp::Address->new($handle);
- $newrec->load();
- is( $newrec->id, undef, "can't load record with undef id");
-
- $newrec = TestApp::Address->new($handle);
- $newrec->load_by_cols( name => '12345678901234' );
- is( $newrec->id, $newid, "load record by 'name' column value");
+ $newrec = TestApp::Address->new($handle);
+ $newrec->load();
+ is( $newrec->id, undef, "can't load record with undef id");
+
+ $newrec = TestApp::Address->new($handle);
+ $newrec->load_by_cols( name => '12345678901234' );
+ is( $newrec->id, $newid, "load record by 'name' column value");
# load_by_col with operator
- $newrec = TestApp::Address->new($handle);
- $newrec->load_by_cols( name => { value => '%45678%',
- operator => 'LIKE' } );
- is( $newrec->id, $newid, "load record by 'name' with LIKE");
+ $newrec = TestApp::Address->new($handle);
+ $newrec->load_by_cols( name => { value => '%45678%',
+ operator => 'LIKE' } );
+ is( $newrec->id, $newid, "load record by 'name' with LIKE");
# load_by_primary_keys
- $newrec = TestApp::Address->new($handle);
- ($val, $msg) = $newrec->load_by_primary_keys( id => $newid );
- ok( $val, "load record by PK");
- is( $newrec->id, $newid, "loaded correct record");
- $newrec = TestApp::Address->new($handle);
- ($val, $msg) = $newrec->load_by_primary_keys( {id => $newid} );
- ok( $val, "load record by PK");
- is( $newrec->id, $newid, "loaded correct record" );
- $newrec = TestApp::Address->new($handle);
- ($val, $msg) = $newrec->load_by_primary_keys( phone => 'some' );
- ok( !$val, "couldn't load, missing PK column");
- is( $msg, "Missing PK column: 'id'", "right error message" );
+ $newrec = TestApp::Address->new($handle);
+ ($val, $msg) = $newrec->load_by_primary_keys( id => $newid );
+ ok( $val, "load record by PK");
+ is( $newrec->id, $newid, "loaded correct record");
+ $newrec = TestApp::Address->new($handle);
+ ($val, $msg) = $newrec->load_by_primary_keys( {id => $newid} );
+ ok( $val, "load record by PK");
+ is( $newrec->id, $newid, "loaded correct record" );
+ $newrec = TestApp::Address->new($handle);
+ ($val, $msg) = $newrec->load_by_primary_keys( phone => 'some' );
+ ok( !$val, "couldn't load, missing PK column");
+ is( $msg, "Missing PK column: 'id'", "right error message" );
# Defaults kick in
- $rec = TestApp::Address->new($handle);
- $id = $rec->create( name => 'Chmrr' );
- ok( $id, "new record");
- $rec = TestApp::Address->new($handle);
- $rec->load_by_cols( name => 'Chmrr' );
+ $rec = TestApp::Address->new($handle);
+ $id = $rec->create( name => 'Chmrr' );
+ ok( $id, "new record");
+ $rec = TestApp::Address->new($handle);
+ $rec->load_by_cols( name => 'Chmrr' );
is( $rec->id, $id, "loaded record by empty value" );
is( $rec->address, '', "Got default on create" );
# load_by_cols and empty or NULL values
- $rec = TestApp::Address->new($handle);
- $id = $rec->create( name => 'Obra', phone => undef );
- ok( $id, "new record");
- $rec = TestApp::Address->new($handle);
- $rec->load_by_cols( name => 'Obra', phone => undef, employee_id => '' );
+ $rec = TestApp::Address->new($handle);
+ $id = $rec->create( name => 'Obra', phone => undef );
+ ok( $id, "new record");
+ $rec = TestApp::Address->new($handle);
+ $rec->load_by_cols( name => 'Obra', phone => undef, employee_id => '' );
is( $rec->id, $id, "loaded record by empty value" );
# __set error paths
- $rec = TestApp::Address->new($handle);
- $rec->load( $id );
- $val = $rec->set_name( 'Obra' );
- isa_ok( $val, 'Class::ReturnValue', "couldn't set same value, error returned");
- is( ($val->as_array)[1], "That is already the current value", "correct error message" );
- is( $rec->name, 'Obra', "old value is still there");
- $val = $rec->set_name( 'invalid' );
- isa_ok( $val, 'Class::ReturnValue', "couldn't set invalid value, error returned");
- is( ($val->as_array)[1], 'Illegal value for name', "correct error message" );
- is( $rec->name, 'Obra', "old value is still there");
+ $rec = TestApp::Address->new($handle);
+ $rec->load( $id );
+ $val = $rec->set_name( 'Obra' );
+ isa_ok( $val, 'Class::ReturnValue', "couldn't set same value, error returned");
+ is( ($val->as_array)[1], "That is already the current value", "correct error message" );
+ is( $rec->name, 'Obra', "old value is still there");
+ $val = $rec->set_name( 'invalid' );
+ isa_ok( $val, 'Class::ReturnValue', "couldn't set invalid value, error returned");
+ is( ($val->as_array)[1], 'Illegal value for name', "correct error message" );
+ is( $rec->name, 'Obra', "old value is still there");
# XXX TODO FIXME: this test cover current implementation that is broken //RUZ
# fixed, now we can set undef values(NULLs)
- $val = $rec->set_name( );
- isa_ok( $val, 'Class::ReturnValue', "set empty/undef/NULL value");
- is( ($val->as_array)[1], "The new value has been set.", "correct error message" );
- is( $rec->name, undef, "new value is undef, NULL in DB");
+ $val = $rec->set_name( );
+ isa_ok( $val, 'Class::ReturnValue', "set empty/undef/NULL value");
+ is( ($val->as_array)[1], "The new value has been set.", "correct error message" );
+ is( $rec->name, undef, "new value is undef, NULL in DB");
# deletes
- $newrec = TestApp::Address->new($handle);
- $newrec->load( $newid );
- is( $newrec->delete, 1, 'successfuly delete record');
- $newrec = TestApp::Address->new($handle);
- $newrec->load( $newid );
- is( $newrec->id, undef, "record doesn't exist any more");
+ $newrec = TestApp::Address->new($handle);
+ $newrec->load( $newid );
+ is( $newrec->delete, 1, 'successfuly delete record');
+ $newrec = TestApp::Address->new($handle);
+ $newrec->load( $newid );
+ is( $newrec->id, undef, "record doesn't exist any more");
- cleanup_schema( 'TestApp::Address', $handle );
- disconnect_handle( $handle );
+ cleanup_schema( 'TestApp::Address', $handle );
+ disconnect_handle( $handle );
}} # SKIP, foreach blocks
1;
@@ -212,9 +212,9 @@
sub validate_name
{
- my ($self, $value) = @_;
- return 0 if $value && $value =~ /invalid/i;
- return 1;
+ my ($self, $value) = @_;
+ return 0 if $value && $value =~ /invalid/i;
+ return 1;
}
sub schema_mysql {
@@ -225,7 +225,7 @@
phone varchar(18),
address varchar(50),
employee_id int(8),
- PRIMARY KEY (id))
+ PRIMARY KEY (id))
EOF
}
Modified: Jifty-DBI/trunk/t/01searches.t
==============================================================================
--- Jifty-DBI/trunk/t/01searches.t (original)
+++ Jifty-DBI/trunk/t/01searches.t Tue May 23 14:21:36 2006
@@ -15,157 +15,157 @@
foreach my $d ( @available_drivers ) {
SKIP: {
- unless( has_schema( 'TestApp', $d ) ) {
- skip "No schema for '$d' driver", TESTS_PER_DRIVER;
- }
- unless( should_test( $d ) ) {
- skip "ENV is not defined for driver '$d'", TESTS_PER_DRIVER;
- }
-
- my $handle = get_handle( $d );
- connect_handle( $handle );
- isa_ok($handle->dbh, 'DBI::db');
-
- my $ret = init_schema( 'TestApp', $handle );
- isa_ok($ret,'DBI::st', "Inserted the schema. got a statement handle back");
-
- my $count_all = init_data( 'TestApp::User', $handle );
- ok( $count_all, "init users data" );
-
- my $users_obj = TestApp::UserCollection->new( $handle );
- isa_ok( $users_obj, 'Jifty::DBI::Collection' );
- is( $users_obj->_handle, $handle, "same handle as we used in constructor");
+ unless( has_schema( 'TestApp', $d ) ) {
+ skip "No schema for '$d' driver", TESTS_PER_DRIVER;
+ }
+ unless( should_test( $d ) ) {
+ skip "ENV is not defined for driver '$d'", TESTS_PER_DRIVER;
+ }
+
+ my $handle = get_handle( $d );
+ connect_handle( $handle );
+ isa_ok($handle->dbh, 'DBI::db');
+
+ my $ret = init_schema( 'TestApp', $handle );
+ isa_ok($ret,'DBI::st', "Inserted the schema. got a statement handle back");
+
+ my $count_all = init_data( 'TestApp::User', $handle );
+ ok( $count_all, "init users data" );
+
+ my $users_obj = TestApp::UserCollection->new( $handle );
+ isa_ok( $users_obj, 'Jifty::DBI::Collection' );
+ is( $users_obj->_handle, $handle, "same handle as we used in constructor");
# check that new object returns 0 records in any case
- is( $users_obj->_record_count, 0, '_record_count returns 0 on not limited obj' );
- is( $users_obj->count, 0, 'count returns 0 on not limited obj' );
- is( $users_obj->is_last, undef, 'is_last returns undef on not limited obj after count' );
- is( $users_obj->first, undef, 'first returns undef on not limited obj' );
- is( $users_obj->is_last, undef, 'is_last returns undef on not limited obj after first' );
- is( $users_obj->last, undef, 'last returns undef on not limited obj' );
- is( $users_obj->is_last, undef, 'is_last returns undef on not limited obj after last' );
- $users_obj->goto_first_item;
- is( $users_obj->next, undef, 'next returns undef on not limited obj' );
- is( $users_obj->is_last, undef, 'is_last returns undef on not limited obj after next' );
- # XXX TODO FIXME: may be this methods should be implemented
- # $users_obj->goto_last_item;
- # is( $users_obj->prev, undef, 'prev returns undef on not limited obj' );
- my $items_ref = $users_obj->items_array_ref;
- isa_ok( $items_ref, 'ARRAY', 'items_array_ref always returns array reference' );
- is_deeply( $items_ref, [], 'items_array_ref returns [] on not limited obj' );
+ is( $users_obj->_record_count, 0, '_record_count returns 0 on not limited obj' );
+ is( $users_obj->count, 0, 'count returns 0 on not limited obj' );
+ is( $users_obj->is_last, undef, 'is_last returns undef on not limited obj after count' );
+ is( $users_obj->first, undef, 'first returns undef on not limited obj' );
+ is( $users_obj->is_last, undef, 'is_last returns undef on not limited obj after first' );
+ is( $users_obj->last, undef, 'last returns undef on not limited obj' );
+ is( $users_obj->is_last, undef, 'is_last returns undef on not limited obj after last' );
+ $users_obj->goto_first_item;
+ is( $users_obj->next, undef, 'next returns undef on not limited obj' );
+ is( $users_obj->is_last, undef, 'is_last returns undef on not limited obj after next' );
+ # XXX TODO FIXME: may be this methods should be implemented
+ # $users_obj->goto_last_item;
+ # is( $users_obj->prev, undef, 'prev returns undef on not limited obj' );
+ my $items_ref = $users_obj->items_array_ref;
+ isa_ok( $items_ref, 'ARRAY', 'items_array_ref always returns array reference' );
+ is_deeply( $items_ref, [], 'items_array_ref returns [] on not limited obj' );
# unlimit new object and check
- $users_obj->unlimit;
- is( $users_obj->count, $count_all, 'count returns same number of records as was inserted' );
- isa_ok( $users_obj->first, 'Jifty::DBI::Record', 'first returns record object' );
- isa_ok( $users_obj->last, 'Jifty::DBI::Record', 'last returns record object' );
- $users_obj->goto_first_item;
- isa_ok( $users_obj->next, 'Jifty::DBI::Record', 'next returns record object' );
- $items_ref = $users_obj->items_array_ref;
- isa_ok( $items_ref, 'ARRAY', 'items_array_ref always returns array reference' );
- is( scalar @{$items_ref}, $count_all, 'items_array_ref returns same number of records as was inserted' );
- $users_obj->redo_search;
- $items_ref = $users_obj->items_array_ref;
- isa_ok( $items_ref, 'ARRAY', 'items_array_ref always returns array reference' );
- is( scalar @{$items_ref}, $count_all, 'items_array_ref returns same number of records as was inserted' );
+ $users_obj->unlimit;
+ is( $users_obj->count, $count_all, 'count returns same number of records as was inserted' );
+ isa_ok( $users_obj->first, 'Jifty::DBI::Record', 'first returns record object' );
+ isa_ok( $users_obj->last, 'Jifty::DBI::Record', 'last returns record object' );
+ $users_obj->goto_first_item;
+ isa_ok( $users_obj->next, 'Jifty::DBI::Record', 'next returns record object' );
+ $items_ref = $users_obj->items_array_ref;
+ isa_ok( $items_ref, 'ARRAY', 'items_array_ref always returns array reference' );
+ is( scalar @{$items_ref}, $count_all, 'items_array_ref returns same number of records as was inserted' );
+ $users_obj->redo_search;
+ $items_ref = $users_obj->items_array_ref;
+ isa_ok( $items_ref, 'ARRAY', 'items_array_ref always returns array reference' );
+ is( scalar @{$items_ref}, $count_all, 'items_array_ref returns same number of records as was inserted' );
# try to use $users_obj for all tests, after each call to CleanSlate it should look like new obj.
# and test $obj->new syntax
- my $clean_obj = $users_obj->new( $handle );
- isa_ok( $clean_obj, 'Jifty::DBI::Collection' );
+ my $clean_obj = $users_obj->new( $handle );
+ isa_ok( $clean_obj, 'Jifty::DBI::Collection' );
# basic limits
- $users_obj->clean_slate;
- is_deeply( $users_obj, $clean_obj, 'after clean_slate looks like new object');
- $users_obj->limit( column => 'login', value => 'obra' );
- is( $users_obj->count, 1, 'found one user with login obra' );
- TODO: {
- local $TODO = 'require discussion';
- is( $users_obj->is_last, undef, 'is_last returns undef before we fetch any record' );
- }
- my $first_rec = $users_obj->first;
- isa_ok( $first_rec, 'Jifty::DBI::Record', 'First returns record object' );
- is( $users_obj->is_last, 1, '1 record in the collection then first rec is last');
- is( $first_rec->login, 'obra', 'login is correct' );
- my $last_rec = $users_obj->last;
- is( $last_rec, $first_rec, 'last returns same object as first' );
- is( $users_obj->is_last, 1, 'is_last always returns 1 after last call');
- $users_obj->goto_first_item;
- my $next_rec = $users_obj->next;
- is( $next_rec, $first_rec, 'next returns same object as first' );
- is( $users_obj->is_last, 1, 'is_last returns 1 after fetch first record with next method');
- is( $users_obj->next, undef, 'only one record in the collection' );
- TODO: {
- local $TODO = 'require discussion';
- is( $users_obj->is_last, undef, 'next returns undef, is_last returns undef too');
- }
- $items_ref = $users_obj->items_array_ref;
- isa_ok( $items_ref, 'ARRAY', 'items_array_ref always returns array reference' );
- is( scalar @{$items_ref}, 1, 'items_array_ref has only 1 record' );
+ $users_obj->clean_slate;
+ is_deeply( $users_obj, $clean_obj, 'after clean_slate looks like new object');
+ $users_obj->limit( column => 'login', value => 'obra' );
+ is( $users_obj->count, 1, 'found one user with login obra' );
+ TODO: {
+ local $TODO = 'require discussion';
+ is( $users_obj->is_last, undef, 'is_last returns undef before we fetch any record' );
+ }
+ my $first_rec = $users_obj->first;
+ isa_ok( $first_rec, 'Jifty::DBI::Record', 'First returns record object' );
+ is( $users_obj->is_last, 1, '1 record in the collection then first rec is last');
+ is( $first_rec->login, 'obra', 'login is correct' );
+ my $last_rec = $users_obj->last;
+ is( $last_rec, $first_rec, 'last returns same object as first' );
+ is( $users_obj->is_last, 1, 'is_last always returns 1 after last call');
+ $users_obj->goto_first_item;
+ my $next_rec = $users_obj->next;
+ is( $next_rec, $first_rec, 'next returns same object as first' );
+ is( $users_obj->is_last, 1, 'is_last returns 1 after fetch first record with next method');
+ is( $users_obj->next, undef, 'only one record in the collection' );
+ TODO: {
+ local $TODO = 'require discussion';
+ is( $users_obj->is_last, undef, 'next returns undef, is_last returns undef too');
+ }
+ $items_ref = $users_obj->items_array_ref;
+ isa_ok( $items_ref, 'ARRAY', 'items_array_ref always returns array reference' );
+ is( scalar @{$items_ref}, 1, 'items_array_ref has only 1 record' );
# similar basic limit, but with different operatorS and less first/next/last tests
- # LIKE
- $users_obj->clean_slate;
- is_deeply( $users_obj, $clean_obj, 'after clean_slate looks like new object');
- $users_obj->limit( column => 'name', operator => 'MATCHES', value => 'Glass' );
- is( $users_obj->count, 1, "found one user with 'Glass' in the name" );
- $first_rec = $users_obj->first;
- isa_ok( $first_rec, 'Jifty::DBI::Record', 'First returns record object' );
- is( $first_rec->login, 'glasser', 'login is correct' );
-
- # STARTSWITH
- $users_obj->clean_slate;
- is_deeply( $users_obj, $clean_obj, 'after clean_slate looks like new object');
- $users_obj->limit( column => 'name', operator => 'STARTSWITH', value => 'Ruslan' );
- is( $users_obj->count, 1, "found one user who name starts with 'Ruslan'" );
- $first_rec = $users_obj->first;
- isa_ok( $first_rec, 'Jifty::DBI::Record', 'First returns record object' );
- is( $first_rec->login, 'cubic', 'login is correct' );
-
- # ENDSWITH
- $users_obj->clean_slate;
- is_deeply( $users_obj, $clean_obj, 'after clean_slate looks like new object');
- $users_obj->limit( column => 'name', operator => 'ENDSWITH', value => 'Tang' );
- is( $users_obj->count, 1, "found one user who name ends with 'Tang'" );
- $first_rec = $users_obj->first;
- isa_ok( $first_rec, 'Jifty::DBI::Record', 'First returns record object' );
- is( $first_rec->login, 'audreyt', 'login is correct' );
-
- # IS NULL
- # XXX TODO FIXME: column => undef should be handled as NULL
- $users_obj->clean_slate;
- is_deeply( $users_obj, $clean_obj, 'after clean_slate looks like new object');
- $users_obj->limit( column => 'phone', operator => 'IS', value => 'NULL' );
- is( $users_obj->count, 2, "found 2 users who has unknown phone number" );
- $users_obj->clean_slate;
- is_deeply( $users_obj, $clean_obj, 'after clean_slate looks like new object');
- $users_obj->limit( column => 'address', operator => 'IS', value => 'NULL' );
- is( $users_obj->count, 0, "found 0 users who has unknown address" );
-
- # IS NOT NULL
- $users_obj->clean_slate;
- is_deeply( $users_obj, $clean_obj, 'after clean_slate looks like new object');
- $users_obj->limit( column => 'phone', operator => 'IS NOT', value => 'NULL', QOUTEvalue => 0 );
- is( $users_obj->count, $count_all - 2, "found users who have phone number filled" );
- $users_obj->clean_slate;
- is_deeply( $users_obj, $clean_obj, 'after clean_slate looks like new object');
- $users_obj->limit( column => 'address', operator => 'IS NOT', value => 'NULL', QOUTEvalue => 0 );
- is( $users_obj->count, $count_all, "found users who have address filled" );
-
- # ORDER BY / GROUP BY
- $users_obj->clean_slate;
- is_deeply( $users_obj, $clean_obj, 'after clean_slate looks like new object');
- $users_obj->unlimit;
- $users_obj->group_by(column => 'login');
- $users_obj->order_by(column => 'login', order => 'desc');
- $users_obj->column(column => 'login');
- is( $users_obj->count, $count_all, "group by / order by finds right amount");
- $first_rec = $users_obj->first;
- isa_ok( $first_rec, 'Jifty::DBI::Record', 'First returns record object' );
- is( $first_rec->login, 'obra', 'login is correct' );
+ # LIKE
+ $users_obj->clean_slate;
+ is_deeply( $users_obj, $clean_obj, 'after clean_slate looks like new object');
+ $users_obj->limit( column => 'name', operator => 'MATCHES', value => 'Glass' );
+ is( $users_obj->count, 1, "found one user with 'Glass' in the name" );
+ $first_rec = $users_obj->first;
+ isa_ok( $first_rec, 'Jifty::DBI::Record', 'First returns record object' );
+ is( $first_rec->login, 'glasser', 'login is correct' );
+
+ # STARTSWITH
+ $users_obj->clean_slate;
+ is_deeply( $users_obj, $clean_obj, 'after clean_slate looks like new object');
+ $users_obj->limit( column => 'name', operator => 'STARTSWITH', value => 'Ruslan' );
+ is( $users_obj->count, 1, "found one user who name starts with 'Ruslan'" );
+ $first_rec = $users_obj->first;
+ isa_ok( $first_rec, 'Jifty::DBI::Record', 'First returns record object' );
+ is( $first_rec->login, 'cubic', 'login is correct' );
+
+ # ENDSWITH
+ $users_obj->clean_slate;
+ is_deeply( $users_obj, $clean_obj, 'after clean_slate looks like new object');
+ $users_obj->limit( column => 'name', operator => 'ENDSWITH', value => 'Tang' );
+ is( $users_obj->count, 1, "found one user who name ends with 'Tang'" );
+ $first_rec = $users_obj->first;
+ isa_ok( $first_rec, 'Jifty::DBI::Record', 'First returns record object' );
+ is( $first_rec->login, 'audreyt', 'login is correct' );
+
+ # IS NULL
+ # XXX TODO FIXME: column => undef should be handled as NULL
+ $users_obj->clean_slate;
+ is_deeply( $users_obj, $clean_obj, 'after clean_slate looks like new object');
+ $users_obj->limit( column => 'phone', operator => 'IS', value => 'NULL' );
+ is( $users_obj->count, 2, "found 2 users who has unknown phone number" );
+ $users_obj->clean_slate;
+ is_deeply( $users_obj, $clean_obj, 'after clean_slate looks like new object');
+ $users_obj->limit( column => 'address', operator => 'IS', value => 'NULL' );
+ is( $users_obj->count, 0, "found 0 users who has unknown address" );
+
+ # IS NOT NULL
+ $users_obj->clean_slate;
+ is_deeply( $users_obj, $clean_obj, 'after clean_slate looks like new object');
+ $users_obj->limit( column => 'phone', operator => 'IS NOT', value => 'NULL', QOUTEvalue => 0 );
+ is( $users_obj->count, $count_all - 2, "found users who have phone number filled" );
+ $users_obj->clean_slate;
+ is_deeply( $users_obj, $clean_obj, 'after clean_slate looks like new object');
+ $users_obj->limit( column => 'address', operator => 'IS NOT', value => 'NULL', QOUTEvalue => 0 );
+ is( $users_obj->count, $count_all, "found users who have address filled" );
+
+ # ORDER BY / GROUP BY
+ $users_obj->clean_slate;
+ is_deeply( $users_obj, $clean_obj, 'after clean_slate looks like new object');
+ $users_obj->unlimit;
+ $users_obj->group_by(column => 'login');
+ $users_obj->order_by(column => 'login', order => 'desc');
+ $users_obj->column(column => 'login');
+ is( $users_obj->count, $count_all, "group by / order by finds right amount");
+ $first_rec = $users_obj->first;
+ isa_ok( $first_rec, 'Jifty::DBI::Record', 'First returns record object' );
+ is( $first_rec->login, 'obra', 'login is correct' );
- cleanup_schema( 'TestApp', $handle );
- disconnect_handle( $handle );
+ cleanup_schema( 'TestApp', $handle );
+ disconnect_handle( $handle );
}} # SKIP, foreach blocks
1;
@@ -178,9 +178,9 @@
id integer AUTO_INCREMENT,
login varchar(18) NOT NULL,
name varchar(36),
- phone varchar(18),
- address varchar(18),
- PRIMARY KEY (id))
+ phone varchar(18),
+ address varchar(18),
+ PRIMARY KEY (id))
EOF
}
@@ -192,7 +192,7 @@
login varchar(18) NOT NULL,
name varchar(36),
phone varchar(18),
- address varchar(18)
+ address varchar(18)
)
EOF
@@ -202,11 +202,11 @@
<<EOF;
CREATE table users (
- id integer primary key,
- login varchar(18) NOT NULL,
- name varchar(36),
- phone varchar(18),
- address varchar(18))
+ id integer primary key,
+ login varchar(18) NOT NULL,
+ name varchar(36),
+ phone varchar(18),
+ address varchar(18))
EOF
}
Modified: Jifty-DBI/trunk/t/02records_object.t
==============================================================================
--- Jifty-DBI/trunk/t/02records_object.t (original)
+++ Jifty-DBI/trunk/t/02records_object.t Tue May 23 14:21:36 2006
@@ -16,38 +16,38 @@
foreach my $d ( @available_drivers ) {
SKIP: {
- unless( has_schema( 'TestApp', $d ) ) {
- skip "No schema for '$d' driver", TESTS_PER_DRIVER;
- }
- unless( should_test( $d ) ) {
- skip "ENV is not defined for driver '$d'", TESTS_PER_DRIVER;
- }
-
- my $handle = get_handle( $d );
- connect_handle( $handle );
- isa_ok($handle->dbh, 'DBI::db');
-
- my $ret = init_schema( 'TestApp', $handle );
- 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, "Got an id for the new emplyee");
- my $phone = TestApp::Phone->new($handle);
- isa_ok( $phone, 'TestApp::Phone', "it's a TestApp::Phone");
- my $p_id = $phone->create( employee => $e_id, phone => '+7(903)264-03-51');
- # XXX: test fails if next string is commented
- is($p_id, 1, "Loaded record $p_id");
- $phone->load( $p_id );
-
- my $obj = $phone->employee($handle);
- ok($obj, "Employee #$e_id has phone #$p_id");
- isa_ok( $obj, 'TestApp::Employee');
- is($obj->id, $e_id);
- is($obj->name, 'RUZ');
+ unless( has_schema( 'TestApp', $d ) ) {
+ skip "No schema for '$d' driver", TESTS_PER_DRIVER;
+ }
+ unless( should_test( $d ) ) {
+ skip "ENV is not defined for driver '$d'", TESTS_PER_DRIVER;
+ }
+
+ my $handle = get_handle( $d );
+ connect_handle( $handle );
+ isa_ok($handle->dbh, 'DBI::db');
+
+ my $ret = init_schema( 'TestApp', $handle );
+ 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, "Got an id for the new emplyee");
+ my $phone = TestApp::Phone->new($handle);
+ isa_ok( $phone, 'TestApp::Phone', "it's a TestApp::Phone");
+ my $p_id = $phone->create( employee => $e_id, phone => '+7(903)264-03-51');
+ # XXX: test fails if next string is commented
+ is($p_id, 1, "Loaded record $p_id");
+ $phone->load( $p_id );
+
+ my $obj = $phone->employee($handle);
+ ok($obj, "Employee #$e_id has phone #$p_id");
+ isa_ok( $obj, 'TestApp::Employee');
+ is($obj->id, $e_id);
+ is($obj->name, 'RUZ');
- cleanup_schema( 'TestApp', $handle );
- disconnect_handle( $handle );
+ cleanup_schema( 'TestApp', $handle );
+ disconnect_handle( $handle );
}} # SKIP, foreach blocks
1;
@@ -58,14 +58,14 @@
[
q{
CREATE table employees (
- id integer primary key,
- name varchar(36)
+ id integer primary key,
+ name varchar(36)
)
}, q{
CREATE table phones (
- id integer primary key,
- employee integer NOT NULL,
- phone varchar(18)
+ id integer primary key,
+ employee integer NOT NULL,
+ phone varchar(18)
) }
]
}
@@ -73,14 +73,14 @@
sub schema_mysql {
[ q{
CREATE TEMPORARY table employees (
- id integer AUTO_INCREMENT primary key,
- name varchar(36)
+ id integer AUTO_INCREMENT primary key,
+ name varchar(36)
)
}, q{
CREATE TEMPORARY table phones (
- id integer AUTO_INCREMENT primary key,
- employee integer NOT NULL,
- phone varchar(18)
+ id integer AUTO_INCREMENT primary key,
+ employee integer NOT NULL,
+ phone varchar(18)
)
} ]
}
@@ -88,14 +88,14 @@
sub schema_pg {
[ q{
CREATE TEMPORARY table employees (
- id serial PRIMARY KEY,
- name varchar
+ id serial PRIMARY KEY,
+ name varchar
)
}, q{
CREATE TEMPORARY table phones (
- id serial PRIMARY KEY,
- employee integer references employees(id),
- phone varchar
+ id serial PRIMARY KEY,
+ employee integer references employees(id),
+ phone varchar
)
} ]
}
Modified: Jifty-DBI/trunk/t/03rebless.t
==============================================================================
--- Jifty-DBI/trunk/t/03rebless.t (original)
+++ Jifty-DBI/trunk/t/03rebless.t Tue May 23 14:21:36 2006
@@ -17,20 +17,20 @@
foreach my $d ( @available_drivers ) {
SKIP: {
- unless( should_test( $d ) ) {
- skip "ENV is not defined for driver '$d'", TESTS_PER_DRIVER;
- }
+ unless( should_test( $d ) ) {
+ skip "ENV is not defined for driver '$d'", TESTS_PER_DRIVER;
+ }
- my $handle = Jifty::DBI::Handle->new;
- ok($handle, "Made a generic handle");
-
- is(ref $handle, 'Jifty::DBI::Handle', "It's really generic");
-
- connect_handle_with_driver( $handle, $d );
- isa_ok($handle->dbh, 'DBI::db');
-
- isa_ok($handle, "Jifty::DBI::Handle::$d", "Specialized Handle");
- disconnect_handle_with_driver( $handle, $d );
+ my $handle = Jifty::DBI::Handle->new;
+ ok($handle, "Made a generic handle");
+
+ is(ref $handle, 'Jifty::DBI::Handle', "It's really generic");
+
+ connect_handle_with_driver( $handle, $d );
+ isa_ok($handle->dbh, 'DBI::db');
+
+ isa_ok($handle, "Jifty::DBI::Handle::$d", "Specialized Handle");
+ disconnect_handle_with_driver( $handle, $d );
}} # SKIP, foreach blocks
1;
Modified: Jifty-DBI/trunk/t/06filter_datetime.t
==============================================================================
--- Jifty-DBI/trunk/t/06filter_datetime.t (original)
+++ Jifty-DBI/trunk/t/06filter_datetime.t Tue May 23 14:21:36 2006
@@ -15,48 +15,48 @@
foreach my $d ( @available_drivers ) {
SKIP: {
- unless( has_schema( 'TestApp::User', $d ) ) {
- skip "No schema for '$d' driver", TESTS_PER_DRIVER;
- }
- unless( should_test( $d ) ) {
- skip "ENV is not defined for driver '$d'", TESTS_PER_DRIVER;
- }
- diag("start testing with '$d' handle") if $ENV{TEST_VERBOSE};
-
- my $handle = get_handle( $d );
- connect_handle( $handle );
- isa_ok($handle->dbh, 'DBI::db');
+ unless( has_schema( 'TestApp::User', $d ) ) {
+ skip "No schema for '$d' driver", TESTS_PER_DRIVER;
+ }
+ unless( should_test( $d ) ) {
+ skip "ENV is not defined for driver '$d'", TESTS_PER_DRIVER;
+ }
+ diag("start testing with '$d' handle") if $ENV{TEST_VERBOSE};
+
+ my $handle = get_handle( $d );
+ connect_handle( $handle );
+ isa_ok($handle->dbh, 'DBI::db');
- my $ret = init_schema( 'TestApp::User', $handle );
- isa_ok($ret,'DBI::st', "Inserted the schema. got a statement handle back");
+ my $ret = init_schema( 'TestApp::User', $handle );
+ isa_ok($ret,'DBI::st', "Inserted the schema. got a statement handle back");
- my $rec = TestApp::User->new($handle);
- isa_ok($rec, 'Jifty::DBI::Record');
+ my $rec = TestApp::User->new($handle);
+ isa_ok($rec, 'Jifty::DBI::Record');
- my $now = time;
+ my $now = time;
my $today = DateTime->from_epoch( epoch => $now )->truncate( to => 'day' )->epoch;
- my $dt = DateTime->from_epoch( epoch => $now );
- my($id) = $rec->create( created => $dt, event_on => $dt );
- ok($id, "Successfuly created ticket");
- ok($rec->load($id), "Loaded the record");
- is($rec->id, $id, "The record has its id");
- isa_ok($rec->created, 'DateTime' );
- is( $rec->created->epoch, $now, "Correct value");
+ my $dt = DateTime->from_epoch( epoch => $now );
+ my($id) = $rec->create( created => $dt, event_on => $dt );
+ ok($id, "Successfuly created ticket");
+ ok($rec->load($id), "Loaded the record");
+ is($rec->id, $id, "The record has its id");
+ isa_ok($rec->created, 'DateTime' );
+ is( $rec->created->epoch, $now, "Correct value");
isa_ok($rec->event_on, 'DateTime' );
is( $rec->event_on->epoch, $today, "Correct value");
- # undef/NULL
- $rec->set_created;
- is($rec->created, undef, "Set undef value" );
-
- # from string
- require POSIX;
- $rec->set_created( POSIX::strftime( "%Y-%m-%d %H:%M:%S", gmtime($now) ) );
- isa_ok($rec->created, 'DateTime' );
- is( $rec->created->epoch, $now, "Correct value");
+ # undef/NULL
+ $rec->set_created;
+ is($rec->created, undef, "Set undef value" );
+
+ # from string
+ require POSIX;
+ $rec->set_created( POSIX::strftime( "%Y-%m-%d %H:%M:%S", gmtime($now) ) );
+ isa_ok($rec->created, 'DateTime' );
+ is( $rec->created->epoch, $now, "Correct value");
- cleanup_schema( 'TestApp', $handle );
- disconnect_handle( $handle );
+ cleanup_schema( 'TestApp', $handle );
+ disconnect_handle( $handle );
}
}
@@ -70,7 +70,7 @@
<<EOF;
CREATE table users (
id integer primary key,
- created datetime,
+ created datetime,
event_on date
)
EOF
@@ -82,7 +82,7 @@
<<EOF;
CREATE TEMPORARY table users (
id integer auto_increment primary key,
- created datetime,
+ created datetime,
event_on date
)
EOF
@@ -94,7 +94,7 @@
<<EOF;
CREATE TEMPORARY table users (
id serial primary key,
- created timestamp,
+ created timestamp,
event_on date
)
EOF
Modified: Jifty-DBI/trunk/t/06filter_truncate.t
==============================================================================
--- Jifty-DBI/trunk/t/06filter_truncate.t (original)
+++ Jifty-DBI/trunk/t/06filter_truncate.t Tue May 23 14:21:36 2006
@@ -13,62 +13,62 @@
foreach my $d ( @available_drivers ) {
SKIP: {
- unless( should_test( $d ) ) {
- skip "ENV is not defined for driver '$d'", TESTS_PER_DRIVER;
- }
- diag("start testing with '$d' handle") if $ENV{TEST_VERBOSE};
- my $handle = get_handle( $d );
- connect_handle( $handle );
- isa_ok($handle->dbh, 'DBI::db');
-
- unless( has_schema( 'TestApp::User', $handle ) ) {
- skip "No schema for '$d' driver", TESTS_PER_DRIVER - 1;
- }
-
- my $ret = init_schema( 'TestApp::User', $handle );
- isa_ok($ret,'DBI::st', "Inserted the schema. got a statement handle back");
-
- my $rec = TestApp::User->new($handle);
- isa_ok($rec, 'Jifty::DBI::Record');
-
- # name would be truncated
- my($id) = $rec->create( login => "obra", name => "Jesse Vincent" );
- ok($id, "Successfuly created ticket");
- ok($rec->load($id), "Loaded the record");
- is($rec->id, $id, "The record has its id");
- is($rec->login, 'obra', "Login is not truncated" );
- is($rec->name, 'Jesse Vinc', "But name is truncated" );
-
- # UTF-8 string with flag set
- use Encode ();
- ($id) = $rec->create( login => "\x{442}\x{435}\x{441}\x{442}", name => "test" );
- ok($id, "Successfuly created ticket");
- ok($rec->load($id), "Loaded the record");
- is($rec->id, $id, "The record has its id");
- is(Encode::decode_utf8($rec->login), "\x{442}\x{435}", "Login is truncated to two UTF-8 chars" );
- is($rec->name, 'test', "Name is not truncated" );
+ unless( should_test( $d ) ) {
+ skip "ENV is not defined for driver '$d'", TESTS_PER_DRIVER;
+ }
+ diag("start testing with '$d' handle") if $ENV{TEST_VERBOSE};
+ my $handle = get_handle( $d );
+ connect_handle( $handle );
+ isa_ok($handle->dbh, 'DBI::db');
+
+ unless( has_schema( 'TestApp::User', $handle ) ) {
+ skip "No schema for '$d' driver", TESTS_PER_DRIVER - 1;
+ }
+
+ my $ret = init_schema( 'TestApp::User', $handle );
+ isa_ok($ret,'DBI::st', "Inserted the schema. got a statement handle back");
+
+ my $rec = TestApp::User->new($handle);
+ isa_ok($rec, 'Jifty::DBI::Record');
+
+ # name would be truncated
+ my($id) = $rec->create( login => "obra", name => "Jesse Vincent" );
+ ok($id, "Successfuly created ticket");
+ ok($rec->load($id), "Loaded the record");
+ is($rec->id, $id, "The record has its id");
+ is($rec->login, 'obra', "Login is not truncated" );
+ is($rec->name, 'Jesse Vinc', "But name is truncated" );
+
+ # UTF-8 string with flag set
+ use Encode ();
+ ($id) = $rec->create( login => "\x{442}\x{435}\x{441}\x{442}", name => "test" );
+ ok($id, "Successfuly created ticket");
+ ok($rec->load($id), "Loaded the record");
+ is($rec->id, $id, "The record has its id");
+ is(Encode::decode_utf8($rec->login), "\x{442}\x{435}", "Login is truncated to two UTF-8 chars" );
+ is($rec->name, 'test', "Name is not truncated" );
# this test fails on Pg because it doesn't like data that
# has bytes in unsupported encoding, we should use 'bytea'
# type for this test, but we don't have coverage for this
-# # scalar with cp1251 octets
-# $str = "\x{442}\x{435}\x{441}\x{442}\x{442}\x{435}\x{441}\x{442}";
-# $str = Encode::encode('cp1251', $str);
-# ($id) = $rec->create( login => $str, name => "test" );
-# ok($id, "Successfuly created ticket");
-# ok($rec->load($id), "Loaded the record");
-# is($rec->id, $id, "The record has its id");
-# is($rec->login, "\xf2\xe5\xf1\xf2\xf2", "Login is truncated to five octets" );
-# is($rec->name, 'test', "Name is not truncated" );
-
- # check that filter also work for set_* operations
- $rec->set_login( 'ruz' );
- $rec->set_name( 'Ruslan Zakirov' );
- is($rec->login, "ruz", "Login is not truncated" );
- is($rec->name, 'Ruslan Zak', "Name is truncated" );
+# # scalar with cp1251 octets
+# $str = "\x{442}\x{435}\x{441}\x{442}\x{442}\x{435}\x{441}\x{442}";
+# $str = Encode::encode('cp1251', $str);
+# ($id) = $rec->create( login => $str, name => "test" );
+# ok($id, "Successfuly created ticket");
+# ok($rec->load($id), "Loaded the record");
+# is($rec->id, $id, "The record has its id");
+# is($rec->login, "\xf2\xe5\xf1\xf2\xf2", "Login is truncated to five octets" );
+# is($rec->name, 'test', "Name is not truncated" );
+
+ # check that filter also work for set_* operations
+ $rec->set_login( 'ruz' );
+ $rec->set_name( 'Ruslan Zakirov' );
+ is($rec->login, "ruz", "Login is not truncated" );
+ is($rec->name, 'Ruslan Zak', "Name is truncated" );
- cleanup_schema( 'TestApp', $handle );
- disconnect_handle( $handle );
+ cleanup_schema( 'TestApp', $handle );
+ disconnect_handle( $handle );
}
}
@@ -80,9 +80,9 @@
<<EOF;
CREATE table users (
id integer primary key,
- login char(5),
- name varchar(10),
- disabled int(4) default 0
+ login char(5),
+ name varchar(10),
+ disabled int(4) default 0
)
EOF
@@ -93,9 +93,9 @@
<<EOF;
CREATE TEMPORARY table users (
id integer auto_increment primary key,
- login char(5),
- name varchar(10),
- disabled int(4) default 0
+ login char(5),
+ name varchar(10),
+ disabled int(4) default 0
)
EOF
@@ -106,9 +106,9 @@
<<EOF;
CREATE TEMPORARY table users (
id integer auto_increment primary key,
- login binary(5),
- name varbinary(10),
- disabled int(4) default 0
+ login binary(5),
+ name varbinary(10),
+ disabled int(4) default 0
)
EOF
@@ -121,9 +121,9 @@
<<EOF;
CREATE TEMPORARY table users (
id serial primary key,
- login varchar(5),
- name varchar(10),
- disabled integer default 0
+ login varchar(5),
+ name varchar(10),
+ disabled integer default 0
)
EOF
Modified: Jifty-DBI/trunk/t/06filter_utf8.t
==============================================================================
--- Jifty-DBI/trunk/t/06filter_utf8.t (original)
+++ Jifty-DBI/trunk/t/06filter_utf8.t Tue May 23 14:21:36 2006
@@ -15,75 +15,75 @@
foreach my $d ( @available_drivers ) {
SKIP: {
- unless( has_schema( 'TestApp::User', $d ) ) {
- skip "No schema for '$d' driver", TESTS_PER_DRIVER;
- }
- unless( should_test( $d ) ) {
- skip "ENV is not defined for driver '$d'", TESTS_PER_DRIVER;
- }
- diag("start testing with '$d' handle") if $ENV{TEST_VERBOSE};
-
- my $handle = get_handle( $d );
- connect_handle( $handle );
- isa_ok($handle->dbh, 'DBI::db');
-
- my $ret = init_schema( 'TestApp::User', $handle );
- isa_ok($ret,'DBI::st', "Inserted the schema. got a statement handle back");
-
- $handle->input_filters( 'Jifty::DBI::Filter::utf8' );
- is( ($handle->input_filters)[0], 'Jifty::DBI::Filter::utf8', 'Filter was added' );
-
- my $rec = TestApp::User->new($handle);
- isa_ok($rec, 'Jifty::DBI::Record');
-
- # "test" in Russian
- my $str = "\x{442}\x{435}\x{441}\x{442}";
-
- my($id) = $rec->create( signature => $str );
- ok($id, "Successfuly created ticket");
- ok($rec->load($id), "Loaded the record");
- is($rec->id, $id, "The record has its id");
- ok( Encode::is_utf8($rec->signature), "Value is UTF-8" );
- is( $rec->signature, $str, "Value is the same" );
-
- # correct data with no UTF-8 flag
- my $nstr = Encode::encode_utf8( $str );
- ($id) = $rec->create( signature => $nstr );
- ok($id, "Successfuly created ticket");
- ok($rec->load($id), "Loaded the record");
- is($rec->id, $id, "The record has its id");
- ok( Encode::is_utf8($rec->signature), "Value is UTF-8" );
- is( $rec->signature, $str, "Value is the same" );
-
- # cut string in the middle of the unicode char
- # and drop flag, leave only first char and
- # a half of the second so in result we will
- # get only one char
- $nstr = do{ use bytes; substr( $str, 0, 3 ) };
- ($id) = $rec->create( signature => $nstr );
- ok($id, "Successfuly created ticket");
- ok($rec->load($id), "Loaded the record");
- is($rec->id, $id, "The record has its id");
- ok( Encode::is_utf8($rec->signature), "Value is UTF-8" );
- is( $rec->signature, "\x{442}", "Value is correct" );
-
- # UTF-8 string with flag unset and enabeld trancation
- # truncation should cut third char, but utf8 filter should
- # replace it with \x{fffd} code point
- $rec->set_name( Encode::encode_utf8($str) );
- is($rec->name, "\x{442}\x{435}",
- "Name was truncated to two UTF-8 chars"
- );
-
- # create with undef value, no utf8 or truncate magic
- ($id) = $rec->create( signature => undef );
- ok($id, "Successfuly created ticket");
- ok($rec->load($id), "Loaded the record");
- is($rec->id, $id, "The record has its id");
- is($rec->signature, undef, "successfuly stored and fetched undef");
+ unless( has_schema( 'TestApp::User', $d ) ) {
+ skip "No schema for '$d' driver", TESTS_PER_DRIVER;
+ }
+ unless( should_test( $d ) ) {
+ skip "ENV is not defined for driver '$d'", TESTS_PER_DRIVER;
+ }
+ diag("start testing with '$d' handle") if $ENV{TEST_VERBOSE};
+
+ my $handle = get_handle( $d );
+ connect_handle( $handle );
+ isa_ok($handle->dbh, 'DBI::db');
+
+ my $ret = init_schema( 'TestApp::User', $handle );
+ isa_ok($ret,'DBI::st', "Inserted the schema. got a statement handle back");
+
+ $handle->input_filters( 'Jifty::DBI::Filter::utf8' );
+ is( ($handle->input_filters)[0], 'Jifty::DBI::Filter::utf8', 'Filter was added' );
+
+ my $rec = TestApp::User->new($handle);
+ isa_ok($rec, 'Jifty::DBI::Record');
+
+ # "test" in Russian
+ my $str = "\x{442}\x{435}\x{441}\x{442}";
+
+ my($id) = $rec->create( signature => $str );
+ ok($id, "Successfuly created ticket");
+ ok($rec->load($id), "Loaded the record");
+ is($rec->id, $id, "The record has its id");
+ ok( Encode::is_utf8($rec->signature), "Value is UTF-8" );
+ is( $rec->signature, $str, "Value is the same" );
+
+ # correct data with no UTF-8 flag
+ my $nstr = Encode::encode_utf8( $str );
+ ($id) = $rec->create( signature => $nstr );
+ ok($id, "Successfuly created ticket");
+ ok($rec->load($id), "Loaded the record");
+ is($rec->id, $id, "The record has its id");
+ ok( Encode::is_utf8($rec->signature), "Value is UTF-8" );
+ is( $rec->signature, $str, "Value is the same" );
+
+ # cut string in the middle of the unicode char
+ # and drop flag, leave only first char and
+ # a half of the second so in result we will
+ # get only one char
+ $nstr = do{ use bytes; substr( $str, 0, 3 ) };
+ ($id) = $rec->create( signature => $nstr );
+ ok($id, "Successfuly created ticket");
+ ok($rec->load($id), "Loaded the record");
+ is($rec->id, $id, "The record has its id");
+ ok( Encode::is_utf8($rec->signature), "Value is UTF-8" );
+ is( $rec->signature, "\x{442}", "Value is correct" );
+
+ # UTF-8 string with flag unset and enabeld trancation
+ # truncation should cut third char, but utf8 filter should
+ # replace it with \x{fffd} code point
+ $rec->set_name( Encode::encode_utf8($str) );
+ is($rec->name, "\x{442}\x{435}",
+ "Name was truncated to two UTF-8 chars"
+ );
+
+ # create with undef value, no utf8 or truncate magic
+ ($id) = $rec->create( signature => undef );
+ ok($id, "Successfuly created ticket");
+ ok($rec->load($id), "Loaded the record");
+ is($rec->id, $id, "The record has its id");
+ is($rec->signature, undef, "successfuly stored and fetched undef");
- cleanup_schema( 'TestApp', $handle );
- disconnect_handle( $handle );
+ cleanup_schema( 'TestApp', $handle );
+ disconnect_handle( $handle );
}
}
@@ -95,8 +95,8 @@
<<EOF;
CREATE table users (
id integer primary key,
- name varchar(5),
- signature varchar(100)
+ name varchar(5),
+ signature varchar(100)
)
EOF
@@ -107,8 +107,8 @@
<<EOF;
CREATE TEMPORARY table users (
id integer auto_increment primary key,
- name varchar(5),
- signature varchar(100)
+ name varchar(5),
+ signature varchar(100)
)
EOF
@@ -119,8 +119,8 @@
<<EOF;
CREATE TEMPORARY table users (
id serial primary key,
- name varchar(5),
- signature varchar(100)
+ name varchar(5),
+ signature varchar(100)
)
EOF
Modified: Jifty-DBI/trunk/t/10schema.t
==============================================================================
--- Jifty-DBI/trunk/t/10schema.t (original)
+++ Jifty-DBI/trunk/t/10schema.t Tue May 23 14:21:36 2006
@@ -32,7 +32,7 @@
}
unless( should_test( $d ) ) {
- skip "ENV is not defined for driver $d", TESTS_PER_DRIVER;
+ skip "ENV is not defined for driver $d", TESTS_PER_DRIVER;
}
my $handle = get_handle( $d );
Modified: Jifty-DBI/trunk/t/11schema_records.t
==============================================================================
--- Jifty-DBI/trunk/t/11schema_records.t (original)
+++ Jifty-DBI/trunk/t/11schema_records.t Tue May 23 14:21:36 2006
@@ -16,188 +16,188 @@
foreach my $d ( @available_drivers ) {
SKIP: {
- unless( has_schema( 'TestApp', $d ) ) {
- skip "No schema for '$d' driver", TESTS_PER_DRIVER;
- }
- unless( should_test( $d ) ) {
- skip "ENV is not defined for driver '$d'", TESTS_PER_DRIVER;
- }
-
- my $handle = get_handle( $d );
- connect_handle( $handle );
- isa_ok($handle->dbh, 'DBI::db', "Got handle for $d");
-
- my $ret = init_schema( 'TestApp', $handle );
- 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, "Got an id for the new employee: $e_id");
- $emp->load($e_id);
- is($emp->id, $e_id);
-
- my $phone_collection = $emp->phones;
- isa_ok($phone_collection, 'TestApp::PhoneCollection');
-
- {
- my ($val, $msg);
- eval { ($val, $msg) = $emp->set_phones(1,2,3); };
- ok(not($@), 'set does not die') or warn $@;
- ok($@ !~ /^DBD::.*::st execute failed: /,
- "no stacktrace emitted"
- );
- ok(! $val, $msg) or warn "msg: $msg";
- ok($msg =~ m/Collection column '.*' not writable/,
- '"not writable" message'
- );
- }
-
- {
- my $ph = $phone_collection->next;
- is($ph, undef, "No phones yet");
- }
-
- my $phone = TestApp::Phone->new($handle);
- isa_ok( $phone, 'TestApp::Phone');
- my $p_id = $phone->create( employee => $e_id, phone => '+7(903)264-03-51');
- is($p_id, 1, "Loaded phone $p_id");
- $phone->load( $p_id );
-
- my $obj = $phone->employee;
-
- ok($obj, "Employee #$e_id has phone #$p_id");
- isa_ok( $obj, 'TestApp::Employee');
- is($obj->id, $e_id);
- is($obj->name, 'RUZ');
-
- {
- $phone_collection->redo_search;
- my $ph = $phone_collection->next;
- isa_ok($ph, 'TestApp::Phone');
- is($ph->id, $p_id, 'found first phone');
- is($ph->phone, '+7(903)264-03-51');
- is($phone_collection->next, undef);
- }
-
- # tests for no object mapping
- my $val = $phone->phone;
- is( $val, '+7(903)264-03-51', 'Non-object things still work');
-
- my $emp2 = TestApp::Employee->new($handle);
- isa_ok($emp2, 'TestApp::Employee');
- my $e2_id = $emp2->create( name => 'Dave' );
- ok($e2_id, "Got an id for the new employee: $e2_id");
- $emp2->load($e2_id);
- is($emp2->id, $e2_id);
-
- my $phone2_collection = $emp2->phones;
- isa_ok($phone2_collection, 'TestApp::PhoneCollection');
-
- {
- my $ph = $phone2_collection->next;
- is($ph, undef, "new emp has no phones");
- }
-
- {
- $phone_collection->redo_search;
- my $ph = $phone_collection->next;
- isa_ok($ph, 'TestApp::Phone');
- is($ph->id, $p_id, 'first emp still has phone');
- is($ph->phone, '+7(903)264-03-51');
- is($phone_collection->next, undef);
- }
-
- $phone->set_employee($e2_id);
-
-
- my $emp3 = $phone->employee;
- isa_ok($emp3, 'TestApp::Employee');
- is($emp3->name, 'Dave', 'changed employees by ID');
- is($emp3->id, $emp2->id);
-
- {
- $phone_collection->redo_search;
- is($phone_collection->next, undef, "first emp lost phone");
- }
-
- {
- $phone2_collection->redo_search;
- my $ph = $phone2_collection->next;
- isa_ok($ph, 'TestApp::Phone');
- is($ph->id, $p_id, 'new emp stole the phone');
- is($ph->phone, '+7(903)264-03-51');
- is($phone2_collection->next, undef);
- }
-
-
- $phone->set_employee($emp);
-
- my $emp4 = $phone->employee;
- isa_ok($emp4, 'TestApp::Employee');
- is($emp4->name, 'RUZ', 'changed employees by obj');
- is($emp4->id, $emp->id);
-
- {
- $phone2_collection->redo_search;
- is($phone2_collection->next, undef, "second emp lost phone");
- }
-
- {
- $phone_collection->redo_search;
- my $ph = $phone_collection->next;
- isa_ok($ph, 'TestApp::Phone');
- is($ph->id, $p_id, 'first emp stole the phone');
- is($ph->phone, '+7(903)264-03-51');
- is($phone_collection->next, undef);
- }
-
- my $phone2 = TestApp::Phone->new($handle);
- isa_ok( $phone2, 'TestApp::Phone');
- my $p2_id = $phone2->create( employee => $e_id, phone => '123456');
- ok($p2_id, "Loaded phone $p2_id");
- $phone2->load( $p2_id );
-
- {
- $phone_collection->redo_search;
- my $ph = $phone_collection->next;
- isa_ok($ph, 'TestApp::Phone');
- is($ph->id, $p_id, 'still has this phone');
- is($ph->phone, '+7(903)264-03-51');
- $ph = $phone_collection->next;
- isa_ok($ph, 'TestApp::Phone');
- is($ph->id, $p2_id, 'now has that phone');
- is($ph->phone, '123456');
- is($phone_collection->next, undef);
- }
-
- # Test Create with obj as argument
- my $phone3 = TestApp::Phone->new($handle);
- isa_ok( $phone3, 'TestApp::Phone');
- my $p3_id = $phone3->create( employee => $emp, phone => '7890');
- ok($p3_id, "Loaded phone $p3_id");
- $phone3->load( $p3_id );
-
- {
- $phone_collection->redo_search;
- my $ph = $phone_collection->next;
- isa_ok($ph, 'TestApp::Phone');
- is($ph->id, $p_id, 'still has this phone');
- is($ph->phone, '+7(903)264-03-51');
- $ph = $phone_collection->next;
- isa_ok($ph, 'TestApp::Phone');
- is($ph->id, $p2_id, 'still has that phone');
- is($ph->phone, '123456');
- $ph = $phone_collection->next;
- isa_ok($ph, 'TestApp::Phone');
- is($ph->id, $p3_id, 'even has this other phone');
- is($ph->phone, '7890');
- is($phone_collection->next, undef);
- }
-
-
+ unless( has_schema( 'TestApp', $d ) ) {
+ skip "No schema for '$d' driver", TESTS_PER_DRIVER;
+ }
+ unless( should_test( $d ) ) {
+ skip "ENV is not defined for driver '$d'", TESTS_PER_DRIVER;
+ }
+
+ my $handle = get_handle( $d );
+ connect_handle( $handle );
+ isa_ok($handle->dbh, 'DBI::db', "Got handle for $d");
+
+ my $ret = init_schema( 'TestApp', $handle );
+ 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, "Got an id for the new employee: $e_id");
+ $emp->load($e_id);
+ is($emp->id, $e_id);
+
+ my $phone_collection = $emp->phones;
+ isa_ok($phone_collection, 'TestApp::PhoneCollection');
+
+ {
+ my ($val, $msg);
+ eval { ($val, $msg) = $emp->set_phones(1,2,3); };
+ ok(not($@), 'set does not die') or warn $@;
+ ok($@ !~ /^DBD::.*::st execute failed: /,
+ "no stacktrace emitted"
+ );
+ ok(! $val, $msg) or warn "msg: $msg";
+ ok($msg =~ m/Collection column '.*' not writable/,
+ '"not writable" message'
+ );
+ }
+
+ {
+ my $ph = $phone_collection->next;
+ is($ph, undef, "No phones yet");
+ }
+
+ my $phone = TestApp::Phone->new($handle);
+ isa_ok( $phone, 'TestApp::Phone');
+ my $p_id = $phone->create( employee => $e_id, phone => '+7(903)264-03-51');
+ is($p_id, 1, "Loaded phone $p_id");
+ $phone->load( $p_id );
+
+ my $obj = $phone->employee;
+
+ ok($obj, "Employee #$e_id has phone #$p_id");
+ isa_ok( $obj, 'TestApp::Employee');
+ is($obj->id, $e_id);
+ is($obj->name, 'RUZ');
+
+ {
+ $phone_collection->redo_search;
+ my $ph = $phone_collection->next;
+ isa_ok($ph, 'TestApp::Phone');
+ is($ph->id, $p_id, 'found first phone');
+ is($ph->phone, '+7(903)264-03-51');
+ is($phone_collection->next, undef);
+ }
+
+ # tests for no object mapping
+ my $val = $phone->phone;
+ is( $val, '+7(903)264-03-51', 'Non-object things still work');
+
+ my $emp2 = TestApp::Employee->new($handle);
+ isa_ok($emp2, 'TestApp::Employee');
+ my $e2_id = $emp2->create( name => 'Dave' );
+ ok($e2_id, "Got an id for the new employee: $e2_id");
+ $emp2->load($e2_id);
+ is($emp2->id, $e2_id);
+
+ my $phone2_collection = $emp2->phones;
+ isa_ok($phone2_collection, 'TestApp::PhoneCollection');
+
+ {
+ my $ph = $phone2_collection->next;
+ is($ph, undef, "new emp has no phones");
+ }
+
+ {
+ $phone_collection->redo_search;
+ my $ph = $phone_collection->next;
+ isa_ok($ph, 'TestApp::Phone');
+ is($ph->id, $p_id, 'first emp still has phone');
+ is($ph->phone, '+7(903)264-03-51');
+ is($phone_collection->next, undef);
+ }
+
+ $phone->set_employee($e2_id);
+
+
+ my $emp3 = $phone->employee;
+ isa_ok($emp3, 'TestApp::Employee');
+ is($emp3->name, 'Dave', 'changed employees by ID');
+ is($emp3->id, $emp2->id);
+
+ {
+ $phone_collection->redo_search;
+ is($phone_collection->next, undef, "first emp lost phone");
+ }
+
+ {
+ $phone2_collection->redo_search;
+ my $ph = $phone2_collection->next;
+ isa_ok($ph, 'TestApp::Phone');
+ is($ph->id, $p_id, 'new emp stole the phone');
+ is($ph->phone, '+7(903)264-03-51');
+ is($phone2_collection->next, undef);
+ }
+
+
+ $phone->set_employee($emp);
+
+ my $emp4 = $phone->employee;
+ isa_ok($emp4, 'TestApp::Employee');
+ is($emp4->name, 'RUZ', 'changed employees by obj');
+ is($emp4->id, $emp->id);
+
+ {
+ $phone2_collection->redo_search;
+ is($phone2_collection->next, undef, "second emp lost phone");
+ }
+
+ {
+ $phone_collection->redo_search;
+ my $ph = $phone_collection->next;
+ isa_ok($ph, 'TestApp::Phone');
+ is($ph->id, $p_id, 'first emp stole the phone');
+ is($ph->phone, '+7(903)264-03-51');
+ is($phone_collection->next, undef);
+ }
+
+ my $phone2 = TestApp::Phone->new($handle);
+ isa_ok( $phone2, 'TestApp::Phone');
+ my $p2_id = $phone2->create( employee => $e_id, phone => '123456');
+ ok($p2_id, "Loaded phone $p2_id");
+ $phone2->load( $p2_id );
+
+ {
+ $phone_collection->redo_search;
+ my $ph = $phone_collection->next;
+ isa_ok($ph, 'TestApp::Phone');
+ is($ph->id, $p_id, 'still has this phone');
+ is($ph->phone, '+7(903)264-03-51');
+ $ph = $phone_collection->next;
+ isa_ok($ph, 'TestApp::Phone');
+ is($ph->id, $p2_id, 'now has that phone');
+ is($ph->phone, '123456');
+ is($phone_collection->next, undef);
+ }
+
+ # Test Create with obj as argument
+ my $phone3 = TestApp::Phone->new($handle);
+ isa_ok( $phone3, 'TestApp::Phone');
+ my $p3_id = $phone3->create( employee => $emp, phone => '7890');
+ ok($p3_id, "Loaded phone $p3_id");
+ $phone3->load( $p3_id );
+
+ {
+ $phone_collection->redo_search;
+ my $ph = $phone_collection->next;
+ isa_ok($ph, 'TestApp::Phone');
+ is($ph->id, $p_id, 'still has this phone');
+ is($ph->phone, '+7(903)264-03-51');
+ $ph = $phone_collection->next;
+ isa_ok($ph, 'TestApp::Phone');
+ is($ph->id, $p2_id, 'still has that phone');
+ is($ph->phone, '123456');
+ $ph = $phone_collection->next;
+ isa_ok($ph, 'TestApp::Phone');
+ is($ph->id, $p3_id, 'even has this other phone');
+ is($ph->phone, '7890');
+ is($phone_collection->next, undef);
+ }
+
+
- cleanup_schema( 'TestApp', $handle );
- disconnect_handle( $handle );
+ cleanup_schema( 'TestApp', $handle );
+ disconnect_handle( $handle );
}} # SKIP, foreach blocks
1;
@@ -208,14 +208,14 @@
[
q{
CREATE table employees (
- id integer primary key,
- name varchar(36)
+ id integer primary key,
+ name varchar(36)
)
}, q{
CREATE table phones (
- id integer primary key,
- employee integer NOT NULL,
- phone varchar(18)
+ id integer primary key,
+ employee integer NOT NULL,
+ phone varchar(18)
) }
]
}
@@ -223,14 +223,14 @@
sub schema_mysql {
[ q{
CREATE TEMPORARY table employees (
- id integer AUTO_INCREMENT primary key,
- name varchar(36)
+ id integer AUTO_INCREMENT primary key,
+ name varchar(36)
)
}, q{
CREATE TEMPORARY table phones (
- id integer AUTO_INCREMENT primary key,
- employee integer NOT NULL,
- phone varchar(18)
+ id integer AUTO_INCREMENT primary key,
+ employee integer NOT NULL,
+ phone varchar(18)
)
} ]
}
@@ -238,14 +238,14 @@
sub schema_pg {
[ q{
CREATE TEMPORARY table employees (
- id serial PRIMARY KEY,
- name varchar
+ id serial PRIMARY KEY,
+ name varchar
)
}, q{
CREATE TEMPORARY table phones (
- id serial PRIMARY KEY,
- employee integer references employees(id),
- phone varchar
+ id serial PRIMARY KEY,
+ employee integer references employees(id),
+ phone varchar
)
} ]
}
Modified: Jifty-DBI/trunk/t/utils.pl
==============================================================================
--- Jifty-DBI/trunk/t/utils.pl (original)
+++ Jifty-DBI/trunk/t/utils.pl Tue May 23 14:21:36 2006
@@ -12,14 +12,14 @@
=cut
our @supported_drivers = qw(
- SQLite
- Informix
- mysql
- mysqlPP
- ODBC
- Oracle
- Pg
- Sybase
+ SQLite
+ Informix
+ mysql
+ mysqlPP
+ ODBC
+ Oracle
+ Pg
+ Sybase
);
=head2 @available_drivers
@@ -42,13 +42,13 @@
sub get_handle
{
- my $type = shift;
- my $class = 'Jifty::DBI::Handle::'. $type;
- eval "require $class";
- die $@ if $@;
- my $handle;
- $handle = $class->new( @_ );
- return $handle;
+ my $type = shift;
+ my $class = 'Jifty::DBI::Handle::'. $type;
+ eval "require $class";
+ die $@ if $@;
+ my $handle;
+ $handle = $class->new( @_ );
+ return $handle;
}
=head2 handle_to_driver
@@ -59,9 +59,9 @@
sub handle_to_driver
{
- my $driver = ref($_[0]);
- $driver =~ s/^.*:://;
- return $driver;
+ my $driver = ref($_[0]);
+ $driver =~ s/^.*:://;
+ return $driver;
}
=head2 connect_handle
@@ -72,9 +72,9 @@
sub connect_handle
{
- my $call = "connect_". lc handle_to_driver( $_[0] );
- return unless defined &$call;
- goto &$call;
+ my $call = "connect_". lc handle_to_driver( $_[0] );
+ return unless defined &$call;
+ goto &$call;
}
=head2 connect_handle_with_driver($handle, $driver)
@@ -87,41 +87,41 @@
sub connect_handle_with_driver
{
- my $call = "connect_". lc $_[1];
- return unless defined &$call;
- @_ = $_[0];
- goto &$call;
+ 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.$$")
- );
+ 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{'JDBI_TEST_MYSQL'},
- user => $ENV{'JDBI_TEST_MYSQL_USER'} || 'root',
- password => $ENV{'JDBI_TEST_MYSQL_PASS'} || '',
- );
+ my $handle = shift;
+ return $handle->connect(
+ driver => 'mysql',
+ database => $ENV{'JDBI_TEST_MYSQL'},
+ user => $ENV{'JDBI_TEST_MYSQL_USER'} || 'root',
+ password => $ENV{'JDBI_TEST_MYSQL_PASS'} || '',
+ );
}
sub connect_pg
{
- my $handle = shift;
- return $handle->connect(
- driver => 'Pg',
- database => $ENV{'JDBI_TEST_PG'},
- user => $ENV{'JDBI_TEST_PG_USER'} || 'postgres',
- password => $ENV{'JDBI_TEST_PG_PASS'} || '',
- );
+ my $handle = shift;
+ return $handle->connect(
+ driver => 'Pg',
+ database => $ENV{'JDBI_TEST_PG'},
+ user => $ENV{'JDBI_TEST_PG_USER'} || 'postgres',
+ password => $ENV{'JDBI_TEST_PG_PASS'} || '',
+ );
}
=head2 disconnect_handle
@@ -132,9 +132,9 @@
sub disconnect_handle
{
- my $call = "disconnect_". lc handle_to_driver( $_[0] );
- return unless defined &$call;
- goto &$call;
+ my $call = "disconnect_". lc handle_to_driver( $_[0] );
+ return unless defined &$call;
+ goto &$call;
}
=head2 disconnect_handle_with_driver($handle, $driver)
@@ -145,33 +145,33 @@
sub disconnect_handle_with_driver
{
- my $call = "disconnect_". lc $_[1];
- return unless defined &$call;
- @_ = $_[0];
- goto &$call;
+ my $call = "disconnect_". lc $_[1];
+ return unless defined &$call;
+ @_ = $_[0];
+ goto &$call;
}
sub disconnect_sqlite
{
- my $handle = shift;
- $handle->disconnect;
- unlink File::Spec->catfile(File::Spec->tmpdir(), "sb-test.$$");
+ my $handle = shift;
+ $handle->disconnect;
+ unlink File::Spec->catfile(File::Spec->tmpdir(), "sb-test.$$");
}
sub disconnect_mysql
{
- my $handle = shift;
- $handle->disconnect;
+ my $handle = shift;
+ $handle->disconnect;
- # XXX: is there something we should do here?
+ # XXX: is there something we should do here?
}
sub disconnect_pg
{
- my $handle = shift;
- $handle->disconnect;
+ my $handle = shift;
+ $handle->disconnect;
- # XXX: is there something we should do here?
+ # XXX: is there something we should do here?
}
=head2 should_test $driver
@@ -184,10 +184,10 @@
sub should_test
{
- my $driver = shift;
- return 1 if lc $driver eq 'sqlite';
- my $env = 'JDBI_TEST_'. uc $driver;
- return $ENV{$env};
+ my $driver = shift;
+ return 1 if lc $driver eq 'sqlite';
+ my $env = 'JDBI_TEST_'. uc $driver;
+ return $ENV{$env};
}
=head2 has_schema $class { $driver | $handle }
@@ -205,25 +205,25 @@
sub has_schema
{
- my ($class, $driver) = @_;
- unless( UNIVERSAL::isa( $driver, 'Jifty::DBI::Handle' ) ) {
- my $method = 'schema_'. lc $driver;
- $method = '' unless UNIVERSAL::can( $class, $method );
- return $method;
- } else {
- my $ver = $driver->database_version;
- return has_schema( $class, handle_to_driver( $driver ) ) unless $ver;
-
- my $method = 'schema_'. lc handle_to_driver( $driver );
- $ver =~ s/-.*$//;
- my @nums = grep $_, map { int($_) } split /\./, $ver;
- while( @nums ) {
- my $m = $method ."_". join '_', @nums;
- return $m if( UNIVERSAL::can( $class, $m ) );
- pop @nums;
- }
- return has_schema( $class, handle_to_driver( $driver ) );
- }
+ my ($class, $driver) = @_;
+ unless( UNIVERSAL::isa( $driver, 'Jifty::DBI::Handle' ) ) {
+ my $method = 'schema_'. lc $driver;
+ $method = '' unless UNIVERSAL::can( $class, $method );
+ return $method;
+ } else {
+ my $ver = $driver->database_version;
+ return has_schema( $class, handle_to_driver( $driver ) ) unless $ver;
+
+ my $method = 'schema_'. lc handle_to_driver( $driver );
+ $ver =~ s/-.*$//;
+ my @nums = grep $_, map { int($_) } split /\./, $ver;
+ while( @nums ) {
+ my $m = $method ."_". join '_', @nums;
+ return $m if( UNIVERSAL::can( $class, $m ) );
+ pop @nums;
+ }
+ return has_schema( $class, handle_to_driver( $driver ) );
+ }
}
=head2 init_schema
@@ -237,17 +237,17 @@
sub init_schema
{
- my ($class, $handle) = @_;
- my $call = has_schema( $class, $handle );
- diag( "using '$class\:\:$call' schema for ". handle_to_driver( $handle ) ) if $ENV{TEST_VERBOSE};
- my $schema = $class->$call();
- $schema = ref( $schema )? $schema : [$schema];
- my $ret;
- foreach my $query( @$schema ) {
- $ret = $handle->simple_query( $query );
- return $ret unless UNIVERSAL::isa( $ret, 'DBI::st' );
- }
- return $ret;
+ my ($class, $handle) = @_;
+ my $call = has_schema( $class, $handle );
+ diag( "using '$class\:\:$call' schema for ". handle_to_driver( $handle ) ) if $ENV{TEST_VERBOSE};
+ my $schema = $class->$call();
+ $schema = ref( $schema )? $schema : [$schema];
+ my $ret;
+ foreach my $query( @$schema ) {
+ $ret = $handle->simple_query( $query );
+ return $ret unless UNIVERSAL::isa( $ret, 'DBI::st' );
+ }
+ return $ret;
}
=head2 cleanup_schema
@@ -260,14 +260,14 @@
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->simple_query( $query ) };
- }
+ 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->simple_query( $query ) };
+ }
}
=head2 init_data
@@ -276,21 +276,21 @@
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;
+ 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 Jifty-commit
mailing list