r69813 - in /branches/upstream/libjifty-dbi-perl/current: Changes META.yml SIGNATURE lib/Jifty/DBI.pm lib/Jifty/DBI/Collection.pm lib/Jifty/DBI/Record.pm t/05raw_value.t t/10schema.t t/13collection.t t/18triggers.t t/19reference.t

jawnsy-guest at users.alioth.debian.org jawnsy-guest at users.alioth.debian.org
Sun Feb 27 02:26:18 UTC 2011


Author: jawnsy-guest
Date: Sun Feb 27 02:26:13 2011
New Revision: 69813

URL: http://svn.debian.org/wsvn/pkg-perl/?sc=1&rev=69813
Log:
[svn-upgrade] new version libjifty-dbi-perl (0.66)

Modified:
    branches/upstream/libjifty-dbi-perl/current/Changes
    branches/upstream/libjifty-dbi-perl/current/META.yml
    branches/upstream/libjifty-dbi-perl/current/SIGNATURE
    branches/upstream/libjifty-dbi-perl/current/lib/Jifty/DBI.pm
    branches/upstream/libjifty-dbi-perl/current/lib/Jifty/DBI/Collection.pm
    branches/upstream/libjifty-dbi-perl/current/lib/Jifty/DBI/Record.pm
    branches/upstream/libjifty-dbi-perl/current/t/05raw_value.t
    branches/upstream/libjifty-dbi-perl/current/t/10schema.t
    branches/upstream/libjifty-dbi-perl/current/t/13collection.t
    branches/upstream/libjifty-dbi-perl/current/t/18triggers.t
    branches/upstream/libjifty-dbi-perl/current/t/19reference.t

Modified: branches/upstream/libjifty-dbi-perl/current/Changes
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libjifty-dbi-perl/current/Changes?rev=69813&op=diff
==============================================================================
--- branches/upstream/libjifty-dbi-perl/current/Changes (original)
+++ branches/upstream/libjifty-dbi-perl/current/Changes Sun Feb 27 02:26:13 2011
@@ -1,4 +1,19 @@
 Revision history for Perl extension Jifty::DBI.
