In the code below, if reset_session is called in action index,
flash[:test] is not passed to action special. I would expect that
calling reset_session would clear anything in the session/flash which
was set before reset_session was called but to have no impact on the
storage of anything in the session/flash after it reset_session was
Interesting…“p flash” in action index reveals that the flash stores
appropriate contents after reset_session is called. The clearing of the
flash occurs during the redirect.
Is this a bug?
class TestController < ActionController::Base
## comment this “reset_session” call and flash contents are
passed to action special
flash[:test] = ‘This should be passed to action special.’
redirect_to :action => ‘special’
## this outputs (to console) the expected contents of the flash
def special unless flash[:test] render :text => "Flash contents cleared." else render :text => "Flash contents maintained." end end
Test which should pass if flash contents are maintained. Won’t pass if
reset_session is called in action index.
class TestTest < Test::Unit::TestCase
@controller = TestController.new
@request = ActionController::TestRequest.new
@response = ActionController::TestResponse.new
assert_equal ‘This should be passed to action special.’,
assert_redirected_to :action => ‘special’