Navigation Menu

Skip to content

Commit

Permalink
fixed flash
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Apr 18, 2012
1 parent f10cbbc commit bf3e8f3
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
1 change: 1 addition & 0 deletions Changes
Expand Up @@ -2,6 +2,7 @@ This file documents the revision history for Perl extension Mojolicious.

2.84 2012-04-19
- Improved documentation.
- Fixed flash.

2.83 2012-04-18
- Added hostname verification support to Mojo::IOLoop::Client and
Expand Down
6 changes: 3 additions & 3 deletions lib/Mojolicious/Controller.pm
Expand Up @@ -104,16 +104,16 @@ sub finish {
sub flash {
my $self = shift;

# Get
# 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]};
}

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

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

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

# "For example, if you killed your grandfather, you'd cease to exist!
# But existing is basically all I do!"
Expand Down Expand Up @@ -38,6 +38,7 @@ get '/foo';
# GET /bar
get '/bar' => sub {
my $self = shift;
$self->flash(just => 'works!');
$self->redirect_to($self->url_for('foo'));
};

Expand Down Expand Up @@ -75,6 +76,17 @@ EOF
$t->get_ok('/bar')->status_is(302)->header_is('X-Route' => 'bar')
->header_is(Location => 'http://kraih.com/rebased/foo');

# GET /foo (with flash message)
$t->get_ok('/foo')->status_is(200)->content_is(<<EOF);
<base href="http://kraih.com/rebased/" />works!
<link href="/rebased/b.css" media="test" rel="stylesheet" type="text/css" />
<img alt="Test" src="/rebased/images/test.png" />
http://kraih.com/rebased
/rebased
http://kraih.com/
foo
EOF

# GET /baz
$t->get_ok('/baz')->status_is(200)->header_is('X-Route' => 'baz')
->content_is(<<EOF);
Expand Down Expand Up @@ -104,7 +116,7 @@ __DATA__
% }
@@ foo.html.ep
%= base_tag
<%= base_tag %><%= flash 'just' || '' %>
%= stylesheet '/b.css', media => 'test'
%= image '/images/test.png', alt => 'Test'
%= url_for('root')->to_abs
Expand Down

0 comments on commit bf3e8f3

Please sign in to comment.