[Jifty-commit] r1237 - in Jifty-DBI/trunk: . lib/Jifty lib/Jifty/DBI

jifty-commit at lists.jifty.org jifty-commit at lists.jifty.org
Fri Jun 9 18:29:00 EDT 2006


Author: seanmil
Date: Fri Jun  9 18:28:55 2006
New Revision: 1237

Modified:
   Jifty-DBI/trunk/   (props changed)
   Jifty-DBI/trunk/lib/Jifty/DBI.pm
   Jifty-DBI/trunk/lib/Jifty/DBI/Collection.pm
   Jifty-DBI/trunk/lib/Jifty/DBI/Record.pm
   Jifty-DBI/trunk/t/01records.t
   Jifty-DBI/trunk/t/01searches.t
   Jifty-DBI/trunk/t/02-column_constraints.t
   Jifty-DBI/trunk/t/02records_object.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/11schema_records.t
   Jifty-DBI/trunk/t/utils.pl

Log:
 r439 at pc102:  sean | 2006-06-09 18:28:49 -0400
 * Make Jifty::DBI::Record::_init() expect a hash like Jifty::Record does
 * Fixes 'is_distinct' failure when used in Jifty
 


Modified: Jifty-DBI/trunk/lib/Jifty/DBI.pm
==============================================================================
--- Jifty-DBI/trunk/lib/Jifty/DBI.pm	(original)
+++ Jifty-DBI/trunk/lib/Jifty/DBI.pm	Fri Jun  9 18:28:55 2006
@@ -127,7 +127,7 @@
 it to be more clear to define it.
 
  
- my $s = Simple->new($handle);
+ my $s = Simple->new( handle => $handle );
  
  $s->load_by_cols(id=>1); 
 
@@ -187,7 +187,7 @@
 exactly map to database columns. 
 
  ## Get a new record object.
- $s1 = Simple->new($handle);
+ $s1 = Simple->new( handle => $handle );
  my ($id, $status_msg) = $s1->create(id  => 4,
                    foo => 'Foooooo', 
                    bar => 'Barrrrr');
@@ -195,7 +195,7 @@
 Poof! A new row in the database has been created!  Now lets delete the 
 object! 
 
- my $s2 = Simple->new($handle);
+ my $s2 = Simple->new( handle => $handle );
  $s2->load_by_cols(id=>4);
  $s2->delete();
 

Modified: Jifty-DBI/trunk/lib/Jifty/DBI/Collection.pm
==============================================================================
--- Jifty-DBI/trunk/lib/Jifty/DBI/Collection.pm	(original)
+++ Jifty-DBI/trunk/lib/Jifty/DBI/Collection.pm	Fri Jun  9 18:28:55 2006
@@ -566,7 +566,7 @@
         unless $class;
 
     $class->require();
-    return $class->new( $self->_handle );
+    return $class->new( handle => $self->_handle );
 }
 
 =head2 record_class

Modified: Jifty-DBI/trunk/lib/Jifty/DBI/Record.pm
==============================================================================
--- Jifty-DBI/trunk/lib/Jifty/DBI/Record.pm	(original)
+++ Jifty-DBI/trunk/lib/Jifty/DBI/Record.pm	Fri Jun  9 18:28:55 2006
@@ -58,8 +58,10 @@
 # Not yet documented here.  Should almost certainly be overloaded.
 sub _init {
     my $self   = shift;
-    my $handle = shift;
-    $self->_handle($handle);
+    my %args   = (@_);
+    if ( $args{'handle'} ) {
+        $self->_handle( $args{'handle'} );
+    }
 }
 
 =head2 id
@@ -278,7 +280,7 @@
 
     # XXX TODO FIXME we need to figure out the right way to call new here
     # perhaps the handle should have an initiializer for records/collections
-    my $object = $classname->new( $self->_handle );
+    my $object = $classname->new( handle => $self->_handle );
     $object->load_by_cols( $remote_column => $value );
     return $object;
 }
@@ -1110,7 +1112,7 @@
     my $column = shift;
     my $value = shift;
 
-    my $record = $self->new( $self->_handle );
+    my $record = $self->new( handle => $self->_handle );
     $record->load_by_cols ( $column => $value );
 
     my $ret = Class::ReturnValue->new();

Modified: Jifty-DBI/trunk/t/01records.t
==============================================================================
--- Jifty-DBI/trunk/t/01records.t	(original)
+++ Jifty-DBI/trunk/t/01records.t	Fri Jun  9 18:28:55 2006
@@ -29,7 +29,7 @@
         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);
+        my $rec = TestApp::Address->new( handle => $handle );
         isa_ok($rec, 'Jifty::DBI::Record');
 
 
@@ -90,7 +90,7 @@
         $rec->delete;
 
 # make sure we do truncation on create
