Skip to content

Commit

Permalink
bugfix: strange response of single method when specify unmatched cond…
Browse files Browse the repository at this point in the history
…ition
  • Loading branch information
ytnobody committed Dec 28, 2013
1 parent ad3e601 commit 2bcb501
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/Otogiri.pm
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ sub _deflate_param {

sub _inflate_rows {
my ($self, $table, @rows) = @_;
@rows = $self->{inflate} ? map {$self->{inflate}->($_, $table)} @rows : @rows;
@rows = $self->{inflate} ? map {$self->{inflate}->($_, $table)} grep {defined $_} @rows : @rows;
wantarray ? @rows : $rows[0];
}

Expand Down
31 changes: 31 additions & 0 deletions t/40_01_bug_single_with_void_result.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
use strict;
use warnings;
use Test::More;
use Otogiri;

my $dbfile = ':memory:';
my $db = Otogiri->new(
connect_info => ["dbi:SQLite:dbname=$dbfile", '', ''],
inflate => sub {
my ($row, $table) = @_;
$row->{table} = $table;
$row;
},
deflate => sub {
my ($row, $table) = @_;
delete $row->{table};
$row;
},
);

subtest strange_response => sub {
$db->do(<<'SQL'
CREATE TABLE test (id int, name text)
SQL
);
$db->fast_insert(test => {id => 123, name => 'foo'});
my $row = $db->single(test => {id => 111});
is $row, undef;
};

done_testing;

0 comments on commit 2bcb501

Please sign in to comment.