Are flash[] values kept between redirect actions in integration tests?

I have an integration test that sets a flash[] value in action before
redirect and reads it in the next action (the one that previous action
redirects to):

test(“some integration test”) do
get("/one")
assert_equal(true, flash[:foo]) ## is set to true in this action
assert_response(:redirect)

follow_redirect!

assert_equal(true, flash[:foo]) ## has to be true in next action
end

So flash[:foo] has to be “true” in the second action. Because it is set
in the first one. But my test throws an error:

  1. Failure:
    expected but was .

My question is, are flash values kept in integration test? Does it have
to be “true” here or the above behavior is correct?

Use flash.now[:notice] !!

Best

Em quarta-feira, 5 de junho de 2013, Robert W. escreveu:

Wins L. wrote in post #1111366:

My question is, are flash values kept in integration test? Does it have
to be “true” here or the above behavior is correct?

The Rails guide has a clear explanation of the flash:

Yes, the flash message is available IN the following request, but not
after it. My bet is that your assertion is happening after that next
action has completed.

Take a look at the example in Section 5.2 in this guide:

post_via_redirect "/login", :username => users(:avs).username,
  :password => users(:avs).password
assert_equal '/welcome', path
assert_equal 'Welcome avs!', flash[:notice]

Notice there is no follow_redirect! before checking the flash. Your
flash is getting destroyed before you can assert it.

Otavio Nestares wrote in post #1111439:

Use flash.now[:notice] !!

Wouldn’t that just make matters worse? flash.now makes the flash
available in the current request. It does not make it persists across
requests. Use flash.now when you want render the template directly
without a new request. That’s not the case here.