Dancer2-Session-DatabasePlugin

 view release on metacpan or  search on metacpan

t/Dancer2-Session-DatabasePlugin.t  view on Meta::CPAN

use Modern::Perl;
use Data::Dumper;
use Test::More qw(no_plan);
use Plack::Test;
use HTTP::Request::Common;
use File::Temp qw(tempfile);

eval 'require DBD::SQLite';
our $TEST_DB=!$@;

our $SESSION;
our $DBC;
my $class='Dancer2::Session::DatabasePlugin';
require_ok($class);
use_ok($class);

my $self=$class->new;

our $DB;
our $FH;
our ($FH2,$DB2);
BEGIN {
  ($FH,$DB)=tempfile(EXLOCK=>0);
  ($FH2,$DB2)=tempfile(EXLOCK=>0);
}

cmp_ok($self->create_flush_query,'eq','INSERT into SESSIONS (SESSION_ID,SESSION_DATA) values (?,?)','Validate INSERT');
cmp_ok($self->create_retrieve_query,'eq','SELECT SESSION_DATA FROM SESSIONS WHERE SESSION_ID=?','Validate SELECT');
cmp_ok($self->create_sessions_query,'eq','SELECT SESSION_ID FROM SESSIONS','Validate SELECT_ALL');
cmp_ok($self->create_destroy_query,'eq','DELETE FROM SESSIONS WHERE SESSION_ID=?','Validate DELETE');
cmp_ok($self->create_update_query,'eq','UPDATE SESSIONS SET SESSION_DATA=? WHERE SESSION_ID=?','Validate UPDATE');
cmp_ok($self->create_change_query,'eq','UPDATE SESSIONS SET SESSION_ID=? WHERE SESSION_ID=?','Validate RENAME');

my $app=Test::Session->to_app;

my $h='Set-Cookie';
is( ref $app, 'CODE', 'Got app' );
my $test = Plack::Test->create($app);

SKIP: {
  skip 'Cannot load DBD::SQLite',33 unless $TEST_DB;
  skip 'Cannot create test database',33 unless $FH;
  skip '$ENV{ENABLE_DB_TESTING} is false',33 unless $ENV{ENABLE_DB_TESTING};
  {
    my $res  = $test->request( GET '/setup' );
    cmp_ok($res->code,'==',200,'Should get a 200');
    ok(!$res->header($h),'Should not have a cookie!');
    cmp_ok(keys(%{$SESSION->sth_cache}),'==',0,'Should have 0 statement handles');
  }
  {
    my $res  = $test->request( GET '/' );
    cmp_ok($res->code,'==',200,'Should get a 200');
    ok(!$res->header($h),'Should not have a cookie!');
    cmp_ok(keys(%{$SESSION->sth_cache}),'==',0,'Should have 0 statement handles');
  }
  
  my $cookie;
  {
    my $res  = $test->request( GET '/session/create' );
    cmp_ok($res->code,'==',200,'Should get a 200');
    ok($cookie=$res->header($h),'Should have a cookie!');

 view all matches for this distribution
 view release on metacpan -  search on metacpan

( run in 0.646 second using v1.00-cache-2.02-grep-82fe00e-cpan-2c419f77a38b )