Context-Set
view release on metacpan or search on metacpan
t/03-persist.t view on Meta::CPAN
#!perl -T
use strict;
use warnings;
use Test::More tests => 68;
use Test::Fatal qw/dies_ok lives_ok/;
use Context::Set::Manager;
use Context::Set::Storage::DBIC;
use Context::Set::Storage::Split;
use DBI;
use DBD::SQLite;
use Log::Log4perl qw/:easy/;
Log::Log4perl->easy_init($DEBUG);
package My::Schema;
## This is a schema that will be build dynamically.
use base qw/DBIx::Class::Schema::Loader/;
__PACKAGE__->naming('current');
1;
package main;
my $dbh = DBI->connect("dbi:SQLite::memory:" , "", "");
$dbh->{AutoCommit} = 1;
$dbh->do(q|CREATE TABLE contextvalue(id INTEGER PRIMARY KEY AUTOINCREMENT,
context_name VARCHAR(512) NOT NULL,
is_array BOOLEAN NOT NULL,
key VARCHAR(512) NOT NULL,
value VARCHAR(512));|);
## For the split storage
$dbh->do(q|
CREATE TABLE aa(id INTEGER PRIMARY KEY AUTOINCREMENT,
context_name VARCHAR(512) NOT NULL,
is_array BOOLEAN NOT NULL,
key VARCHAR(512) NOT NULL,
value VARCHAR(512));|);
$dbh->do(q|
CREATE TABLE bb(id INTEGER PRIMARY KEY AUTOINCREMENT,
context_name VARCHAR(512) NOT NULL,
is_array BOOLEAN NOT NULL,
key VARCHAR(512) NOT NULL,
value VARCHAR(512));|);
## Build a schema dynamically.
ok( my $schema = My::Schema->connect(sub{ return $dbh ;} , { unsafe => 1 } ), "Ok built schema with dbh");
cmp_ok( scalar($schema->sources) , 'eq' , 3 , "3 sources in schema");
ok( my $rs = $schema->resultset('Contextvalue') , "Ok got resultset");
## And build a Context storage.
my $storage_dbic = Context::Set::Storage::DBIC->new({ resultset => $rs });
## We also need a split storage
my $users_store = Context::Set::Storage::DBIC->new({ resultset => scalar($schema->resultset('Aa')) });
my $general_store = Context::Set::Storage::DBIC->new({ resultset => scalar($schema->resultset('Bb')) });
my $split_store = Context::Set::Storage::Split->new({
rules => [{
name => 'users_specific',
test => sub{ shift->is_inside('users'); },
storage => $users_store
},
( run in 1.305 second using v1.01-cache-2.11-cpan-54e63673c56 )