[Jifty-commit] r5184 - in Jifty-DBI/trunk: lib/Jifty/DBI/Filter t
Jifty commits
jifty-commit at lists.jifty.org
Fri Feb 29 20:03:17 EST 2008
Author: sartak
Date: Fri Feb 29 20:03:17 2008
New Revision: 5184
Modified:
Jifty-DBI/trunk/ (props changed)
Jifty-DBI/trunk/lib/Jifty/DBI/Filter/Boolean.pm
Jifty-DBI/trunk/t/06filter_boolean.t
Log:
r52275 at onn: sartak | 2008-02-29 20:02:51 -0500
encode and decode were swapped :|
Some test fixes. DBD::Pg has a damn "DWIM" option for booleans that caused failures
Modified: Jifty-DBI/trunk/lib/Jifty/DBI/Filter/Boolean.pm
==============================================================================
--- Jifty-DBI/trunk/lib/Jifty/DBI/Filter/Boolean.pm (original)
+++ Jifty-DBI/trunk/lib/Jifty/DBI/Filter/Boolean.pm Fri Feb 29 20:03:17 2008
@@ -40,7 +40,7 @@
=head1 DESCRIPTION
-=head2 encode
+=head2 decode
Transform the value into 1 or 0 so Perl's concept of the boolean's value agrees
with the database's concept of the boolean's value. (For example, 't' and 'f'
@@ -48,7 +48,7 @@
=cut
-sub encode {
+sub decode {
my $self = shift;
my $value_ref = $self->value_ref;
@@ -66,14 +66,14 @@
}
}
-=head2 decode
+=head2 encode
Transform the value to the canonical true or false value as expected by the
database.
=cut
-sub decode {
+sub encode {
my $self = shift;
my $value_ref = $self->value_ref;
Modified: Jifty-DBI/trunk/t/06filter_boolean.t
==============================================================================
--- Jifty-DBI/trunk/t/06filter_boolean.t (original)
+++ Jifty-DBI/trunk/t/06filter_boolean.t Fri Feb 29 20:03:17 2008
@@ -51,12 +51,23 @@
ok($rec->load($id), 'loaded record');
is($rec->id, $id, 'record id matches');
- ok($bool eq 'true' ? $rec->my_data : !$rec->my_data, 'Perl agrees with the expected boolean value');
+ is($rec->my_data, $bool eq 'true' ? 1 : 0, 'Perl agrees with the expected boolean value');
+
my $sth = $handle->simple_query("SELECT my_data FROM users WHERE id = $id");
my ($got) = $sth->fetchrow_array;
+ if ($d eq 'Pg') {
+ # this option tells DBD::Pg to keep booleans as 't' and 'f' and not
+ # map them to 1 and 0
+ $handle->dbh->{pg_bool_tf} = 0;
+ }
+
my $method = "canonical_$bool";
- is( $got, $handle->$method, 'my_data bool match' );
+ is( $got, $handle->$method, "my_data bool match for " . (defined($input) ? $input : 'undef') . " ($bool)" );
+
+ if ($d eq 'Pg') {
+ $handle->dbh->{pg_bool_tf} = 1;
+ }
# undef/NULL
$rec->set_my_data;
@@ -79,7 +90,12 @@
column => 'my_data',
value => $input,
);
- ok($bool eq 'true' ? $col->first->my_data : !$col->first->my_data, 'Perl agrees with the expected boolean value');
+ if ($col->count) {
+ ok($bool eq 'true' ? $col->first->my_data : !$col->first->my_data, 'Perl agrees with the expected boolean value');
+ }
+ else {
+ fail("Got no results from limit");
+ }
}
cleanup_schema('TestApp', $handle);
More information about the Jifty-commit
mailing list