Permalink
Browse files

Don't reuse a closed flash when using now

  • Loading branch information...
1 parent 22fcef9 commit 89ed9fbd1917e431e489dc856042d996d0f088c5 @flop flop committed with josevalim Apr 19, 2011
Showing with 13 additions and 1 deletion.
  1. +5 −1 actionpack/lib/action_dispatch/middleware/flash.rb
  2. +8 −0 actionpack/test/controller/flash_test.rb
@@ -70,6 +70,10 @@ def notice=(message)
def close!(new_flash)
@flash = new_flash
end
+
+ def closed?
+ @flash.closed?
+ end
end
class FlashHash
@@ -146,7 +150,7 @@ def replace(h) #:nodoc:
#
# Entries set via <tt>now</tt> are accessed the same way as standard entries: <tt>flash['my-key']</tt>.
def now
- @now ||= FlashNow.new(self)
+ @now = (!@now || @now.closed?) ? FlashNow.new(self) : @now
end
attr_reader :closed
@@ -272,6 +272,14 @@ def test_setting_flash_does_not_raise_in_following_requests
end
end
+ def test_setting_flash_now_does_not_raise_in_following_requests
+ with_test_route_set do
+ env = { 'action_dispatch.request.flash_hash' => ActionDispatch::Flash::FlashHash.new }
+ get '/set_flash_now', nil, env
+ get '/set_flash_now', nil, env
+ end
+ end
+
def test_setting_flash_raises_after_stream_back_to_client_even_with_an_empty_flash
with_test_route_set do
env = { 'action_dispatch.request.flash_hash' => ActionDispatch::Flash::FlashHash.new }

0 comments on commit 89ed9fb

Please sign in to comment.