Skip to content

Instantly share code, notes, and snippets.

@yappo
Created December 21, 2012 05:17
Show Gist options
  • Save yappo/4350807 to your computer and use it in GitHub Desktop.
Save yappo/4350807 to your computer and use it in GitHub Desktop.
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