Wins Lin
2013-Jun-04 22:12 UTC
Is flash[] value kept through action to action 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: <true> expected but was <nil>. My question is, are flash values kept in integration test? Does it have to be "true" here or the above behavior is correct? -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/89106bcd798e975ad8c532dc8ac10d56%40ruby-forum.com?hl=en-US. For more options, visit https://groups.google.com/groups/opt_out.
Robert Walker
2013-Jun-05 13:40 UTC
Re: Are flash[] values kept between redirect actions in integration tests?
Wins Lin 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: http://guides.rubyonrails.org/action_controller_overview.html#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: http://guides.rubyonrails.org/testing.html#integration-testing 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. -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/785f0fe32fdfe9f0e31f472eeada26ea%40ruby-forum.com?hl=en-US. For more options, visit https://groups.google.com/groups/opt_out.
Otavio Nestares
2013-Jun-05 14:06 UTC
Re: Re: Are flash[] values kept between redirect actions in integration tests?
Use flash.now[:notice] !! Best Em quarta-feira, 5 de junho de 2013, Robert Walker escreveu:> Wins Lin 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: > > http://guides.rubyonrails.org/action_controller_overview.html#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: > > http://guides.rubyonrails.org/testing.html#integration-testing > > 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. > > -- > Posted via http://www.ruby-forum.com/. > > -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Talk" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org <javascript:;>. > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<javascript:;> > . > To view this discussion on the web visit > https://groups.google.com/d/msgid/rubyonrails-talk/785f0fe32fdfe9f0e31f472eeada26ea%40ruby-forum.com?hl=en-US > . > For more options, visit https://groups.google.com/groups/opt_out. > > >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CABN%3DCd6MNLmiJnOYxJXLK3AB020K%2BoFmz6sL4SAWUweZEmp_9w%40mail.gmail.com?hl=en-US. For more options, visit https://groups.google.com/groups/opt_out.
Robert Walker
2013-Jun-05 14:28 UTC
Re: Re: Are flash[] values kept between redirect actions in integration tests?
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. -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/f264b6650aeaedd2d6881c7a6c80ff15%40ruby-forum.com?hl=en-US. For more options, visit https://groups.google.com/groups/opt_out.