-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy path03_flash.t
77 lines (49 loc) · 2 KB
/
03_flash.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
use strict;
use warnings;
use Test::More;
use Test::Deep;
use Catalyst::Plugin::Session;
my $c_meta = Class::MOP::Class->create_anon_class(
superclasses => [ 'Catalyst::Plugin::Session', 'Moose::Object', ],
);
my $c = $c_meta->name->new;
my $flash = {};
$c_meta->add_method(
get_session_data => sub {
my ( $c, $key ) = @_;
return $key =~ /expire/ ? time() + 1000 : $flash;
},
);
$c->meta->add_method("debug" => sub { 0 });
$c->meta->add_method("store_session_data" => sub { $flash = $_[2] });
$c->meta->add_method("delete_session_data" => sub { $flash = {} });
$c->meta->add_method( _sessionid => sub { "deadbeef" });
my $config = { expires => 1000 };
$c->meta->add_method( config => sub { { session => $config } });
my $stash = {};
$c->meta->add_method( stash => sub { $stash } );
is_deeply( $c->session, {}, "nothing in session" );
is_deeply( $c->flash, {}, "nothing in flash" );
$c->flash->{foo} = "moose";
$c->finalize_body;
is_deeply( $c->flash, { foo => "moose" }, "one key in flash" );
cmp_deeply( $c->session, { __updated => re('^\d+$'), __flash => $c->flash }, "session has __flash with flash data" );
$c->flash(bar => "gorch");
is_deeply( $c->flash, { foo => "moose", bar => "gorch" }, "two keys in flash" );
cmp_deeply( $c->session, { __updated => re('^\d+$'), __flash => $c->flash }, "session still has __flash with flash data" );
$c->finalize_body;
is_deeply( $c->flash, { bar => "gorch" }, "one key in flash" );
$c->finalize_body;
$c->flash->{test} = 'clear_flash';
$c->finalize_body;
$c->clear_flash();
is_deeply( $c->flash, {}, "nothing in flash after clear_flash" );
$c->finalize_body;
is_deeply( $c->flash, {}, "nothing in flash after finalize after clear_flash" );
cmp_deeply( $c->session, { __updated => re('^\d+$'), }, "session has empty __flash after clear_flash + finalize" );
$c->flash->{bar} = "gorch";
$config->{flash_to_stash} = 1;
$c->finalize_body;
$c->prepare_action;
is_deeply( $c->stash, { bar => "gorch" }, "flash copied to stash" );
done_testing;