-        my $newrec = TestApp::Address->new($handle);
+        my $newrec = TestApp::Address->new( handle => $handle );
         my $newid = $newrec->create( name => '1234567890123456789012345678901234567890',
                                      employee_id => '1234567890' );
 
@@ -101,26 +101,26 @@
         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);
+        $newrec = TestApp::Address->new( handle => $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);
+        $newrec = TestApp::Address->new( handle => $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);
+        $newrec = TestApp::Address->new( handle => $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);
+        $newrec = TestApp::Address->new( handle => $handle );
         {
                 local $SIG{__WARN__} = sub{return};
                 ($val, $msg) = $newrec->_load_from_sql('SELECT ...');
@@ -129,53 +129,53 @@
         is($msg, "Couldn't execute query", "reason is bad SQL");
 
 # test load_* methods
-        $newrec = TestApp::Address->new($handle);
+        $newrec = TestApp::Address->new( handle => $handle );
         $newrec->load();
         is( $newrec->id, undef, "can't load record with undef id");
 
-        $newrec = TestApp::Address->new($handle);
+        $newrec = TestApp::Address->new( handle => $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 = TestApp::Address->new( handle => $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);
+        $newrec = TestApp::Address->new( handle => $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);
+        $newrec = TestApp::Address->new( handle => $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);
+        $newrec = TestApp::Address->new( handle => $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);
+        $rec = TestApp::Address->new( handle => $handle );
         $id = $rec->create( name => 'Chmrr' );
         ok( $id, "new record");
-        $rec = TestApp::Address->new($handle);
+        $rec = TestApp::Address->new( handle => $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);
+        $rec = TestApp::Address->new( handle => $handle );
         $id = $rec->create( name => 'Obra', phone => undef );
         ok( $id, "new record");
-        $rec = TestApp::Address->new($handle);
+        $rec = TestApp::Address->new( handle => $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 = TestApp::Address->new( handle => $handle );
         $rec->load( $id );
         $val = $rec->set_name( 'Obra' );
         isa_ok( $val, 'Class::ReturnValue', "couldn't set same value, error returned");
@@ -193,10 +193,10 @@
         is( $rec->name, undef, "new value is undef, NULL in DB");
 
 # deletes
-        $newrec = TestApp::Address->new($handle);
+        $newrec = TestApp::Address->new( handle => $handle );
         $newrec->load( $newid );
         is( $newrec->delete, 1, 'successfuly delete record');
-        $newrec = TestApp::Address->new($handle);
+        $newrec = TestApp::Address->new( handle => $handle );
         $newrec->load( $newid );
         is( $newrec->id, undef, "record doesn't exist any more");
 

Modified: Jifty-DBI/trunk/t/01searches.t
==============================================================================
--- Jifty-DBI/trunk/t/01searches.t	(original)
+++ Jifty-DBI/trunk/t/01searches.t	Fri Jun  9 18:28:55 2006
@@ -32,7 +32,7 @@
         my $count_all = init_data( 'TestApp::User', $handle );
         ok( $count_all,  "init users data" );
 
-        my $users_obj = TestApp::UserCollection->new( $handle );
+        my $users_obj = TestApp::UserCollection->new( handle => $handle );
         isa_ok( $users_obj, 'Jifty::DBI::Collection' );
         is( $users_obj->_handle, $handle, "same handle as we used in constructor");
 
@@ -71,7 +71,7 @@
 
 # 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 );
+        my $clean_obj = $users_obj->new( handle => $handle );
         isa_ok( $clean_obj, 'Jifty::DBI::Collection' );
 
 # basic limits
@@ -220,9 +220,8 @@
 
 sub _init {
     my $self = shift;
-    my $handle = shift;
     $self->table('users');
-    $self->_handle($handle);
+    $self->SUPER::_init(@_);
 }
 
 sub init_data {
@@ -256,7 +255,7 @@
 
 sub _init {
     my $self = shift;
-    $self->SUPER::_init( handle => shift );
+    $self->SUPER::_init(@_);
     $self->table('users');
 }
 

Modified: Jifty-DBI/trunk/t/02-column_constraints.t
==============================================================================
--- Jifty-DBI/trunk/t/02-column_constraints.t	(original)
+++ Jifty-DBI/trunk/t/02-column_constraints.t	Fri Jun  9 18:28:55 2006
@@ -30,7 +30,7 @@
         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 $emp = TestApp::Employee->new( handle => $handle );
         my $e_id = $emp->create( name => 'RUZ', employee_num => '123' );
         ok($e_id, "Got an id for the new employee");
 
@@ -43,7 +43,7 @@
         ok($e_id, "Was able to create a second record successfully");
         my $e_id2 = $emp->create( name => 'Bar', employee_num => '123' );
         ok(!$e_id2, "is_distinct prevents us from creating another record");
-        my $obj = TestApp::Employee->new($handle);
+        my $obj = TestApp::Employee->new( handle => $handle );
         $obj->load( $e_id );
         ok(!$obj->set_employee_num('123'), "is_distinct prevents us from modifying a record to a duplicate value");
 

Modified: Jifty-DBI/trunk/t/02records_object.t
==============================================================================
--- Jifty-DBI/trunk/t/02records_object.t	(original)
+++ Jifty-DBI/trunk/t/02records_object.t	Fri Jun  9 18:28:55 2006
@@ -30,17 +30,17 @@
         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 $emp = TestApp::Employee->new( handle => $handle );
         my $e_id = $emp->create( Name => 'RUZ' );
         ok($e_id, "Got an id for the new emplyee");
-        my $phone = TestApp::Phone->new($handle);
+        my $phone = TestApp::Phone->new( handle => $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);
+        my $obj = $phone->employee( handle => $handle );
         ok($obj, "Employee #$e_id has phone #$p_id");
         isa_ok( $obj, 'TestApp::Employee');
         is($obj->id, $e_id);

Modified: Jifty-DBI/trunk/t/06filter_datetime.t
==============================================================================
--- Jifty-DBI/trunk/t/06filter_datetime.t	(original)
+++ Jifty-DBI/trunk/t/06filter_datetime.t	Fri Jun  9 18:28:55 2006
@@ -30,7 +30,7 @@
         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);
+        my $rec = TestApp::User->new( handle => $handle );
         isa_ok($rec, 'Jifty::DBI::Record');
 
         my $now = time;

Modified: Jifty-DBI/trunk/t/06filter_truncate.t
==============================================================================
--- Jifty-DBI/trunk/t/06filter_truncate.t	(original)
+++ Jifty-DBI/trunk/t/06filter_truncate.t	Fri Jun  9 18:28:55 2006
@@ -28,7 +28,7 @@
         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);
+        my $rec = TestApp::User->new( handle => $handle );
         isa_ok($rec, 'Jifty::DBI::Record');
 
         # name would be truncated

Modified: Jifty-DBI/trunk/t/06filter_utf8.t
==============================================================================
--- Jifty-DBI/trunk/t/06filter_utf8.t	(original)
+++ Jifty-DBI/trunk/t/06filter_utf8.t	Fri Jun  9 18:28:55 2006
@@ -33,7 +33,7 @@
         $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);
+        my $rec = TestApp::User->new( handle => $handle );
         isa_ok($rec, 'Jifty::DBI::Record');
 
         # "test" in Russian

Modified: Jifty-DBI/trunk/t/11schema_records.t
==============================================================================
--- Jifty-DBI/trunk/t/11schema_records.t	(original)
+++ Jifty-DBI/trunk/t/11schema_records.t	Fri Jun  9 18:28:55 2006
@@ -30,7 +30,7 @@
         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 $emp = TestApp::Employee->new( handle => $handle );
         my $e_id = $emp->create( Name => 'RUZ' );
         ok($e_id, "Got an id for the new employee: $e_id");
         $emp->load($e_id);
@@ -57,7 +57,7 @@
             is($ph, undef, "No phones yet");
         }
         
