-
Notifications
You must be signed in to change notification settings - Fork 2
/
schema.t
84 lines (55 loc) · 2.21 KB
/
schema.t
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
use strict;
use warnings;
use utf8;
use Test::More;
use Test::Exception;
use Dancer::Session::DBIC;
use Dancer qw(:syntax :tests);
use File::Spec;
use lib File::Spec->catdir( 't', 'lib' );
use DBICx::TestDatabase;
use Test::WibbleObject;
test_session_schema('Test::Schema');
test_session_schema('Test::Custom', {resultset => 'Custom',
id_column => 'customs_id',
data_column => 'custom_data'});
sub test_session_schema {
my ($schema_class, $schema_options) = @_;
my $schema = DBICx::TestDatabase->new($schema_class);
set session => 'DBIC';
set session_options => {
%{$schema_options || {}},
schema => sub {return $schema},
};
my $session = session->create;
isa_ok($session, 'Dancer::Session::DBIC');
my $session_id = session->id;
ok(defined($session_id) && $session_id > 0, 'Testing session id')
|| diag "Session id: ", $session_id;
session foo => 'bar';
my $session_value = session('foo');
ok($session_value eq 'bar', 'Testing session value')
|| diag "Session value: ", $session_value;
# destroy session
session->destroy;
my $next_session_id = session->id;
my $resultset = $schema_options->{resultset} || 'Session';
my $ret = $schema->resultset($resultset)->find($session_id);
ok(! defined($ret), 'Testing session destruction')
|| diag "Return value: ", $ret;
# testing with utf8 character
session camel => 'ラクダ';
my $camel = session('camel');
ok ($camel eq 'ラクダ', 'Testing utf-8 characters in the session.')
|| diag "Return values: ", $camel;
# to_json allows objects
my ( $wibble, $data );
lives_ok( sub { $wibble = Test::WibbleObject->new() },
"create Test::WibbleObject" );
isa_ok( $wibble, "Test::WibbleObject" );
lives_ok( sub { $wibble->name("Foo")}, "wibble name set to Foo" );
lives_ok( sub { session wibble => $wibble }, "put wibble in session" );
lives_ok( sub { $data = session('wibble') }, "get wibble out of session" );
is_deeply( $data, { name => "Foo" }, "returned data is good" );
}
done_testing;