kd's tests updated, code fixed
Yuval Kogman [Wed, 8 Mar 2006 09:39:36 +0000 (09:39 +0000)]
lib/Catalyst/Plugin/Session.pm
t/lib/FlashTestApp.pm
t/semi_persistent_flash.t

index cdda2fd..cbcf7e8 100644 (file)
@@ -147,7 +147,7 @@ sub _load_session {
     if ( my $sid = $c->_sessionid ) {
         if ( $c->session_expires ) {    # > 0
 
-            my $session_data = $c->get_session_data("session:$sid");
+            my $session_data = $c->get_session_data("session:$sid") || return;
             $c->_session($session_data);
 
             no warnings 'uninitialized';    # ne __address
@@ -157,7 +157,7 @@ sub _load_session {
                 $c->log->warn(
                         "Deleting session $sid due to address mismatch ("
                       . $session_data->{__address} . " != "
-                      . $c->request->address . ")",
+                      . $c->request->address . ")" . Carp::longmess,
                 );
                 $c->delete_session("address mismatch");
                 return;
@@ -291,7 +291,8 @@ sub session {
 
 sub keep_flash {
     my ( $c, @keys ) = @_;
-    ($c->_flash_keep_keys->{@keys}) = ((undef) x @keys);
+    my $href = $c->_flash_keep_keys || $c->_flash_keep_keys({});
+    (@{$href}{@keys}) = ((undef) x @keys);
 }
 
 sub flash {
index ff8395b..b7e0189 100644 (file)
@@ -1,10 +1,11 @@
 #!/usr/bin/perl -w
 
 package FlashTestApp;
-use Catalyst qw/Session Session::Store::File Session::State::Cookie/;
+use Catalyst qw/Session Session::Store::Dummy Session::State::Cookie/;
 
 use strict;
 use warnings;
+no warnings 'uninitialized';
 
 sub default : Private {
     my ($self, $c) = @_;
@@ -16,7 +17,7 @@ sub first : Global {
     my ( $self, $c ) = @_;
     if ( ! $c->flash->{is_set}) {
         $c->stash->{message} = "flash is not set";
-        $c->stash->{is_set} = 1;
+        $c->flash->{is_set} = 1;
     }
 }
 
@@ -32,7 +33,7 @@ sub third : Global {
     my ( $self, $c ) = @_;
     if ($c->flash->{is_set} == 2) {
         $c->stash->{message} = "flash set second time";
-        $c->flash->{is_set} = 2;
+        $c->keep_flash("is_set");
     }
 }
 
@@ -48,7 +49,7 @@ sub fifth : Global {
     $c->forward('/first');
 }
 
-sub end : Local {
+sub end : Private {
     my ($self, $c) = @_;
     $c->res->output($c->stash->{message});
 }
index 76b968b..2156296 100644 (file)
@@ -8,9 +8,6 @@ BEGIN {
         or plan skip_all =>
             "Catalyst::Plugin::Session::State::Cookie is required for this test";
 
-    eval { require Catalyst::Plugin::Session::Store::File}
-        or plan skil_all =>
-            'Catalyst::Plugin::Session::Store::File is required for this test';
     eval { require Test::WWW::Mechanize::Catalyst }
       or plan skip_all =>
       'Test::WWW::Mechanize::Catalyst is required for this test';
@@ -25,23 +22,23 @@ use Test::WWW::Mechanize::Catalyst 'FlashTestApp';
 my $ua = Test::WWW::Mechanize::Catalyst->new;
 
 # flash absent for initial request
-$ua->get_ok( "http://localhost/first") for $ua;
+$ua->get_ok( "http://localhost/first");
 $ua->content_contains( "flash is not set", "not set");
 
 # present for 1st req.
-$ua->get_ok( "http://localhost/second") for $ua;
+$ua->get_ok( "http://localhost/second");
 $ua->content_contains( "flash set first time", "set first");
 
 # should be the same 2nd req.
-$ua->get_ok( "http://localhost/third") for $ua;
+$ua->get_ok( "http://localhost/third");
 $ua->content_contains( "flash set second time", "set second");
 
 # and the third request, flash->{is_set} has the same value as 2nd.
-$ua->get_ok( "http://localhost/fourth") for $ua;
+$ua->get_ok( "http://localhost/fourth");
 $ua->content_contains( "flash set 3rd time, same val as prev.", "set third");
 
 
 # and should be absent again for the 4th req.
-$ua->get_ok( "http://localhost/fifth") for $ua;
+$ua->get_ok( "http://localhost/fifth");
 $ua->content_contains( "flash is not", "flash has gone");