Skip to content

Commit

Permalink
fixed another small flash bug
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Apr 18, 2012
1 parent d2c29aa commit 99aa643
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
13 changes: 5 additions & 8 deletions lib/Mojolicious/Controller.pm
Expand Up @@ -105,15 +105,12 @@ sub flash {
my $self = shift;

# Check old flash
my $session = $self->stash->{'mojo.session'};
if ($_[0] && !defined $_[1] && !ref $_[0]) {
return unless ref $session eq 'HASH';
return unless my $flash = $session->{flash};
return $flash->{$_[0]};
}
my $session = $self->session;
return $session->{flash} ? $session->{flash}{$_[0]} : undef
if @_ == 1 && !ref $_[0];

# Initialize new flash
my $flash = $self->session->{new_flash} ||= {};
# Initialize new flash and merge values
my $flash = $session->{new_flash} ||= {};
%$flash = (%$flash, %{@_ > 1 ? {@_} : $_[0]});

return $self;
Expand Down
5 changes: 4 additions & 1 deletion t/mojolicious/rebased_lite_app.t
Expand Up @@ -6,7 +6,7 @@ BEGIN {
$ENV{MOJO_REACTOR} = 'Mojo::Reactor::Poll';
}

use Test::More tests => 22;
use Test::More tests => 24;

# "For example, if you killed your grandfather, you'd cease to exist!
# But existing is basically all I do!"
Expand Down Expand Up @@ -73,8 +73,11 @@ foo
EOF

# GET /bar
ok !$t->ua->cookie_jar->find($t->ua->app_url->path('/foo')),
'no session cookie';
$t->get_ok('/bar')->status_is(302)->header_is('X-Route' => 'bar')
->header_is(Location => 'http://kraih.com/rebased/foo');
ok $t->ua->cookie_jar->find($t->ua->app_url->path('/foo')), 'session cookie';

# GET /foo (with flash message)
$t->get_ok('/foo')->status_is(200)->content_is(<<EOF);
Expand Down

0 comments on commit 99aa643

Please sign in to comment.