+
+0.66 2011-02-14
+- Features:
+    * Provide a sane way to wrap a function around an aliased column in order_by
+    * Pass old_value to triggers on column update
+
+- Fixes:
+    * Respect the 'by' attribute for refers_to columns in create and set
+    * Use the right FK when using a record object in load_by_cols or
+      limit [rt.cpan.org #64779]
+    * Don't encode fields when attempting to limit with IS
+    * Fix since/till by refactoring columns to use an updated all_columns
+
+- Installation:
+    * Only run these URI filter tests if we have URI [rt.cpan.org #65047]
 
 0.64 Wed Dec  8 15:21:17 EST 2010
 - Installation:

Modified: branches/upstream/libjifty-dbi-perl/current/META.yml
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libjifty-dbi-perl/current/META.yml?rev=69813&op=diff
==============================================================================
--- branches/upstream/libjifty-dbi-perl/current/META.yml (original)
+++ branches/upstream/libjifty-dbi-perl/current/META.yml Sun Feb 27 02:26:13 2011
@@ -47,4 +47,4 @@
   version: 0
 resources:
   license: http://dev.perl.org/licenses/
-version: 0.64
+version: 0.66

Modified: branches/upstream/libjifty-dbi-perl/current/SIGNATURE
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libjifty-dbi-perl/current/SIGNATURE?rev=69813&op=diff
==============================================================================
--- branches/upstream/libjifty-dbi-perl/current/SIGNATURE (original)
+++ branches/upstream/libjifty-dbi-perl/current/SIGNATURE Sun Feb 27 02:26:13 2011
@@ -15,9 +15,9 @@
 Hash: SHA1
 
 SHA1 418a58763132c9a476627cbdce5ff01395ce84d4 .gitignore
-SHA1 e1c395f642330252cb46d4993d57ffea7880033d Changes
+SHA1 37266036389c91467c5bccd288f584a2b2415617 Changes
 SHA1 18b75d45e40e1ff66f673bab9fdaf37edf93794e MANIFEST
-SHA1 8f362327ea5bd6c5d365d2cb3dcf4eb226506ad6 META.yml
+SHA1 e5d135ba5b8445d15c5f6e0998ac08a10504936f META.yml
 SHA1 48bd6ca8a37ec79b7cae91028d7e9489ad33a03b Makefile.PL
 SHA1 e29d7b270f78a5a406921571b08290c46f2a42f6 README
 SHA1 82d6ac3f6def48558d09f8b6e3b53ed4194d8c81 ROADMAP
@@ -41,8 +41,8 @@
 SHA1 026cc0551a0ad399d195e395b46bdf842e115192 inc/Module/Install/Metadata.pm
 SHA1 5457015ea5a50e93465bf2dafa29feebd547f85b inc/Module/Install/Win32.pm
 SHA1 051e7fa8063908befa3440508d0584a2497b97db inc/Module/Install/WriteAll.pm
-SHA1 906c5411b030874ae888ead4c17922fd175ad490 lib/Jifty/DBI.pm
-SHA1 70bccd7b0081632f79964271b08a228a26de0396 lib/Jifty/DBI/Collection.pm
+SHA1 8963f051b47634cc0d5b8baf90804a2d6c59efe7 lib/Jifty/DBI.pm
+SHA1 b69be5d3f06d651772e4a65ec6e6e3da6e9e419d lib/Jifty/DBI/Collection.pm
 SHA1 503ca4cf6693580dedf8adee58267532f8467908 lib/Jifty/DBI/Collection/Union.pm
 SHA1 bcba77fd2bacf0475aea1de97f57365c8de92ca6 lib/Jifty/DBI/Collection/Unique.pm
 SHA1 ac2e81ee7f24e65bcb40c86746f3e4159aeefb25 lib/Jifty/DBI/Column.pm
@@ -69,7 +69,7 @@
 SHA1 cf80896a175702a157770f64ae469430678c3357 lib/Jifty/DBI/Handle/mysql.pm
 SHA1 f2cc4fcce79c9a88a023d4e6bd96c2089eef1ced lib/Jifty/DBI/Handle/mysqlPP.pm
 SHA1 b7eca843dfbf0607bde08f566b2d03ba52fe82fd lib/Jifty/DBI/HasFilters.pm
-SHA1 1a5e2f434db00d9b31fa4153e1424c378dea0506 lib/Jifty/DBI/Record.pm
+SHA1 169e97345e6b581d88564da97cd3c1267ba0f010 lib/Jifty/DBI/Record.pm
 SHA1 663978b31373520d1e2deec87e957d1dbfd1347c lib/Jifty/DBI/Record/Cachable.pm
 SHA1 e30b1a3be2101d839a0a57e921e6f87889ef8da1 lib/Jifty/DBI/Record/Memcached.pm
 SHA1 53834b3315a509ba33a8647681f472d3ae7b0557 lib/Jifty/DBI/Record/Plugin.pm
@@ -89,7 +89,7 @@
 SHA1 4a4ed7341a37aa1ba4ecc03ad73e120a4052eac9 t/03rename_column.t
 SHA1 cb788b5336ae7c6f1fbf7795e38e2c4441f5c216 t/03rename_table.t
 SHA1 62c42d8458d73898f47f1b72d757239747321ef5 t/04memcached.t
-SHA1 4d2b42f80c2adaab70aa236a720cf57fa4b65677 t/05raw_value.t
+SHA1 854be4bb9e4e9643900341ec688ff9ec021a28e7 t/05raw_value.t
 SHA1 f0371e275879019e2abe732bbb5626d0d05049a0 t/06filter.t
 SHA1 38b1446e2b030261ba943dbdd03c48dfb6c3765f t/06filter_base64.t
 SHA1 646947b41cfcddf80b627505940244aed2c6c5ea t/06filter_boolean.t
@@ -100,16 +100,16 @@
 SHA1 f0f6ce9d48f419de6ac6154684f9065f32e30ddd t/06filter_truncate.t
 SHA1 2e9777a47e3a920d063bfbf9d56375c67c5b89c5 t/06filter_utf8.t
 SHA1 bb91f506a251d7b27d2fcd29c482a345318ef04f t/06filter_yaml.t
-SHA1 46197c643a2c26d678a2a79e61f550e4589bfadc t/10schema.t
+SHA1 92d6516ea923555ff5b54774d3d9b483170a6a4a t/10schema.t
 SHA1 f4b0e5a9c9c22b873f12551e8b4aea7592fd94d3 t/11schema_records.t
 SHA1 164ebb7144e978617c81306f5017bdcbcf41b801 t/12prefetch.t
-SHA1 2389b47958bd6f92a561ca893d7bfab166ced127 t/13collection.t
+SHA1 6792dbe544de8f24dccf9c412b96c913b4ff6388 t/13collection.t
 SHA1 41b7fbaf031d103a4f2066f177cc3bee84ab0458 t/14handle-pg.t
 SHA1 4f41229caa246bf6ebb369010deb0c1eb8809666 t/15types.t
 SHA1 5958e59e29d29fbf3862b5d3471472cbd82d191e t/16inheritance.t
 SHA1 c7004285662f16abca274918f86d17ea43fe8c90 t/17virtualtypes.t
-SHA1 cc7d6dd9889837143074729d30030ddabcfa6b9e t/18triggers.t
-SHA1 54b7727b49111162703581d13dd47dfe276fbe9a t/19reference.t
+SHA1 32457dd407414a89bd82d7fe59afab1014f8f920 t/18triggers.t
+SHA1 befc46d5364088775b6dda5ae1cf970c1b0fa4e8 t/19reference.t
 SHA1 72a16ddfc2642564023448450f3475ae5abf6d86 t/20overload.t
 SHA1 cf5b3950070fda63ba1b497f7d89dd6c36ae9c93 t/99-pod-coverage.t
 SHA1 12002f10b761d5952c5dc5143321379405283f9a t/99-pod-spelling.t
@@ -121,7 +121,7 @@
 -----BEGIN PGP SIGNATURE-----
 Version: GnuPG v1.4.10 (Darwin)
 
-iEYEARECAAYFAkz/6TgACgkQsxfQtHhyRPo1QgCfRMhwqkS8/56Xz/c4VihUk54k
-+JMAnRox8Eg3RIfhqpHd73M4BcyaqOFQ
-=Tm1r
+iEYEARECAAYFAk1ZnfAACgkQsxfQtHhyRPq6YQCfaTsXkpzasgXlv41gDq6JTpci
+khMAmwT7upq90E4xMjqIZEjJVVIcmRq9
+=osRu
 -----END PGP SIGNATURE-----

Modified: branches/upstream/libjifty-dbi-perl/current/lib/Jifty/DBI.pm
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libjifty-dbi-perl/current/lib/Jifty/DBI.pm?rev=69813&op=diff
==============================================================================
--- branches/upstream/libjifty-dbi-perl/current/lib/Jifty/DBI.pm (original)
+++ branches/upstream/libjifty-dbi-perl/current/lib/Jifty/DBI.pm Sun Feb 27 02:26:13 2011
@@ -2,7 +2,7 @@
 use warnings;
 use strict;
 
-$Jifty::DBI::VERSION = '0.64';
+$Jifty::DBI::VERSION = '0.66';
 
 =head1 NAME
 

Modified: branches/upstream/libjifty-dbi-perl/current/lib/Jifty/DBI/Collection.pm
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libjifty-dbi-perl/current/lib/Jifty/DBI/Collection.pm?rev=69813&op=diff
==============================================================================
--- branches/upstream/libjifty-dbi-perl/current/lib/Jifty/DBI/Collection.pm (original)
+++ branches/upstream/libjifty-dbi-perl/current/lib/Jifty/DBI/Collection.pm Sun Feb 27 02:26:13 2011
@@ -1255,7 +1255,9 @@
         : $args{'column'};
     my $clause_id = $args{'subclause'} || $qualified_column;
 
-    # XXX: when is column_obj undefined?
+    # $column_obj is undefined when the table2 argument to the join is a table
+    # name and not a collection model class.  In that case, the class key
+    # doesn't exist for the join.
     my $class
         = $self->{joins}{ $args{alias} }
         && $self->{joins}{ $args{alias} }{class}
@@ -1267,7 +1269,7 @@
     $self->new_item->_apply_input_filters(
         column    => $column_obj,
         value_ref => \$args{'value'},
-    ) if $column_obj && $column_obj->encode_on_select;
+    ) if $column_obj && $column_obj->encode_on_select && $args{operator} !~ /IS/;
 
     # make passing in an object DTRT
     my $value_ref = ref( $args{value} );
@@ -1275,17 +1277,23 @@
         if ( ( $value_ref ne 'ARRAY' )
             && $args{value}->isa('Jifty::DBI::Record') )
         {
-            $args{value} = $args{value}->id;
+            my $by = (defined $column_obj and defined $column_obj->by)
+                        ? $column_obj->by
+                        : 'id';
+            $args{value} = $args{value}->$by;
         } elsif ( $value_ref eq 'ARRAY' ) {
 
             # Don't modify the original reference, it isn't polite
             $args{value} = [ @{ $args{value} } ];
             map {
+                my $by = (defined $column_obj and defined $column_obj->by)
+                            ? $column_obj->by
+                            : 'id';
                 $_ = (
                       ( ref $_ && $_->isa('Jifty::DBI::Record') )
-                    ? ( $_->id )
+                    ? ( $_->$by )
                     : $_
-                    )
+                )
             } @{ $args{value} };
         }
     }
