Various refactorings and fixes for the session plugin's lazy loading
[catagits/Catalyst-Plugin-Session.git] / t / 03_flash.t
CommitLineData
da9aa7d5 1#!/usr/bin/perl
2
3use strict;
4use warnings;
5
19c130c2 6use Test::More tests => 7;
da9aa7d5 7use Test::MockObject::Extends;
8use Test::Exception;
9
10my $m;
11BEGIN { use_ok( $m = "Catalyst::Plugin::Session" ) }
12
ab634fee 13my $c = Test::MockObject::Extends->new($m);
14
15my $flash = {};
16$c->mock(
17 get_session_data => sub {
18 my ( $c, $key ) = @_;
19 return $key =~ /expire/ ? time() + 1000 : $flash;
20 }
21);
22$c->set_true("store_session_data");
23$c->set_always( _sessionid => "deadbeef" );
24$c->set_always( config => { session => { expires => 1000 } } );
25$c->set_always( stash => {} );
da9aa7d5 26
ab634fee 27is_deeply( $c->flash, {}, "nothing in flash" );
da9aa7d5 28
29$c->flash->{foo} = "moose";
30
31$c->finalize;
da9aa7d5 32
33is_deeply( $c->flash, { foo => "moose" }, "one key in flash" );
34
35$c->flash->{bar} = "gorch";
36
ab634fee 37is_deeply( $c->flash, { foo => "moose", bar => "gorch" }, "two keys in flash" );
da9aa7d5 38
39$c->finalize;
da9aa7d5 40
41is_deeply( $c->flash, { bar => "gorch" }, "one key in flash" );
42
43$c->finalize;
da9aa7d5 44
ab634fee 45is_deeply( $c->flash, {}, "nothing in flash" );
19c130c2 46
47$c->flash->{bar} = "gorch";
48
49$c->config->{session}{flash_to_stash} = 1;
50
51$c->finalize;
52$c->prepare_action;
53
54is_deeply( $c->stash, { bar => "gorch" }, "flash copied to stash" );
55