-        my $phone = TestApp::Phone->new($handle);
+        my $phone = TestApp::Phone->new( handle => $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");
@@ -83,7 +83,7 @@
         my $val = $phone->phone;
         is( $val, '+7(903)264-03-51', 'Non-object things still work');
         
-        my $emp2 = TestApp::Employee->new($handle);
+        my $emp2 = TestApp::Employee->new( handle => $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");
@@ -151,7 +151,7 @@
             is($phone_collection->next, undef);
         }
         
-        my $phone2 = TestApp::Phone->new($handle);
+        my $phone2 = TestApp::Phone->new( handle => $handle );
         isa_ok( $phone2, 'TestApp::Phone');
         my $p2_id = $phone2->create( employee => $e_id, phone => '123456');
         ok($p2_id, "Loaded phone $p2_id");
@@ -171,7 +171,7 @@
         }
         
         # Test Create with obj as argument
-        my $phone3 = TestApp::Phone->new($handle);
+        my $phone3 = TestApp::Phone->new( handle => $handle );
         isa_ok( $phone3, 'TestApp::Phone');
         my $p3_id = $phone3->create( employee => $emp, phone => '7890');
         ok($p3_id, "Loaded phone $p3_id");

Modified: Jifty-DBI/trunk/t/utils.pl
==============================================================================
--- Jifty-DBI/trunk/t/utils.pl	(original)
+++ Jifty-DBI/trunk/t/utils.pl	Fri Jun  9 18:28:55 2006
@@ -285,7 +285,7 @@
                 for( my $i = 0; $i < @columns; $i++ ) {
                         $args{ $columns[$i] } = $values->[$i];
                 }
-                my $rec = $class->new( $handle );
+                my $rec = $class->new( handle => $handle );
                 my $id = $rec->create( %args );
                 die "Couldn't create record" unless $id;
                 $count++;


More information about the Jifty-commit mailing list