@@ -1560,6 +1568,10 @@
 the function then you have to build correct reference with alias
 in the C<alias.column> format.
 
+If you specify C<function> and C<column>, the column (and C<alias>) will be
+wrapped in the function.  This is useful for simple functions like C<min> or
+C<lower>.
+
 Use array of hashes to order by many columns/functions.
 
 Calling this I<sets> the ordering, it doesn't refine it. If you want to keep
@@ -1640,7 +1652,7 @@
             $rowhash{'order'} = "ASC";
         }
 
-        if ( $rowhash{'function'} ) {
+        if ( $rowhash{'function'} and not defined $rowhash{'column'} ) {
             $clause .= ( $clause ? ", " : " " );
             $clause .= $rowhash{'function'} . ' ';
             $clause .= $rowhash{'order'};
@@ -1650,9 +1662,11 @@
         {
 
             $clause .= ( $clause ? ", " : " " );
+            $clause .= $rowhash{'function'} . "(" if $rowhash{'function'};
             $clause .= $rowhash{'alias'} . "." if $rowhash{'alias'};
-            $clause .= $rowhash{'column'} . " ";
-            $clause .= $rowhash{'order'};
+            $clause .= $rowhash{'column'};
+            $clause .= ")" if $rowhash{'function'};
+            $clause .= " " . $rowhash{'order'};
         }
     }
     $clause = " ORDER BY$clause " if $clause;

Modified: branches/upstream/libjifty-dbi-perl/current/lib/Jifty/DBI/Record.pm
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libjifty-dbi-perl/current/lib/Jifty/DBI/Record.pm?rev=69813&op=diff
==============================================================================
--- branches/upstream/libjifty-dbi-perl/current/lib/Jifty/DBI/Record.pm (original)
+++ branches/upstream/libjifty-dbi-perl/current/lib/Jifty/DBI/Record.pm Sun Feb 27 02:26:13 2011
@@ -349,8 +349,12 @@
                         my $self = shift;
                         my $val  = shift;
 
-                        $val = $val->id
-                            if UNIVERSAL::isa( $val, 'Jifty::DBI::Record' );
+                        if (UNIVERSAL::isa( $val, 'Jifty::DBI::Record' )) {
+                            my $col = $self->column($column_name);
+                            my $by  = defined $col->by ? $col->by : 'id';
+                            $val = $val->$by;
+                        }
+
                         return (
                             $self->_set(
                                 column => $column_name,
@@ -569,18 +573,9 @@
     my $self = shift;
     return @{
         $self->_COLUMNS_CACHE() || $self->_COLUMNS_CACHE(
-            [   sort {
-                    ( ( ( $b->type || '' ) eq 'serial' )
-                        <=> ( ( $a->type || '' ) eq 'serial' ) )
-                        or (
-                        ( $a->sort_order || 0 ) <=> ( $b->sort_order || 0 ) )
-                        or ( $a->name cmp $b->name )
-                    } grep {
-                    $_->active
-                    } values %{ $self->_columns_hashref }
-            ]
+            [ grep { $_->active } $self->all_columns ]
         )
-        };
+    };
 }
 
 =head2 all_columns
@@ -596,11 +591,10 @@
 
     # Not cached because it's not expected to be used often
     return sort {
-        ( ( ( $b->type || '' ) eq 'serial' )
-            <=> ( ( $a->type || '' ) eq 'serial' ) )
-            or ( ( $a->sort_order || 0 ) <=> ( $b->sort_order || 0 ) )
-            or ( $a->name cmp $b->name )
-    } values %{ $self->_columns_hashref || {} };
+        ((($b->type || '') eq 'serial') <=> (($a->type || '') eq 'serial'))
+        or       (($a->sort_order || 0) <=> ($b->sort_order || 0))
+        or                   ( $a->name cmp $b->name )
+    } values %{ $self->_columns_hashref }
 }
 
 sub _columns_hashref {
@@ -919,6 +913,9 @@
     );
     return $ok if ( not defined $ok );
 
