X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2F03_flash.t;h=0ead785fab8fc9bcaccdf58f2a71410bb531f91e;hb=d7cb2327deb8adbfe9ca7113d0e23b87635195da;hp=a56c43b76312f934dbc4807aaca87d9c7c2c8d0d;hpb=19c130c28deee544c48e29e9297da771fd397066;p=catagits%2FCatalyst-Plugin-Session.git diff --git a/t/03_flash.t b/t/03_flash.t index a56c43b..0ead785 100644 --- a/t/03_flash.t +++ b/t/03_flash.t @@ -3,52 +3,77 @@ use strict; use warnings; -use Test::More tests => 7; -use Test::MockObject::Extends; +use Test::More tests => 12; use Test::Exception; +use Test::Deep; my $m; BEGIN { use_ok( $m = "Catalyst::Plugin::Session" ) } -my $c = Test::MockObject::Extends->new( $m ); - -$c->set_always( get_session_data => { } ); -$c->set_true( "store_session_data" ); -$c->set_always( _sessionid => "deadbeef"); -$c->set_always( config => { } ); -$c->set_always( stash => { } ); - -$c->_load_flash; - -is_deeply( $c->flash, {}, "nothing in flash"); +my $c_meta = Class::MOP::Class->create_anon_class( + superclasses => [ $m, '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; -$c->_load_flash; +$c->finalize_body; is_deeply( $c->flash, { foo => "moose" }, "one key in flash" ); -$c->flash->{bar} = "gorch"; +cmp_deeply( $c->session, { __updated => re('^\d+$'), __flash => $c->flash }, "session has __flash with flash data" ); -is_deeply( $c->flash, { foo => "moose", bar => "gorch" }, "two keys in flash"); +$c->flash(bar => "gorch"); -$c->finalize; -$c->_load_flash; +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; -$c->_load_flash; +$c->finalize_body; + +$c->flash->{test} = 'clear_flash'; -is_deeply( $c->flash, {}, "nothing in 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"; -$c->config->{session}{flash_to_stash} = 1; +$config->{flash_to_stash} = 1; -$c->finalize; +$c->finalize_body; $c->prepare_action; is_deeply( $c->stash, { bar => "gorch" }, "flash copied to stash" ); -