controller
controller copied to clipboard
Don't persist flash after first redirect
Fixes https://github.com/hanami/controller/issues/285
There is something that doesn't look good. The spec doesn't pass locally, but it does over CI. My intent was to reproduce the bug only, so the build supposed to not pass..
Nevermind. CI are reporting a false positive: https://travis-ci.org/hanami/controller/jobs/551367840 The build is failing but the script/ci
exits with 0
, which confuses CI.
I'm going to have a look @jodosha @AlfonsoUceda
The logic seems fine, every time we trigger a redirect we store the values in kept
if there is any _data
and after the action is over we call clear
on the flash
updating the count for kept
values and expire the ones that have been there for 2 or more requests.
The test triggers 2 redirects and finally renders Destination
but we access the flash
before clearing the session, so the kept values haven't been deleted yet if the test were to trigger one redirect more the test will pass.
@jodosha I took the liberty to add a commit https://github.com/hanami/controller/pull/293/commits/344e7371641b93875a7021f829556f5fddff3132 commenting your failing spec and adding one that proves my theory about adding an extra redirect.
Just wanted to start the conversation and what is the desired behaviour for the users. A possible solution is to expire kept data instead when reaching the count of 2
https://github.com/hanami/controller/blob/344e7371641b93875a7021f829556f5fddff3132/lib/hanami/action/flash.rb#L197 we could expire it to the count of 1
, but I'm sure this will break other tests.
Thoughts?