Created
December 21, 2012 05:17
-
-
Save yappo/4350807 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use strict; | |
use warnings; | |
use Test::More; | |
{ | |
package Model; | |
use parent 'Teng'; | |
} | |
{ | |
package Model::Schema; | |
use Teng::Schema::Declare; | |
table { | |
name 'teng'; | |
pk 'id'; | |
columns qw( id at ); | |
inflate at => sub { | |
my $val = shift; | |
"at = $val"; | |
}; | |
deflate at => sub { | |
my $val = shift; | |
$val =~ s/^at = // or die 'bad format'; | |
$val; | |
}; | |
}; | |
} | |
my $db = Model->new( | |
connect_info => [ 'dbi:SQLite:dbname=:memory:' ] | |
); | |
$db->dbh->do(q{CREATE TABLE teng ( id INTEGER PRIMARY KEY, at INTEGER)}); | |
$db->insert( 'teng', { id => 1, at => 'at = 1000' } ); | |
subtest 'ok pattern' => sub { | |
my $row = $db->single( 'teng', { id => 1 } ); | |
is $row->at, 'at = 1000'; | |
$row->at(10); | |
is $row->at, 'at = 10'; | |
$row->update({ at => 'at = 1' }); | |
is $row->at, 'at = 1'; | |
}; | |
subtest 'bad pattern' => sub { | |
my $row = $db->single( 'teng', { id => 1 } ); | |
$row->at(31); | |
eval { | |
$row->update; | |
is $row->at, 'at = 31'; | |
}; | |
is $@, ''; | |
}; | |
done_testing; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment