Dancer2-Session-DBIC
view release on metacpan or search on metacpan
* Use DBIx::Sugar (Peter Mottram).
* Switch from Class::Load try_load_class to Module::Runtime use_module
(Peter Mottram).
* Use Dancer2::Serializer::JSON instead of JSON (Peter Mottram).
* Allow non primary key as session id column (Andy Jack, GH #2).
[BUG FIXES]
* Fix generating new sessions for every request
(Peter Mottram, Rory Zweistra, GH #9).
* Use decoded_content instead of content in UTF-8 tests
(Peter Mottram, GH #8).
[TESTS]
* Stop Test::More complaining about wide chars in print (Peter Mottram).
* Add tests for UTF-8 data in the session (Stefan Hornburg/Racke).
* Add test for correct primary key in sessions table
(Stefan Hornburg/Racke).
0.007 Wed Aug 6 11:03:52 2014 CEST
t/plugin_dbic.t view on Meta::CPAN
my $app = Dancer2->runner->psgi_app;
is( ref $app, 'CODE', 'Got app' );
test_psgi $app, sub {
my $cb = shift;
my $res = $cb->( GET '/sessionid' );
my $newid = $res->decoded_content;
# extract the cookie
my $cookie = $res->header('Set-Cookie');
$cookie =~ s/^(.*?);.*$/$1/s;
ok( $cookie, "Got the cookie: $cookie" );
my @headers = ( Cookie => $cookie );
my $session_id = $cb->( GET '/id', @headers )->decoded_content;
like( $session_id, qr/^[0-9a-z_-]+$/i, 'Retrieve session id', );
is(
$cb->( GET '/getfoo', @headers )->decoded_content,
'', 'Retrieve pristine foo key',
);
is(
$cb->( GET '/putfoo', @headers )->decoded_content,
'bar', 'Set foo key to bar',
);
is(
$cb->( GET '/getfoo', @headers )->decoded_content,
'bar', 'Retrieve foo key which is "bar" now',
);
is(
$cb->( GET '/getcamel', @headers )->decoded_content,
'', 'Retrieve pristine camel key',
);
is(
$cb->( GET '/putcamel', @headers )->decoded_content,
'ã©ã¯ã', 'Set camel key to ã©ã¯ã',
);
is(
$cb->( GET '/getcamel', @headers )->decoded_content,
'ã©ã¯ã', 'Retrieve camel key which is "ã©ã¯ã" now',
);
like(
$cb->( GET '/sessionid', @headers )->decoded_content,
qr/\w/, "Found session id",
);
my $oldid = $cb->( GET '/sessionid', @headers )->decoded_content;
is( $oldid, $newid, "Same id, session holds" );
is(
$cb->( GET '/destroy', @headers )->decoded_content,
'Session destroyed',
'Session destroyed without crashing',
);
is(
$cb->( GET '/getfoo', @headers )->decoded_content,
'', 'Retrieve pristine foo key after destroying',
);
$newid = $cb->( GET '/sessionid', @headers )->decoded_content;
ok( $newid ne $oldid, "New and old ids differ" );
};
done_testing;
my $app = Dancer2->runner->psgi_app;
is( ref $app, 'CODE', 'Got app' );
test_psgi $app, sub {
my $cb = shift;
my $res = $cb->( GET '/sessionid' );
my $newid = $res->decoded_content;
# extract the cookie
my $cookie = $res->header('Set-Cookie');
$cookie =~ s/^(.*?);.*$/$1/s;
ok ($cookie, "Got the cookie: $cookie");
my @headers = (Cookie => $cookie);
my $session_id = $cb->( GET '/id', @headers)->decoded_content;
like(
$session_id,
qr/^[0-9a-z_-]+$/i,
'Retrieve session id',
);
is(
$cb->( GET '/getfoo', @headers )->decoded_content,
'',
'Retrieve pristine foo key',
);
cmp_ok $schema->resultset($rs_expected)->count, '==', 1,
"One session in the database";
ok $schema->resultset($rs_expected)
->find( { $pk_expected => $session_id } ),
"Database record found with correct session id";
is(
$cb->( GET '/putfoo', @headers )->decoded_content,
'bar',
'Set foo key to bar',
);
is(
$cb->( GET '/getfoo', @headers )->decoded_content,
'bar',
'Retrieve foo key which is "bar" now',
);
is(
$cb->( GET '/getcamel', @headers )->decoded_content,
'',
'Retrieve pristine camel key',
);
is(
$cb->( GET '/putcamel', @headers )->decoded_content,
'ã©ã¯ã',
'Set camel key to ã©ã¯ã',
);
is(
$cb->( GET '/getcamel', @headers )->decoded_content,
'ã©ã¯ã',
'Retrieve camel key which is "ã©ã¯ã" now',
);
like(
$cb->( GET '/sessionid', @headers )->decoded_content,
qr/\w/,
"Found session id",
);
my $oldid = $cb->( GET '/sessionid', @headers )->decoded_content;
is($oldid, $newid, "Same id, session holds");
$res = $cb->( GET '/change_session_id', @headers );
$newid = $res->decoded_content;
SKIP: {
skip "This Dancer2 version does not support change_session_id", 5
unless $newid ne 'unsupported';
note "testing change_session_id";
isnt( $oldid, $newid,
"after change_session_id we have new ID in response" );
$cookie = $res->header('Set-Cookie');
cmp_ok $schema->resultset($rs_expected)->count, '==', 1,
"One session in the database";
ok $schema->resultset($rs_expected)
->find( { $pk_expected => $newid } ),
"Database record found with correct session id";
}
is(
$cb->( GET '/destroy', @headers)->decoded_content,
'Session destroyed',
'Session destroyed without crashing',
);
is(
$cb->( GET '/getfoo', @headers )->decoded_content,
'',
'Retrieve pristine foo key after destroying',
);
$newid = $cb->( GET '/sessionid', @headers )->decoded_content;
ok($newid ne $oldid, "New and old ids differ");
};
return $dbic_session;
}
done_testing;
( run in 0.282 second using v1.01-cache-2.11-cpan-a9ef4e587e4 )