+    # Fetch the old value for the benefit of the triggers
+    my $old_value = $self->_value( $args{column} );
+
     $ok = $self->__set(%args);
     return $ok if not $ok;
 
@@ -928,13 +925,13 @@
     # Call the general after_set triggers
     $self->_run_callback(
         name => "after_set",
-        args => { column => $args{column}, value => $value },
+        args => { column => $args{column}, value => $value, old_value => $old_value },
     );
 
     # Call the specific after_set_column triggers
     $self->_run_callback(
         name => "after_set_" . $args{column},
-        args => { column => $args{column}, value => $value },
+        args => { column => $args{column}, value => $value, old_value => $old_value },
     );
 
     return $ok;
@@ -1130,9 +1127,8 @@
             }
 
             if ( blessed $value && $value->isa('Jifty::DBI::Record') ) {
-
-                # XXX TODO: check for proper foriegn keyness here
-                $value = $value->id;
+                my $by  = defined $column_obj->by ? $column_obj->by : 'id';
+                $value = $value->$by;
             }
 
             $self->_apply_input_filters(
@@ -1404,11 +1400,12 @@
         }
         if (    $column->readable
             and $column->refers_to
-            and UNIVERSAL::isa( $column->refers_to, "Jifty::DBI::Record" ) )
+            and UNIVERSAL::isa( $column->refers_to, "Jifty::DBI::Record" )
+            and UNIVERSAL::isa( $attribs{$column_name}, 'Jifty::DBI::Record' ) )
         {
-            $attribs{$column_name} = $attribs{$column_name}->id
-                if UNIVERSAL::isa( $attribs{$column_name},
-                'Jifty::DBI::Record' );
+            # lookup the column referenced or default to id
+            my $by = defined $column->by ? $column->by : 'id';
+            $attribs{$column_name} = $attribs{$column_name}->$by;
         }
 
         $self->_apply_input_filters(

Modified: branches/upstream/libjifty-dbi-perl/current/t/05raw_value.t
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libjifty-dbi-perl/current/t/05raw_value.t?rev=69813&op=diff
==============================================================================
--- branches/upstream/libjifty-dbi-perl/current/t/05raw_value.t (original)
+++ branches/upstream/libjifty-dbi-perl/current/t/05raw_value.t Sun Feb 27 02:26:13 2011
@@ -5,6 +5,9 @@
 use Test::More;
 BEGIN { require "t/utils.pl" }
 our (@available_drivers);
+
+eval "use URI";
+plan skip_all => "URI required for testing the URI filter" if $@;
 
 use constant TESTS_PER_DRIVER => 14;
 
@@ -33,7 +36,7 @@
         my $rec = TestApp::User->new( handle => $handle );
         isa_ok($rec, 'Jifty::DBI::Record');
 
-        use URI;
+        require URI;
         my $uri = URI->new( 'http://bestpractical.com/foo' );
         my ($id) = $rec->create(uri => $uri);
         ok($id, "Successfuly created a user");

Modified: branches/upstream/libjifty-dbi-perl/current/t/10schema.t
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libjifty-dbi-perl/current/t/10schema.t?rev=69813&op=diff
==============================================================================
--- branches/upstream/libjifty-dbi-perl/current/t/10schema.t (original)
+++ branches/upstream/libjifty-dbi-perl/current/t/10schema.t Sun Feb 27 02:26:13 2011
@@ -5,7 +5,7 @@
 use Test::More;
 use version;
 
-use constant TESTS_PER_DRIVER => 77;
+use constant TESTS_PER_DRIVER => 87;
 our @available_drivers;
 
 BEGIN {
@@ -111,6 +111,7 @@
 
     for my $version (qw/ 0.2.0 0.2.4 0.2.6 0.2.8 0.2.9 /) {
 
+        Sample::Address->_COLUMNS_CACHE(undef);
         Sample::Address->schema_version($version);
 
         my $SG = Jifty::DBI::SchemaGenerator->new($handle, $version);
@@ -131,6 +132,11 @@
         else {
             ok(!Sample::Address->COLUMNS->{street}->active, 'street not active');
         }
+
+        # employee_id shows up twice when we map over name because employee
+        # is automagically injected as an aliased column
+        is_deeply([map { $_->name } Sample::Address->all_columns], [qw(id employee_id employee_id name phone street)], "got all columns");
+        is_deeply([map { $_->name } Sample::Address->columns], [qw(id employee_id employee_id name phone), ($street_added ? qw(street) : ())], "got all active columns");
 
         my $address_version_schema = $street_added ? "${address_schema}_024"
             :                                         $address_schema;

Modified: branches/upstream/libjifty-dbi-perl/current/t/13collection.t
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libjifty-dbi-perl/current/t/13collection.t?rev=69813&op=diff
==============================================================================
--- branches/upstream/libjifty-dbi-perl/current/t/13collection.t (original)
+++ branches/upstream/libjifty-dbi-perl/current/t/13collection.t Sun Feb 27 02:26:13 2011
@@ -3,7 +3,7 @@
 use strict;
 use warnings;
 
-use Test::More tests => 8;
+use Test::More tests => 10;
 
 my $package;
 BEGIN { 
@@ -123,5 +123,26 @@
    ' ORDER BY ab.msg_id DESC, main.yaks ASC ',
    "add_order_by works when passing a list-as-hash directly";
 
+# test specifying just function
+$obj->order_by(
+    function => 'min(foo)',
+);
+
+is $obj->_order_clause,
+   ' ORDER BY min(foo) ASC ',
+   "order_by function and column works";
+
+# test specifying function and column
+$obj->order_by(
+    function => 'lower',
+    column => 'name',
+    order => 'DESC',
+);
+
+is $obj->_order_clause,
+   ' ORDER BY lower(main.name) DESC ',
+   "order_by function and column works";
+
 $obj->clear_order_by;
 is($obj->_order_clause, '', "clear_order_by works");
+

Modified: branches/upstream/libjifty-dbi-perl/current/t/18triggers.t
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libjifty-dbi-perl/current/t/18triggers.t?rev=69813&op=diff
==============================================================================
--- branches/upstream/libjifty-dbi-perl/current/t/18triggers.t (original)
+++ branches/upstream/libjifty-dbi-perl/current/t/18triggers.t Sun Feb 27 02:26:13 2011
@@ -7,7 +7,7 @@
 BEGIN { require "t/utils.pl" }
 our (@available_drivers);
 
-use constant TESTS_PER_DRIVER => 62;
+use constant TESTS_PER_DRIVER => 66;
 
 my $total = scalar(@available_drivers) * TESTS_PER_DRIVER;
 plan tests => $total;
@@ -90,9 +90,10 @@
         my $arg = shift;
         isa_ok($self, 'TestApp::Address');
         is(ref $arg, 'HASH', 'arg is a hash');
-        is(scalar(keys %$arg), 2, 'hash has 2 keys');
+        is(scalar(keys %$arg), 3, 'hash has 3 keys');
         ok($arg->{column}, "column arg is set");
         ok($arg->{value}, "value arg is set");
+        ok($arg->{old_value}, "old_value arg is set");
     });
     $self->add_trigger(before_delete => sub {
         my $self = shift;
@@ -111,8 +112,8 @@
     my $self   = shift;
     my $column = shift;
 
-    my $value = $column eq 'name' ? 'zostay'
-              :                     '098 765 4321';
+    my $old_value = $column eq 'name' ? 'Sterling' : '123 456 7890';
+    my $value     = $column eq 'name' ? 'zostay'   : '098 765 4321';
 
     $self->add_trigger('before_set_'.$column => sub {
         my $self = shift;
@@ -129,9 +130,10 @@
         my $arg = shift;
         isa_ok($self, 'TestApp::Address');
         is(ref $arg, 'HASH', 'arg is a hash');
-        is(scalar(keys %$arg), 2, 'hash has 2 keys');
+        is(scalar(keys %$arg), 3, 'hash has 3 keys');
         is($arg->{column}, $column, "column arg is $column");
         is($arg->{value}, $value, "value arg is $value");
+        is($arg->{old_value}, $old_value, "old_value arg is $old_value");
     });
 }
 

Modified: branches/upstream/libjifty-dbi-perl/current/t/19reference.t
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libjifty-dbi-perl/current/t/19reference.t?rev=69813&op=diff
==============================================================================
--- branches/upstream/libjifty-dbi-perl/current/t/19reference.t (original)
+++ branches/upstream/libjifty-dbi-perl/current/t/19reference.t Sun Feb 27 02:26:13 2011
@@ -6,7 +6,7 @@
 BEGIN { require "t/utils.pl" }
 our (@available_drivers);
 
-use constant TESTS_PER_DRIVER => 13;
+use constant TESTS_PER_DRIVER => 40;
 
 my $total = scalar(@available_drivers) * TESTS_PER_DRIVER;
 plan tests => $total;
@@ -34,17 +34,31 @@
         {my $ret = init_schema( 'TestApp::Food', $handle );
         isa_ok($ret,'DBI::st', "Inserted the schema. got a statement handle back" );}
 
-        my $rec = TestApp::Currency->new( handle => $handle );
-        isa_ok($rec, 'Jifty::DBI::Record');
-
-        my ($id) = $rec->create( name => "USD" );
-
-        $rec = TestApp::Food->new( handle => $handle );
+        # USD
+        my $usd = TestApp::Currency->new( handle => $handle );
+        isa_ok($usd, 'Jifty::DBI::Record');
+
+        my ($id) = $usd->create( name => "USD" );
+        ok($id, "got id");
+        ok($usd->load($id), "loaded the just created currency record (USD)");
+        is($usd->name, "USD", "same name");
+
+        # GBP
+        my $gbp = TestApp::Currency->new(handle=>$handle);
+        isa_ok($usd, 'Jifty::DBI::Record');
+
+        my ($gid) = $gbp->create( name => "GBP" );
+        ok($gid, "got id");
+        ok($gbp->load($gid), "loaded the just created currency record (GBP)");
+        is($gbp->name, "GBP", "same name");
+        
+        my $rec = TestApp::Food->new( handle => $handle );
         isa_ok($rec, 'Jifty::DBI::Record');
 
         my ($paella) = $rec->create( name => "paella" );
         $rec->create( name => "nigiri" );
 
+        # create using currency string
         $rec = TestApp::User->new( handle => $handle );
         ($id) = $rec->create( currency => 'USD' );
 
@@ -54,12 +68,71 @@
         is($rec->currency->name, 'USD');
 
         is( $rec->food, undef, 'null_reference option in effect' );
-
-        no warnings 'once';
-        local *TestApp::User::null_reference = sub {0};
-        $rec->load($id);
-        isa_ok($rec->food, 'TestApp::Food', 'referee is null but shuold still return an object');
-        is($rec->food->id, undef);
+        
+        {
+            no warnings 'once';
+            local *TestApp::User::null_reference = sub {0};
+            $rec->load($id);
+            isa_ok($rec->food, 'TestApp::Food', 'referee is null but shuold still return an object');
+            is($rec->food->id, undef);
+        }
+
+        # create using currency object
+        $rec = TestApp::User->new( handle => $handle );
+        ($id) = $rec->create( currency => $usd );
+
+        ok($id);
+        ok($rec->load($id), "Loaded the record");
+        isa_ok($rec->currency, 'TestApp::Currency');
+        is($rec->currency->name, 'USD');
+
+        my $food = TestApp::Food->new( handle => $handle );
+        $food->load($paella);
+
+        # create with undef, set using currency string
+        $rec = TestApp::User->new( handle => $handle );
+        ($id) = $rec->create(food => $food);
+
+        ok($id);
+        ok($rec->load($id), "Loaded the record");
+        is($rec->currency, undef, 'No currency object');
+        $rec->set_currency('USD');
+        isa_ok($rec->currency, 'TestApp::Currency');
+        is($rec->currency->name, 'USD');
+
+        # create with undef, set using currency object
+        $rec = TestApp::User->new( handle => $handle );
+        ($id) = $rec->create(food => $food);
+
+        ok($id);
+        ok($rec->load($id), "Loaded the record");
+        is($rec->currency, undef, 'No currency object');
+        $rec->set_currency($gbp);
+        isa_ok($rec->currency, 'TestApp::Currency');
+        is($rec->currency->name, 'GBP');
+
+        # load_by_cols with object
+        $rec = TestApp::User->new(handle=>$handle);
+        $rec->load_by_cols( currency => $usd );
+
+        ok($rec->id, "got id");
+        is($rec->currency->name, "USD", "got currency");
+
+        # limit with object
+        my $users = TestApp::UserCollection->new(handle => $handle);
+        $users->limit( column => 'currency', value => $usd );
+
+        is($users->count, 3, "got 3 users");
+        is($users->first->currency->name, "USD", "got USD");
+
+        $users = TestApp::UserCollection->new(handle => $handle);
+        $users->limit( column => 'currency', value => $gbp );
+        is($users->count, 1, "got 1 users");
+        
+        # limit with mixed array
+        $users = TestApp::UserCollection->new(handle => $handle);
+        $users->limit( column => 'currency', value => [$gbp, 'USD'] );
+        is($users->count, 4, "got 4 users");
 }
 }
 
@@ -199,4 +272,7 @@
 
 };
 
+package TestApp::UserCollection;
+use base qw/Jifty::DBI::Collection/;
+
 1;




More information about the Pkg-perl-cvs-commits mailing list